2 * $Id: uams_passwd.c,v 1.13.2.1 2002-02-08 00:00:01 srittau 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 )
85 return( AFPERR_PARAM );
88 len = (unsigned char) *ibuf++;
90 if (!len || len > ibuflen || len > ulen ) {
91 return( AFPERR_PARAM );
94 memcpy(username, ibuf, len );
97 username[ len ] = '\0';
99 if ((unsigned long) ibuf & 1) { /* pad character */
103 if (ibuflen < PASSWDLEN) {
104 return( AFPERR_PARAM );
106 ibuf[ PASSWDLEN ] = '\0';
108 if (( pwd = uam_getname(username, ulen)) == NULL ) {
112 syslog(LOG_INFO, "cleartext login: %s", username);
113 if (uam_checkuser(pwd) < 0) {
114 return AFPERR_NOTAUTH;
118 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
119 syslog( LOG_INFO, "no shadow passwd entry for %s", username);
120 return AFPERR_NOTAUTH;
122 pwd->pw_passwd = sp->sp_pwdp;
123 #endif /* SHADOWPW */
125 if (!pwd->pw_passwd) {
126 return AFPERR_NOTAUTH;
137 uam_afp_getcmdline( &ac, &av );
138 sprintf( hostname, "%s@%s", username, clientname );
140 if( sia_validate_user( NULL, ac, av, hostname, username,
141 NULL, FALSE, NULL, ibuf ) != SIASUCCESS )
142 return AFPERR_NOTAUTH;
147 p = crypt( ibuf, pwd->pw_passwd );
148 if ( strcmp( p, pwd->pw_passwd ) == 0 )
152 return AFPERR_NOTAUTH;
158 static int passwd_changepw(void *obj, char *username,
159 struct passwd *pwd, char *ibuf,
160 int ibuflen, char *rbuf, int *rbuflen)
164 #endif /* SHADOWPW */
165 char pw[PASSWDLEN + 1], *p;
166 uid_t uid = geteuid();
168 if (uam_checkuser(pwd) < 0)
169 return AFPERR_ACCESS;
172 memcpy(pw, ibuf, PASSWDLEN);
173 memset(ibuf, 0, PASSWDLEN);
174 pw[PASSWDLEN] = '\0';
177 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
178 syslog( LOG_INFO, "no shadow passwd entry for %s", username);
181 pwd->pw_passwd = sp->sp_pwdp;
182 #endif /* SHADOWPW */
184 p = crypt(pw, pwd->pw_passwd );
185 if (strcmp( p, pwd->pw_passwd )) {
186 memset(pw, 0, sizeof(pw));
187 return AFPERR_NOTAUTH;
192 ibuf[PASSWDLEN] = '\0';
196 #endif /* SHADOWPW */
202 /* Printer ClearTxtUAM login */
203 static int passwd_printer(start, stop, username, out)
204 char *start, *stop, *username;
210 #endif /* SHADOWPW */
212 char password[PASSWDLEN + 1] = "\0";
213 static const char *loginok = "0\r";
216 data = (char *)malloc(stop - start + 1);
217 strncpy(data, start, stop - start + 1);
219 /* We are looking for the following format in data:
220 * (username) (password)
222 * Let's hope username doesn't contain ") ("!
225 /* Parse input for username in () */
226 if ((p = strchr(data, '(' )) == NULL) {
227 syslog(LOG_INFO,"Bad Login ClearTxtUAM: username not found in string");
232 if ((q = strstr(data, ") (" )) == NULL) {
233 syslog(LOG_INFO,"Bad Login ClearTxtUAM: username not found in string");
237 strncpy(username, p, q - p);
239 /* Parse input for password in next () */
241 if ((q = strrchr(data, ')' )) == NULL) {
242 syslog(LOG_INFO,"Bad Login ClearTxtUAM: password not found in string");
246 strncpy(password, p, q - p);
248 /* Done copying username and password, clean up */
251 ulen = strlen(username);
253 if (( pwd = uam_getname(username, ulen)) == NULL ) {
254 syslog(LOG_INFO, "Bad Login ClearTxtUAM: ( %s ) not found ",
259 if (uam_checkuser(pwd) < 0) {
260 /* syslog of error happens in uam_checkuser */
265 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
266 syslog(LOG_INFO, "Bad Login ClearTxtUAM: no shadow passwd entry for %s",
270 pwd->pw_passwd = sp->sp_pwdp;
271 #endif /* SHADOWPW */
273 if (!pwd->pw_passwd) {
274 syslog(LOG_INFO, "Bad Login ClearTxtUAM: no password for %s",
280 if ( kcheckuser( pwd, password) == 0)
284 p = crypt(password, pwd->pw_passwd);
285 if (strcmp(p, pwd->pw_passwd) != 0) {
286 syslog(LOG_INFO, "Bad Login ClearTxtUAM: %s: bad password", username);
290 /* Login successful */
291 append(out, loginok, strlen(loginok));
292 syslog(LOG_INFO, "Login ClearTxtUAM: %s", username);
297 static int uam_setup(const char *path)
299 if (uam_register(UAM_SERVER_LOGIN, path, "Cleartxt Passwrd",
300 passwd_login, NULL, NULL) < 0)
302 if (uam_register(UAM_SERVER_PRINTAUTH, path, "ClearTxtUAM",
309 static void uam_cleanup(void)
311 uam_unregister(UAM_SERVER_LOGIN, "Cleartxt Passwrd");
312 uam_unregister(UAM_SERVER_PRINTAUTH, "ClearTxtUAM");
315 UAM_MODULE_EXPORT struct uam_export uams_clrtxt = {
318 uam_setup, uam_cleanup