2 * $Id: uams_passwd.c,v 1.11 2001-06-25 15:18:01 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.
31 #include <atalk/afp.h>
32 #include <atalk/uam.h>
40 static char *clientname;
44 static int passwd_login(void *obj, struct passwd **uam_pwd,
45 char *ibuf, int ibuflen,
46 char *rbuf, int *rbuflen)
57 if (uam_afpserver_option(obj, UAM_OPTION_USERNAME,
58 (void *) &username, &ulen) < 0)
62 if( uam_afpserver_option( obj, UAM_OPTION_CLIENTNAME,
63 (void *) &clientname, NULL ) < 0 )
67 len = (unsigned char) *ibuf++;
69 return( AFPERR_PARAM );
72 memcpy(username, ibuf, len );
74 username[ len ] = '\0';
75 if ((unsigned long) ibuf & 1) /* pad character */
77 ibuf[ PASSWDLEN ] = '\0';
79 if (( pwd = uam_getname(username, ulen)) == NULL ) {
83 syslog(LOG_INFO, "cleartext login: %s", username);
84 if (uam_checkuser(pwd) < 0)
85 return AFPERR_NOTAUTH;
88 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
89 syslog( LOG_INFO, "no shadow passwd entry for %s", username);
90 return AFPERR_NOTAUTH;
92 pwd->pw_passwd = sp->sp_pwdp;
96 return AFPERR_NOTAUTH;
106 uam_afp_getcmdline( &ac, &av );
107 sprintf( hostname, "%s@%s", username, clientname );
109 if( sia_validate_user( NULL, ac, av, hostname, username,
110 NULL, FALSE, NULL, ibuf ) != SIASUCCESS )
111 return AFPERR_NOTAUTH;
116 p = crypt( ibuf, pwd->pw_passwd );
117 if ( strcmp( p, pwd->pw_passwd ) == 0 )
121 return AFPERR_NOTAUTH;
127 static int passwd_changepw(void *obj, char *username,
128 struct passwd *pwd, char *ibuf,
129 int ibuflen, char *rbuf, int *rbuflen)
134 char pw[PASSWDLEN + 1], *p;
135 uid_t uid = geteuid();
137 if (uam_checkuser(pwd) < 0)
138 return AFPERR_ACCESS;
141 memcpy(pw, ibuf, PASSWDLEN);
142 memset(ibuf, 0, PASSWDLEN);
143 pw[PASSWDLEN] = '\0';
146 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
147 syslog( LOG_INFO, "no shadow passwd entry for %s", username);
150 pwd->pw_passwd = sp->sp_pwdp;
153 p = crypt(pw, pwd->pw_passwd );
154 if (strcmp( p, pwd->pw_passwd )) {
155 memset(pw, 0, sizeof(pw));
156 return AFPERR_NOTAUTH;
161 ibuf[PASSWDLEN] = '\0';
171 /* Printer ClearTxtUAM login */
172 static int passwd_printer(start, stop, username, out)
173 char *start, *stop, *username;
181 char password[PASSWDLEN + 1] = "\0";
182 static const char *loginok = "0\r";
185 data = (char *)malloc(stop - start + 1);
186 strncpy(data, start, stop - start + 1);
188 /* We are looking for the following format in data:
189 * (username) (password)
191 * Let's hope username doesn't contain ") ("!
194 /* Parse input for username in () */
195 if ((p = strchr(data, '(' )) == NULL) {
196 syslog(LOG_INFO,"Bad Login ClearTxtUAM: username not found in string");
201 if ((q = strstr(data, ") (" )) == NULL) {
202 syslog(LOG_INFO,"Bad Login ClearTxtUAM: username not found in string");
206 strncpy(username, p, q - p);
208 /* Parse input for password in next () */
210 if ((q = strrchr(data, ')' )) == NULL) {
211 syslog(LOG_INFO,"Bad Login ClearTxtUAM: password not found in string");
215 strncpy(password, p, q - p);
217 /* Done copying username and password, clean up */
220 ulen = strlen(username);
222 if (( pwd = uam_getname(username, ulen)) == NULL ) {
223 syslog(LOG_INFO, "Bad Login ClearTxtUAM: ( %s ) not found ",
228 if (uam_checkuser(pwd) < 0) {
229 /* syslog of error happens in uam_checkuser */
234 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
235 syslog(LOG_INFO, "Bad Login ClearTxtUAM: no shadow passwd entry for %s",
239 pwd->pw_passwd = sp->sp_pwdp;
242 if (!pwd->pw_passwd) {
243 syslog(LOG_INFO, "Bad Login ClearTxtUAM: no password for %s",
249 if ( kcheckuser( pwd, password) == 0)
253 p = crypt(password, pwd->pw_passwd);
254 if (strcmp(p, pwd->pw_passwd) != 0) {
255 syslog(LOG_INFO, "Bad Login ClearTxtUAM: %s: bad password", username);
259 /* Login successful */
260 append(out, loginok, strlen(loginok));
261 syslog(LOG_INFO, "Login ClearTxtUAM: %s", username);
266 static int uam_setup(const char *path)
268 if (uam_register(UAM_SERVER_LOGIN, path, "Cleartxt Passwrd",
269 passwd_login, NULL, NULL) < 0)
271 if (uam_register(UAM_SERVER_PRINTAUTH, path, "ClearTxtUAM",
278 static void uam_cleanup(void)
280 uam_unregister(UAM_SERVER_LOGIN, "Cleartxt Passwrd");
281 uam_unregister(UAM_SERVER_PRINTAUTH, "ClearTxtUAM");
284 UAM_MODULE_EXPORT struct uam_export uams_clrtxt = {
287 uam_setup, uam_cleanup