2 * $Id: uams_passwd.c,v 1.6 2001-02-27 17:07:43 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>
37 static int passwd_login(void *obj, struct passwd **uam_pwd,
38 char *ibuf, int ibuflen,
39 char *rbuf, int *rbuflen)
50 if (uam_afpserver_option(obj, UAM_OPTION_USERNAME,
51 (void *) &username, &ulen) < 0)
54 len = (unsigned char) *ibuf++;
56 return( AFPERR_PARAM );
59 memcpy(username, ibuf, len );
61 username[ len ] = '\0';
62 if ((unsigned long) ibuf & 1) /* pad character */
64 ibuf[ PASSWDLEN ] = '\0';
66 if (( pwd = uam_getname(username, ulen)) == NULL ) {
70 syslog(LOG_INFO, "cleartext login: %s", username);
71 if (uam_checkuser(pwd) < 0)
72 return AFPERR_NOTAUTH;
75 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
76 syslog( LOG_INFO, "no shadow passwd entry for %s", username);
77 return AFPERR_NOTAUTH;
79 pwd->pw_passwd = sp->sp_pwdp;
83 return AFPERR_NOTAUTH;
87 p = crypt( ibuf, pwd->pw_passwd );
88 if ( strcmp( p, pwd->pw_passwd ) == 0 )
91 return AFPERR_NOTAUTH;
97 static int passwd_changepw(void *obj, char *username,
98 struct passwd *pwd, char *ibuf,
99 int ibuflen, char *rbuf, int *rbuflen)
104 char pw[PASSWDLEN + 1], *p;
105 uid_t uid = geteuid();
107 if (uam_checkuser(pwd) < 0)
108 return AFPERR_ACCESS;
111 memcpy(pw, ibuf, PASSWDLEN);
112 memset(ibuf, 0, PASSWDLEN);
113 pw[PASSWDLEN] = '\0';
116 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
117 syslog( LOG_INFO, "no shadow passwd entry for %s", username);
120 pwd->pw_passwd = sp->sp_pwdp;
123 p = crypt(pw, pwd->pw_passwd );
124 if (strcmp( p, pwd->pw_passwd )) {
125 memset(pw, 0, sizeof(pw));
126 return AFPERR_NOTAUTH;
131 ibuf[PASSWDLEN] = '\0';
141 /* Printer ClearTxtUAM login */
142 static int passwd_printer(start, stop, username, out)
143 char *start, *stop, *username;
151 char password[PASSWDLEN + 1] = "\0";
152 static const char *loginok = "0\r";
155 data = (char *)malloc(stop - start + 1);
156 strncpy(data, start, stop - start + 1);
158 /* We are looking for the following format in data:
159 * (username) (password)
161 * Let's hope username doesn't contain ") ("!
164 /* Parse input for username in () */
165 if ((p = strchr(data, '(' )) == NULL) {
166 syslog(LOG_INFO,"Bad Login ClearTxtUAM: username not found in string");
171 if ((q = strstr(data, ") (" )) == NULL) {
172 syslog(LOG_INFO,"Bad Login ClearTxtUAM: username not found in string");
176 strncpy(username, p, q - p);
178 /* Parse input for password in next () */
180 if ((q = strrchr(data, ')' )) == NULL) {
181 syslog(LOG_INFO,"Bad Login ClearTxtUAM: password not found in string");
185 strncpy(password, p, q - p);
187 /* Done copying username and password, clean up */
190 ulen = strlen(username);
192 if (( pwd = uam_getname(username, ulen)) == NULL ) {
193 syslog(LOG_INFO, "Bad Login ClearTxtUAM: ( %s ) not found ",
198 if (uam_checkuser(pwd) < 0) {
199 /* syslog of error happens in uam_checkuser */
204 if (( sp = getspnam( pwd->pw_name )) == NULL ) {
205 syslog(LOG_INFO, "Bad Login ClearTxtUAM: no shadow passwd entry for %s",
209 pwd->pw_passwd = sp->sp_pwdp;
212 if (!pwd->pw_passwd) {
213 syslog(LOG_INFO, "Bad Login ClearTxtUAM: no password for %s",
219 if ( kcheckuser( pwd, password) == 0)
223 p = crypt(password, pwd->pw_passwd);
224 if (strcmp(p, pwd->pw_passwd) != 0) {
225 syslog(LOG_INFO, "Bad Login ClearTxtUAM: %s: bad password", username);
229 /* Login successful */
230 append(out, loginok, strlen(loginok));
231 syslog(LOG_INFO, "Login ClearTxtUAM: %s", username);
236 static int uam_setup(const char *path)
238 if (uam_register(UAM_SERVER_LOGIN, path, "Cleartxt Passwrd",
239 passwd_login, NULL, NULL) < 0)
241 if (uam_register(UAM_SERVER_PRINTAUTH, path, "ClearTxtUAM",
248 static void uam_cleanup(void)
250 uam_unregister(UAM_SERVER_LOGIN, "Cleartxt Passwrd");
251 uam_unregister(UAM_SERVER_PRINTAUTH, "ClearTxtUAM");
254 UAM_MODULE_EXPORT struct uam_export uams_clrtxt = {
257 uam_setup, uam_cleanup