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.
24 #include <atalk/afp.h>
25 #include <atalk/uam.h>
30 static int passwd_login(void *obj, struct passwd **uam_pwd,
31 char *ibuf, int ibuflen,
32 char *rbuf, int *rbuflen)
43 if (uam_afpserver_option(obj, UAM_OPTION_USERNAME,
44 (void *) &username, &ulen) < 0)
47 len = (unsigned char) *ibuf++;
49 return( AFPERR_PARAM );
52 memcpy(username, ibuf, len );
54 username[ len ] = '\0';
55 if ((unsigned long) ibuf & 1) /* pad character */
57 ibuf[ PASSWDLEN ] = '\0';
59 if (( pwd = uam_getname(username, ulen)) == NULL ) {
63 syslog(LOG_INFO, "cleartext login: %s", username);
64 if (uam_checkuser(pwd) < 0)
65 return AFPERR_NOTAUTH;
68 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
69 syslog( LOG_INFO, "no shadow passwd entry for %s", username);
70 return AFPERR_NOTAUTH;
72 pwd->pw_passwd = sp->sp_pwdp;
76 return AFPERR_NOTAUTH;
80 p = crypt( ibuf, pwd->pw_passwd );
81 if ( strcmp( p, pwd->pw_passwd ) == 0 )
84 return AFPERR_NOTAUTH;
90 static int passwd_changepw(void *obj, char *username,
91 struct passwd *pwd, char *ibuf,
92 int ibuflen, char *rbuf, int *rbuflen)
97 char pw[PASSWDLEN + 1], *p;
98 uid_t uid = geteuid();
100 if (uam_checkuser(pwd) < 0)
101 return AFPERR_ACCESS;
104 memcpy(pw, ibuf, PASSWDLEN);
105 memset(ibuf, 0, PASSWDLEN);
106 pw[PASSWDLEN] = '\0';
109 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
110 syslog( LOG_INFO, "no shadow passwd entry for %s", username);
113 pwd->pw_passwd = sp->sp_pwdp;
116 p = crypt(pw, pwd->pw_passwd );
117 if (strcmp( p, pwd->pw_passwd )) {
118 memset(pw, 0, sizeof(pw));
119 return AFPERR_NOTAUTH;
124 ibuf[PASSWDLEN] = '\0';
134 /* Printer ClearTxtUAM login */
135 static int passwd_printer(start, stop, username, out)
136 char *start, *stop, *username;
144 char password[PASSWDLEN + 1] = "\0";
145 static const char *loginok = "0\r";
148 data = (char *)malloc(stop - start + 1);
149 strncpy(data, start, stop - start + 1);
151 /* We are looking for the following format in data:
152 * (username) (password)
154 * Let's hope username doesn't contain ") ("!
157 /* Parse input for username in () */
158 if ((p = strchr(data, '(' )) == NULL) {
159 syslog(LOG_INFO,"Bad Login ClearTxtUAM: username not found in string");
164 if ((q = strstr(data, ") (" )) == NULL) {
165 syslog(LOG_INFO,"Bad Login ClearTxtUAM: username not found in string");
169 strncpy(username, p, q - p);
171 /* Parse input for password in next () */
173 if ((q = strrchr(data, ')' )) == NULL) {
174 syslog(LOG_INFO,"Bad Login ClearTxtUAM: password not found in string");
178 strncpy(password, p, q - p);
180 /* Done copying username and password, clean up */
183 ulen = strlen(username);
185 if (( pwd = uam_getname(username, ulen)) == NULL ) {
186 syslog(LOG_INFO, "Bad Login ClearTxtUAM: ( %s ) not found ",
191 if (uam_checkuser(pwd) < 0) {
192 /* syslog of error happens in uam_checkuser */
197 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
198 syslog(LOG_INFO, "Bad Login ClearTxtUAM: no shadow passwd entry for %s",
202 pwd->pw_passwd = sp->sp_pwdp;
205 if (!pwd->pw_passwd) {
206 syslog(LOG_INFO, "Bad Login ClearTxtUAM: no password for %s",
212 if ( kcheckuser( pwd, password) == 0)
216 p = crypt(password, pwd->pw_passwd);
217 if (strcmp(p, pwd->pw_passwd) != 0) {
218 syslog(LOG_INFO, "Bad Login ClearTxtUAM: %s: bad password", username);
222 /* Login successful */
223 append(out, loginok, strlen(loginok));
224 syslog(LOG_INFO, "Login ClearTxtUAM: %s", username);
229 static int uam_setup(const char *path)
231 if (uam_register(UAM_SERVER_LOGIN, path, "Cleartxt Passwrd",
232 passwd_login, NULL, NULL) < 0)
234 if (uam_register(UAM_SERVER_PRINTAUTH, path, "ClearTxtUAM",
241 static void uam_cleanup(void)
243 uam_unregister(UAM_SERVER_LOGIN, "Cleartxt Passwrd");
244 uam_unregister(UAM_SERVER_PRINTAUTH, "ClearTxtUAM");
247 UAM_MODULE_EXPORT struct uam_export uams_clrtxt = {
250 uam_setup, uam_cleanup