2 * $Id: uams_passwd.c,v 1.7 2001-05-03 13:57:44 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>
36 #ifdef DIGITAL_UNIX_SECURITY
37 #include <sys/types.h>
38 #include <sys/security.h>
40 #endif /* DIGITAL_UNIX_SECURITY */
43 static int passwd_login(void *obj, struct passwd **uam_pwd,
44 char *ibuf, int ibuflen,
45 char *rbuf, int *rbuflen)
53 #ifdef DIGITAL_UNIX_SECURITY
56 #endif /* DIGITAL_UNIX_SECURITY */
60 if (uam_afpserver_option(obj, UAM_OPTION_USERNAME,
61 (void *) &username, &ulen) < 0)
64 len = (unsigned char) *ibuf++;
66 return( AFPERR_PARAM );
69 memcpy(username, ibuf, len );
71 username[ len ] = '\0';
72 if ((unsigned long) ibuf & 1) /* pad character */
74 ibuf[ PASSWDLEN ] = '\0';
76 if (( pwd = uam_getname(username, ulen)) == NULL ) {
80 syslog(LOG_INFO, "cleartext login: %s", username);
81 if (uam_checkuser(pwd) < 0)
82 return AFPERR_NOTAUTH;
85 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
86 syslog( LOG_INFO, "no shadow passwd entry for %s", username);
87 return AFPERR_NOTAUTH;
89 pwd->pw_passwd = sp->sp_pwdp;
93 return AFPERR_NOTAUTH;
97 #ifdef DIGITAL_UNIX_SECURITY
98 pr = getprpwnam( username );
100 return AFPERR_NOTAUTH;
101 if ( strcmp ( bigcrypt ( ibuf, pr->ufld.fd_encrypt ),
102 pr->ufld.fd_encrypt == 0 )
104 #else /* DIGITAL_UNIX_SECURITY */
105 p = crypt( ibuf, pwd->pw_passwd );
106 if ( strcmp( p, pwd->pw_passwd ) == 0 )
108 #endif /* DIGITAL_UNIX_SECURITY */
110 return AFPERR_NOTAUTH;
116 static int passwd_changepw(void *obj, char *username,
117 struct passwd *pwd, char *ibuf,
118 int ibuflen, char *rbuf, int *rbuflen)
123 char pw[PASSWDLEN + 1], *p;
124 uid_t uid = geteuid();
126 if (uam_checkuser(pwd) < 0)
127 return AFPERR_ACCESS;
130 memcpy(pw, ibuf, PASSWDLEN);
131 memset(ibuf, 0, PASSWDLEN);
132 pw[PASSWDLEN] = '\0';
135 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
136 syslog( LOG_INFO, "no shadow passwd entry for %s", username);
139 pwd->pw_passwd = sp->sp_pwdp;
142 p = crypt(pw, pwd->pw_passwd );
143 if (strcmp( p, pwd->pw_passwd )) {
144 memset(pw, 0, sizeof(pw));
145 return AFPERR_NOTAUTH;
150 ibuf[PASSWDLEN] = '\0';
160 /* Printer ClearTxtUAM login */
161 static int passwd_printer(start, stop, username, out)
162 char *start, *stop, *username;
170 char password[PASSWDLEN + 1] = "\0";
171 static const char *loginok = "0\r";
174 data = (char *)malloc(stop - start + 1);
175 strncpy(data, start, stop - start + 1);
177 /* We are looking for the following format in data:
178 * (username) (password)
180 * Let's hope username doesn't contain ") ("!
183 /* Parse input for username in () */
184 if ((p = strchr(data, '(' )) == NULL) {
185 syslog(LOG_INFO,"Bad Login ClearTxtUAM: username not found in string");
190 if ((q = strstr(data, ") (" )) == NULL) {
191 syslog(LOG_INFO,"Bad Login ClearTxtUAM: username not found in string");
195 strncpy(username, p, q - p);
197 /* Parse input for password in next () */
199 if ((q = strrchr(data, ')' )) == NULL) {
200 syslog(LOG_INFO,"Bad Login ClearTxtUAM: password not found in string");
204 strncpy(password, p, q - p);
206 /* Done copying username and password, clean up */
209 ulen = strlen(username);
211 if (( pwd = uam_getname(username, ulen)) == NULL ) {
212 syslog(LOG_INFO, "Bad Login ClearTxtUAM: ( %s ) not found ",
217 if (uam_checkuser(pwd) < 0) {
218 /* syslog of error happens in uam_checkuser */
223 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
224 syslog(LOG_INFO, "Bad Login ClearTxtUAM: no shadow passwd entry for %s",
228 pwd->pw_passwd = sp->sp_pwdp;
231 if (!pwd->pw_passwd) {
232 syslog(LOG_INFO, "Bad Login ClearTxtUAM: no password for %s",
238 if ( kcheckuser( pwd, password) == 0)
242 p = crypt(password, pwd->pw_passwd);
243 if (strcmp(p, pwd->pw_passwd) != 0) {
244 syslog(LOG_INFO, "Bad Login ClearTxtUAM: %s: bad password", username);
248 /* Login successful */
249 append(out, loginok, strlen(loginok));
250 syslog(LOG_INFO, "Login ClearTxtUAM: %s", username);
255 static int uam_setup(const char *path)
257 if (uam_register(UAM_SERVER_LOGIN, path, "Cleartxt Passwrd",
258 passwd_login, NULL, NULL) < 0)
260 if (uam_register(UAM_SERVER_PRINTAUTH, path, "ClearTxtUAM",
267 static void uam_cleanup(void)
269 uam_unregister(UAM_SERVER_LOGIN, "Cleartxt Passwrd");
270 uam_unregister(UAM_SERVER_PRINTAUTH, "ClearTxtUAM");
273 UAM_MODULE_EXPORT struct uam_export uams_clrtxt = {
276 uam_setup, uam_cleanup