1 /* Copyright (c) 1990,1993 Regents of The University of Michigan.
2 * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu)
3 * All Rights Reserved. See COPYRIGHT.
28 #include <atalk/afp.h>
29 #include <atalk/uam.h>
34 static int passwd_login(void *obj, struct passwd **uam_pwd,
35 char *ibuf, int ibuflen,
36 char *rbuf, int *rbuflen)
47 if (uam_afpserver_option(obj, UAM_OPTION_USERNAME,
48 (void *) &username, &ulen) < 0)
51 len = (unsigned char) *ibuf++;
53 return( AFPERR_PARAM );
56 memcpy(username, ibuf, len );
58 username[ len ] = '\0';
59 if ((unsigned long) ibuf & 1) /* pad character */
61 ibuf[ PASSWDLEN ] = '\0';
63 if (( pwd = uam_getname(username, ulen)) == NULL ) {
67 syslog(LOG_INFO, "cleartext login: %s", username);
68 if (uam_checkuser(pwd) < 0)
69 return AFPERR_NOTAUTH;
72 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
73 syslog( LOG_INFO, "no shadow passwd entry for %s", username);
74 return AFPERR_NOTAUTH;
76 pwd->pw_passwd = sp->sp_pwdp;
80 return AFPERR_NOTAUTH;
84 p = crypt( ibuf, pwd->pw_passwd );
85 if ( strcmp( p, pwd->pw_passwd ) == 0 )
88 return AFPERR_NOTAUTH;
94 static int passwd_changepw(void *obj, char *username,
95 struct passwd *pwd, char *ibuf,
96 int ibuflen, char *rbuf, int *rbuflen)
101 char pw[PASSWDLEN + 1], *p;
102 uid_t uid = geteuid();
104 if (uam_checkuser(pwd) < 0)
105 return AFPERR_ACCESS;
108 memcpy(pw, ibuf, PASSWDLEN);
109 memset(ibuf, 0, PASSWDLEN);
110 pw[PASSWDLEN] = '\0';
113 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
114 syslog( LOG_INFO, "no shadow passwd entry for %s", username);
117 pwd->pw_passwd = sp->sp_pwdp;
120 p = crypt(pw, pwd->pw_passwd );
121 if (strcmp( p, pwd->pw_passwd )) {
122 memset(pw, 0, sizeof(pw));
123 return AFPERR_NOTAUTH;
128 ibuf[PASSWDLEN] = '\0';
138 /* Printer ClearTxtUAM login */
139 static int passwd_printer(start, stop, username, out)
140 char *start, *stop, *username;
148 char password[PASSWDLEN + 1] = "\0";
149 static const char *loginok = "0\r";
152 data = (char *)malloc(stop - start + 1);
153 strncpy(data, start, stop - start + 1);
155 /* We are looking for the following format in data:
156 * (username) (password)
158 * Let's hope username doesn't contain ") ("!
161 /* Parse input for username in () */
162 if ((p = strchr(data, '(' )) == NULL) {
163 syslog(LOG_INFO,"Bad Login ClearTxtUAM: username not found in string");
168 if ((q = strstr(data, ") (" )) == NULL) {
169 syslog(LOG_INFO,"Bad Login ClearTxtUAM: username not found in string");
173 strncpy(username, p, q - p);
175 /* Parse input for password in next () */
177 if ((q = strrchr(data, ')' )) == NULL) {
178 syslog(LOG_INFO,"Bad Login ClearTxtUAM: password not found in string");
182 strncpy(password, p, q - p);
184 /* Done copying username and password, clean up */
187 ulen = strlen(username);
189 if (( pwd = uam_getname(username, ulen)) == NULL ) {
190 syslog(LOG_INFO, "Bad Login ClearTxtUAM: ( %s ) not found ",
195 if (uam_checkuser(pwd) < 0) {
196 /* syslog of error happens in uam_checkuser */
201 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
202 syslog(LOG_INFO, "Bad Login ClearTxtUAM: no shadow passwd entry for %s",
206 pwd->pw_passwd = sp->sp_pwdp;
209 if (!pwd->pw_passwd) {
210 syslog(LOG_INFO, "Bad Login ClearTxtUAM: no password for %s",
216 if ( kcheckuser( pwd, password) == 0)
220 p = crypt(password, pwd->pw_passwd);
221 if (strcmp(p, pwd->pw_passwd) != 0) {
222 syslog(LOG_INFO, "Bad Login ClearTxtUAM: %s: bad password", username);
226 /* Login successful */
227 append(out, loginok, strlen(loginok));
228 syslog(LOG_INFO, "Login ClearTxtUAM: %s", username);
233 static int uam_setup(const char *path)
235 if (uam_register(UAM_SERVER_LOGIN, path, "Cleartxt Passwrd",
236 passwd_login, NULL, NULL) < 0)
238 if (uam_register(UAM_SERVER_PRINTAUTH, path, "ClearTxtUAM",
245 static void uam_cleanup(void)
247 uam_unregister(UAM_SERVER_LOGIN, "Cleartxt Passwrd");
248 uam_unregister(UAM_SERVER_PRINTAUTH, "ClearTxtUAM");
251 UAM_MODULE_EXPORT struct uam_export uams_passwd = {
254 uam_setup, uam_cleanup