2 * $Id: uams_passwd.c,v 1.13 2001-09-06 20:00:59 rufustfirefly Exp $
4 * Copyright (c) 1990,1993 Regents of The University of Michigan.
5 * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu)
6 * All Rights Reserved. See COPYRIGHT.
11 #endif /* HAVE_CONFIG_H */
19 #else /* STDC_HEADERS */
23 #endif /* HAVE_STRCHR */
24 char *strchr (), *strrchr ();
26 #define memcpy(d,s,n) bcopy ((s), (d), (n))
27 #define memmove(d,s,n) bcopy ((s), (d), (n))
28 #endif /* ! HAVE_MEMCPY */
29 #endif /* STDC_HEADERS */
33 #endif /* HAVE_UNISTD_H */
36 #endif /* ! NO_CRYPT_H */
48 #include <atalk/afp.h>
49 #include <atalk/uam.h>
57 static char *clientname;
61 static int passwd_login(void *obj, struct passwd **uam_pwd,
62 char *ibuf, int ibuflen,
63 char *rbuf, int *rbuflen)
74 if (uam_afpserver_option(obj, UAM_OPTION_USERNAME,
75 (void *) &username, &ulen) < 0)
79 if( uam_afpserver_option( obj, UAM_OPTION_CLIENTNAME,
80 (void *) &clientname, NULL ) < 0 )
84 len = (unsigned char) *ibuf++;
86 return( AFPERR_PARAM );
89 memcpy(username, ibuf, len );
91 username[ len ] = '\0';
92 if ((unsigned long) ibuf & 1) /* pad character */
94 ibuf[ PASSWDLEN ] = '\0';
96 if (( pwd = uam_getname(username, ulen)) == NULL ) {
100 syslog(LOG_INFO, "cleartext login: %s", username);
101 if (uam_checkuser(pwd) < 0)
102 return AFPERR_NOTAUTH;
105 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
106 syslog( LOG_INFO, "no shadow passwd entry for %s", username);
107 return AFPERR_NOTAUTH;
109 pwd->pw_passwd = sp->sp_pwdp;
110 #endif /* SHADOWPW */
113 return AFPERR_NOTAUTH;
123 uam_afp_getcmdline( &ac, &av );
124 sprintf( hostname, "%s@%s", username, clientname );
126 if( sia_validate_user( NULL, ac, av, hostname, username,
127 NULL, FALSE, NULL, ibuf ) != SIASUCCESS )
128 return AFPERR_NOTAUTH;
133 p = crypt( ibuf, pwd->pw_passwd );
134 if ( strcmp( p, pwd->pw_passwd ) == 0 )
138 return AFPERR_NOTAUTH;
144 static int passwd_changepw(void *obj, char *username,
145 struct passwd *pwd, char *ibuf,
146 int ibuflen, char *rbuf, int *rbuflen)
150 #endif /* SHADOWPW */
151 char pw[PASSWDLEN + 1], *p;
152 uid_t uid = geteuid();
154 if (uam_checkuser(pwd) < 0)
155 return AFPERR_ACCESS;
158 memcpy(pw, ibuf, PASSWDLEN);
159 memset(ibuf, 0, PASSWDLEN);
160 pw[PASSWDLEN] = '\0';
163 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
164 syslog( LOG_INFO, "no shadow passwd entry for %s", username);
167 pwd->pw_passwd = sp->sp_pwdp;
168 #endif /* SHADOWPW */
170 p = crypt(pw, pwd->pw_passwd );
171 if (strcmp( p, pwd->pw_passwd )) {
172 memset(pw, 0, sizeof(pw));
173 return AFPERR_NOTAUTH;
178 ibuf[PASSWDLEN] = '\0';
182 #endif /* SHADOWPW */
188 /* Printer ClearTxtUAM login */
189 static int passwd_printer(start, stop, username, out)
190 char *start, *stop, *username;
196 #endif /* SHADOWPW */
198 char password[PASSWDLEN + 1] = "\0";
199 static const char *loginok = "0\r";
202 data = (char *)malloc(stop - start + 1);
203 strncpy(data, start, stop - start + 1);
205 /* We are looking for the following format in data:
206 * (username) (password)
208 * Let's hope username doesn't contain ") ("!
211 /* Parse input for username in () */
212 if ((p = strchr(data, '(' )) == NULL) {
213 syslog(LOG_INFO,"Bad Login ClearTxtUAM: username not found in string");
218 if ((q = strstr(data, ") (" )) == NULL) {
219 syslog(LOG_INFO,"Bad Login ClearTxtUAM: username not found in string");
223 strncpy(username, p, q - p);
225 /* Parse input for password in next () */
227 if ((q = strrchr(data, ')' )) == NULL) {
228 syslog(LOG_INFO,"Bad Login ClearTxtUAM: password not found in string");
232 strncpy(password, p, q - p);
234 /* Done copying username and password, clean up */
237 ulen = strlen(username);
239 if (( pwd = uam_getname(username, ulen)) == NULL ) {
240 syslog(LOG_INFO, "Bad Login ClearTxtUAM: ( %s ) not found ",
245 if (uam_checkuser(pwd) < 0) {
246 /* syslog of error happens in uam_checkuser */
251 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
252 syslog(LOG_INFO, "Bad Login ClearTxtUAM: no shadow passwd entry for %s",
256 pwd->pw_passwd = sp->sp_pwdp;
257 #endif /* SHADOWPW */
259 if (!pwd->pw_passwd) {
260 syslog(LOG_INFO, "Bad Login ClearTxtUAM: no password for %s",
266 if ( kcheckuser( pwd, password) == 0)
270 p = crypt(password, pwd->pw_passwd);
271 if (strcmp(p, pwd->pw_passwd) != 0) {
272 syslog(LOG_INFO, "Bad Login ClearTxtUAM: %s: bad password", username);
276 /* Login successful */
277 append(out, loginok, strlen(loginok));
278 syslog(LOG_INFO, "Login ClearTxtUAM: %s", username);
283 static int uam_setup(const char *path)
285 if (uam_register(UAM_SERVER_LOGIN, path, "Cleartxt Passwrd",
286 passwd_login, NULL, NULL) < 0)
288 if (uam_register(UAM_SERVER_PRINTAUTH, path, "ClearTxtUAM",
295 static void uam_cleanup(void)
297 uam_unregister(UAM_SERVER_LOGIN, "Cleartxt Passwrd");
298 uam_unregister(UAM_SERVER_PRINTAUTH, "ClearTxtUAM");
301 UAM_MODULE_EXPORT struct uam_export uams_clrtxt = {
304 uam_setup, uam_cleanup