2 * $Id: uams_passwd.c,v 1.12 2001-06-25 20:13:45 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 */
18 #endif /* HAVE_UNISTD_H */
21 #endif /* ! NO_CRYPT_H */
33 #include <atalk/afp.h>
34 #include <atalk/uam.h>
42 static char *clientname;
46 static int passwd_login(void *obj, struct passwd **uam_pwd,
47 char *ibuf, int ibuflen,
48 char *rbuf, int *rbuflen)
59 if (uam_afpserver_option(obj, UAM_OPTION_USERNAME,
60 (void *) &username, &ulen) < 0)
64 if( uam_afpserver_option( obj, UAM_OPTION_CLIENTNAME,
65 (void *) &clientname, NULL ) < 0 )
69 len = (unsigned char) *ibuf++;
71 return( AFPERR_PARAM );
74 memcpy(username, ibuf, len );
76 username[ len ] = '\0';
77 if ((unsigned long) ibuf & 1) /* pad character */
79 ibuf[ PASSWDLEN ] = '\0';
81 if (( pwd = uam_getname(username, ulen)) == NULL ) {
85 syslog(LOG_INFO, "cleartext login: %s", username);
86 if (uam_checkuser(pwd) < 0)
87 return AFPERR_NOTAUTH;
90 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
91 syslog( LOG_INFO, "no shadow passwd entry for %s", username);
92 return AFPERR_NOTAUTH;
94 pwd->pw_passwd = sp->sp_pwdp;
98 return AFPERR_NOTAUTH;
108 uam_afp_getcmdline( &ac, &av );
109 sprintf( hostname, "%s@%s", username, clientname );
111 if( sia_validate_user( NULL, ac, av, hostname, username,
112 NULL, FALSE, NULL, ibuf ) != SIASUCCESS )
113 return AFPERR_NOTAUTH;
118 p = crypt( ibuf, pwd->pw_passwd );
119 if ( strcmp( p, pwd->pw_passwd ) == 0 )
123 return AFPERR_NOTAUTH;
129 static int passwd_changepw(void *obj, char *username,
130 struct passwd *pwd, char *ibuf,
131 int ibuflen, char *rbuf, int *rbuflen)
135 #endif /* SHADOWPW */
136 char pw[PASSWDLEN + 1], *p;
137 uid_t uid = geteuid();
139 if (uam_checkuser(pwd) < 0)
140 return AFPERR_ACCESS;
143 memcpy(pw, ibuf, PASSWDLEN);
144 memset(ibuf, 0, PASSWDLEN);
145 pw[PASSWDLEN] = '\0';
148 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
149 syslog( LOG_INFO, "no shadow passwd entry for %s", username);
152 pwd->pw_passwd = sp->sp_pwdp;
153 #endif /* SHADOWPW */
155 p = crypt(pw, pwd->pw_passwd );
156 if (strcmp( p, pwd->pw_passwd )) {
157 memset(pw, 0, sizeof(pw));
158 return AFPERR_NOTAUTH;
163 ibuf[PASSWDLEN] = '\0';
167 #endif /* SHADOWPW */
173 /* Printer ClearTxtUAM login */
174 static int passwd_printer(start, stop, username, out)
175 char *start, *stop, *username;
181 #endif /* SHADOWPW */
183 char password[PASSWDLEN + 1] = "\0";
184 static const char *loginok = "0\r";
187 data = (char *)malloc(stop - start + 1);
188 strncpy(data, start, stop - start + 1);
190 /* We are looking for the following format in data:
191 * (username) (password)
193 * Let's hope username doesn't contain ") ("!
196 /* Parse input for username in () */
197 if ((p = strchr(data, '(' )) == NULL) {
198 syslog(LOG_INFO,"Bad Login ClearTxtUAM: username not found in string");
203 if ((q = strstr(data, ") (" )) == NULL) {
204 syslog(LOG_INFO,"Bad Login ClearTxtUAM: username not found in string");
208 strncpy(username, p, q - p);
210 /* Parse input for password in next () */
212 if ((q = strrchr(data, ')' )) == NULL) {
213 syslog(LOG_INFO,"Bad Login ClearTxtUAM: password not found in string");
217 strncpy(password, p, q - p);
219 /* Done copying username and password, clean up */
222 ulen = strlen(username);
224 if (( pwd = uam_getname(username, ulen)) == NULL ) {
225 syslog(LOG_INFO, "Bad Login ClearTxtUAM: ( %s ) not found ",
230 if (uam_checkuser(pwd) < 0) {
231 /* syslog of error happens in uam_checkuser */
236 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
237 syslog(LOG_INFO, "Bad Login ClearTxtUAM: no shadow passwd entry for %s",
241 pwd->pw_passwd = sp->sp_pwdp;
242 #endif /* SHADOWPW */
244 if (!pwd->pw_passwd) {
245 syslog(LOG_INFO, "Bad Login ClearTxtUAM: no password for %s",
251 if ( kcheckuser( pwd, password) == 0)
255 p = crypt(password, pwd->pw_passwd);
256 if (strcmp(p, pwd->pw_passwd) != 0) {
257 syslog(LOG_INFO, "Bad Login ClearTxtUAM: %s: bad password", username);
261 /* Login successful */
262 append(out, loginok, strlen(loginok));
263 syslog(LOG_INFO, "Login ClearTxtUAM: %s", username);
268 static int uam_setup(const char *path)
270 if (uam_register(UAM_SERVER_LOGIN, path, "Cleartxt Passwrd",
271 passwd_login, NULL, NULL) < 0)
273 if (uam_register(UAM_SERVER_PRINTAUTH, path, "ClearTxtUAM",
280 static void uam_cleanup(void)
282 uam_unregister(UAM_SERVER_LOGIN, "Cleartxt Passwrd");
283 uam_unregister(UAM_SERVER_PRINTAUTH, "ClearTxtUAM");
286 UAM_MODULE_EXPORT struct uam_export uams_clrtxt = {
289 uam_setup, uam_cleanup