/*
- * $Id: auth.c,v 1.44.2.3.2.3 2003-09-25 12:23:53 didg Exp $
+ * $Id: auth.c,v 1.44.2.3.2.14 2004-06-18 07:58:20 bfernhomberg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
#include <limits.h>
#include <string.h>
#include <ctype.h>
-
-#ifdef SHADOWPW
-#include <shadow.h>
-#endif /* SHADOWPW */
-
+#include <time.h>
#include <pwd.h>
#include <grp.h>
#include <atalk/logger.h>
return AFP_OK;
}
-static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void))
+
+static int afp_errpwdexpired(obj, ibuf, ibuflen, rbuf, rbuflen )
+AFPObj *obj;
+char *ibuf, *rbuf;
+int ibuflen, *rbuflen;
+{
+ *rbuflen = 0;
+ return AFPERR_PWDEXPR;
+}
+
+
+static int set_auth_switch(AFPObj *obj, int expired)
+{
+ int i;
+
+ if (expired) {
+ /*
+ * BF: expired password handling
+ * to allow the user to change his/her password we have to allow login
+ * but every following call except for FPChangePassword will be thrown
+ * away with an AFPERR_PWDEXPR error. (thanks to Leland Wallace from Apple
+ * for clarifying this)
+ */
+
+ for (i=0; i<=0xff; i++) {
+ uam_afpserver_action(i, UAM_AFPSERVER_PREAUTH, afp_errpwdexpired, NULL);
+ }
+ uam_afpserver_action(AFP_LOGOUT, UAM_AFPSERVER_PREAUTH, afp_logout, NULL);
+ uam_afpserver_action(AFP_CHANGEPW, UAM_AFPSERVER_PREAUTH, afp_changepw, NULL);
+ }
+ else {
+ afp_switch = postauth_switch;
+ switch (afp_version) {
+ case 31:
+ uam_afpserver_action(AFP_ENUMERATE_EXT2, UAM_AFPSERVER_POSTAUTH, afp_enumerate_ext2, NULL);
+ case 30:
+ uam_afpserver_action(AFP_ENUMERATE_EXT, UAM_AFPSERVER_POSTAUTH, afp_enumerate_ext, NULL);
+ uam_afpserver_action(AFP_BYTELOCK_EXT, UAM_AFPSERVER_POSTAUTH, afp_bytelock_ext, NULL);
+ /* catsearch_ext uses the same packet as catsearch FIXME double check this, it wasn't true for enue
+ enumerate_ext */
+ uam_afpserver_action(AFP_CATSEARCH_EXT, UAM_AFPSERVER_POSTAUTH, afp_catsearch_ext, NULL);
+ uam_afpserver_action(AFP_GETSESSTOKEN, UAM_AFPSERVER_POSTAUTH, afp_getsession, NULL);
+ uam_afpserver_action(AFP_READ_EXT, UAM_AFPSERVER_POSTAUTH, afp_read_ext, NULL);
+ uam_afpserver_action(AFP_WRITE_EXT, UAM_AFPSERVER_POSTAUTH, afp_write_ext, NULL);
+ uam_afpserver_action(AFP_DISCTOLDSESS, UAM_AFPSERVER_POSTAUTH, afp_disconnect, NULL);
+
+ case 22:
+ /*
+ * If first connection to a server is done in classic AFP2.2 version is used
+ * but OSX uses AFP3.x FPzzz command !
+ */
+ uam_afpserver_action(AFP_ZZZ, UAM_AFPSERVER_POSTAUTH, afp_zzz, NULL);
+ break;
+ }
+ }
+
+ return AFP_OK;
+}
+
+static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void), int expired)
{
#ifdef ADMIN_GRP
int admin = 0;
LOG(log_info, logtype_afpd, "login %s (uid %d, gid %d) %s", pwd->pw_name,
pwd->pw_uid, pwd->pw_gid , afp_versions[afp_version_index].av_name);
+#ifndef NO_DDP
if (obj->proto == AFPPROTO_ASP) {
ASP asp = obj->handle;
int addr_net = ntohs( asp->asp_sat.sat_addr.s_net );
} /* if (addr_net && addr_node ) */
} /* if (options->authprintdir) */
} /* if (obj->proto == AFPPROTO_ASP) */
+#endif
if (initgroups( pwd->pw_name, pwd->pw_gid ) < 0) {
#ifdef RUN_AS_USER
/* Basically if the user is in the admin group, we stay root */
if (( ngroups = getgroups( NGROUPS, groups )) < 0 ) {
- LOG(log_error, logtype_afpd, "login: getgroups: %s", strerror(errno) );
+ LOG(log_error, logtype_afpd, "login: %s getgroups: %s", pwd->pw_name, strerror(errno) );
return AFPERR_BADUAM;
}
+
#ifdef ADMIN_GRP
#ifdef DEBUG
LOG(log_info, logtype_afpd, "obj->options.admingid == %d", obj->options.admingid);
inet_ntoa( dsi->client.sin_addr ) );
if (setegid( pwd->pw_gid ) < 0 || seteuid( pwd->pw_uid ) < 0) {
- LOG(log_error, logtype_afpd, "login: %s", strerror(errno) );
+ LOG(log_error, logtype_afpd, "login: %s %s", pwd->pw_name, strerror(errno) );
return AFPERR_BADUAM;
}
}
#else /* TRU64 */
-#if 0
- if (setregid(pwd->pw_gid, pwd->pw_gid ) < 0 || setreuid(pwd->pw_uid,pwd->pw_uid ) < 0) {
-#endif
- if (setegid( pwd->pw_gid ) < 0 || seteuid( pwd->pw_uid ) < 0) {
- LOG(log_error, logtype_afpd, "login: %s", strerror(errno) );
- return AFPERR_BADUAM;
- }
+ if (setegid( pwd->pw_gid ) < 0 || seteuid( pwd->pw_uid ) < 0) {
+ LOG(log_error, logtype_afpd, "login: %s %s", pwd->pw_name, strerror(errno) );
+ return AFPERR_BADUAM;
+ }
#endif /* TRU64 */
/* There's probably a better way to do this, but for now, we just
#endif /* ADMIN_GRP */
uuid = pwd->pw_uid;
- afp_switch = postauth_switch;
- switch (afp_version) {
- case 31:
- uam_afpserver_action(AFP_ENUMERATE_EXT2, UAM_AFPSERVER_POSTAUTH, afp_enumerate_ext2, NULL);
- case 30:
- uam_afpserver_action(AFP_ENUMERATE_EXT, UAM_AFPSERVER_POSTAUTH, afp_enumerate_ext, NULL);
- uam_afpserver_action(AFP_BYTELOCK_EXT, UAM_AFPSERVER_POSTAUTH, afp_bytelock_ext, NULL);
- /* catsearch_ext uses the same packet as catsearch FIXME double check this, it wasn't true for enue
- enumerate_ext */
- uam_afpserver_action(AFP_CATSEARCH_EXT, UAM_AFPSERVER_POSTAUTH, afp_catsearch_ext, NULL);
- uam_afpserver_action(AFP_GETSESSTOKEN, UAM_AFPSERVER_POSTAUTH, afp_getsession, NULL);
- uam_afpserver_action(AFP_READ_EXT, UAM_AFPSERVER_POSTAUTH, afp_read_ext, NULL);
- uam_afpserver_action(AFP_WRITE_EXT, UAM_AFPSERVER_POSTAUTH, afp_write_ext, NULL);
- uam_afpserver_action(AFP_DISCTOLDSESS, UAM_AFPSERVER_POSTAUTH, afp_disconnect, NULL);
- uam_afpserver_action(AFP_ZZZ, UAM_AFPSERVER_POSTAUTH, afp_zzz, NULL);
+ set_auth_switch(obj, expired);
- break;
- }
obj->logout = logout;
#ifdef FORCE_UIDGID
obj->force_uid = 1;
save_uidgid ( &obj->uidgid );
-#endif
-
+#endif
+
return( AFP_OK );
}
rbuf += sizeof(retdata);
return AFP_OK;
}
+
+/* ---------------------- */
+static int create_session_token(AFPObj *obj)
+{
+ pid_t pid;
+
+ /* use 8 bytes for token as OSX, don't know if it helps */
+ if ( sizeof(pid_t) > SESSIONTOKEN_LEN) {
+ LOG(log_error, logtype_afpd, "sizeof(pid_t) > %u", SESSIONTOKEN_LEN );
+ return AFPERR_MISC;
+ }
+
+ if ( NULL == (obj->sinfo.sessiontoken = malloc(SESSIONTOKEN_LEN)) )
+ return AFPERR_MISC;
+
+ memset(obj->sinfo.sessiontoken, 0, SESSIONTOKEN_LEN);
+ obj->sinfo.sessiontoken_len = SESSIONTOKEN_LEN;
+ pid = getpid();
+ memcpy(obj->sinfo.sessiontoken, &pid, sizeof(pid_t));
+
+ return 0;
+}
+
+static int create_session_key(AFPObj *obj)
+{
+ /* create session key */
+ if (obj->sinfo.sessionkey == NULL) {
+ if (NULL == (obj->sinfo.sessionkey = malloc(SESSIONKEY_LEN)) )
+ return AFPERR_MISC;
+ uam_random_string(obj, obj->sinfo.sessionkey, SESSIONKEY_LEN);
+ obj->sinfo.sessionkey_len = SESSIONKEY_LEN;
+ }
+ return AFP_OK;
+}
+
/* ---------------------- */
int afp_getsession(obj, ibuf, ibuflen, rbuf, rbuflen )
u_int16_t type;
u_int32_t idlen = 0;
u_int32_t boottime;
-
- u_int16_t tklen, tp; /* FIXME: spec u_int32_t? */
- pid_t token;
- char *p;
+ u_int32_t tklen, tp;
+ char *token;
+ char *p;
*rbuflen = 0;
+ tklen = 0;
ibuf += 2;
ibuflen -= 2;
- memcpy(&type, ibuf, sizeof(type));
+ memcpy(&type, ibuf, sizeof(type));
type = ntohs(type);
ibuf += sizeof(type);
ibuflen -= sizeof(type);
+
+ if ( obj->sinfo.sessiontoken == NULL ) {
+ if ( create_session_token( obj ) )
+ return AFPERR_MISC;
+ }
+
/*
*
*/
return AFPERR_PARAM;
}
/* memcpy (id, ibuf, idlen) */
+ tklen = obj->sinfo.sessiontoken_len;
+ token = obj->sinfo.sessiontoken;
}
break;
case 3: /* Jaguar */
if (ibuflen < idlen || idlen > (90-10)) {
return AFPERR_PARAM;
}
- server_ipc_write(IPC_GETSESSION, idlen+8, p );
+ server_ipc_write(IPC_GETSESSION, idlen+8, p );
+ tklen = obj->sinfo.sessiontoken_len;
+ token = obj->sinfo.sessiontoken;
}
type = 0;
break;
- }
- *rbuflen = sizeof(type);
- type = htons(type);
- memcpy(rbuf, &type, sizeof(type));
- rbuf += sizeof(type);
+ case 8: /* Panther Kerberos Token */
+ tklen = obj->sinfo.cryptedkey_len;
+ token = obj->sinfo.cryptedkey;
+ break;
+ default:
+ return AFPERR_NOOP;
+ break;
- *rbuflen += sizeof(tklen);
+ }
- /* use at least 8 bytes for token as OSX, don't know if it helps */
- tklen = sizeof(pid_t);
- if (tklen < 8)
- tklen = 8;
+ if (tklen == 0)
+ return AFPERR_MISC;
- tp = htons(tklen);
+ tp = htonl(tklen);
memcpy(rbuf, &tp, sizeof(tklen));
rbuf += sizeof(tklen);
+ *rbuflen += sizeof(tklen);
+ memcpy(rbuf, token, tklen);
*rbuflen += tklen;
- memset(rbuf, 0, tklen);
- token = getpid();
- memcpy(rbuf, &token, sizeof(pid_t));
+
return AFP_OK;
}
u_int32_t tklen;
pid_t token;
+ int i;
*rbuflen = 0;
ibuf += 2;
+ /* check for guest user */
+ if ( 0 == (strcasecmp(obj->username, obj->options.guest)) ) {
+ return AFPERR_MISC;
+ }
+
memcpy(&type, ibuf, sizeof(type));
type = ntohs(type);
ibuf += sizeof(type);
tklen = ntohl(tklen);
ibuf += sizeof(tklen);
- if (tklen != sizeof(pid_t)) {
+ if ( sizeof(pid_t) > SESSIONTOKEN_LEN) {
+ LOG(log_error, logtype_afpd, "sizeof(pid_t) > %u", SESSIONTOKEN_LEN );
+ return AFPERR_MISC;
+ }
+ if (tklen != SESSIONTOKEN_LEN) {
return AFPERR_MISC;
}
+ tklen = sizeof(pid_t);
memcpy(&token, ibuf, tklen);
+
+ /* our stuff is pid + zero pad */
+ ibuf += tklen;
+ for (i = tklen; i < SESSIONTOKEN_LEN; i++, ibuf++) {
+ if (*ibuf != 0) {
+ return AFPERR_MISC;
+ }
+ }
+
/* killed old session, not easy */
server_ipc_write(IPC_KILLTOKEN, tklen, &token);
sleep(1);
ibuf += len;
ibuflen -= len;
+ if (AFP_OK != (i = create_session_key(obj)) )
+ return send_reply(obj, i);
+
i = afp_uam->u.uam_login.login(obj, &pwd, ibuf, ibuflen, rbuf, rbuflen);
- if (i || !pwd)
+
+ if (!pwd || ( i != AFP_OK && i != AFPERR_PWDEXPR))
return send_reply(obj, i);
- return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout));
+ return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout, ((i==AFPERR_PWDEXPR)?1:0)));
}
/* ---------------------- */
ibuflen--;
}
+ if (AFP_OK != (i = create_session_key(obj)) ) {
+ return send_reply(obj, i);
+ }
+
/* FIXME user name are in UTF8 */
i = afp_uam->u.uam_login.login_ext(obj, username, &pwd, ibuf, ibuflen, rbuf, rbuflen);
- if (i || !pwd)
+
+ if (!pwd || ( i != AFP_OK && i != AFPERR_PWDEXPR))
return send_reply(obj, i);
- return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout));
+ return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout, ((i==AFPERR_PWDEXPR)?1:0)));
}
/* ---------------------- */
return send_reply(obj, AFPERR_NOTAUTH );
}
- ibuf += 2;
+ ibuf += 2; ibuflen -= 2;
err = afp_uam->u.uam_login.logincont(obj, &pwd, ibuf, ibuflen,
rbuf, rbuflen);
- if (err || !pwd)
+ if (!pwd || ( err != AFP_OK && err != AFPERR_PWDEXPR))
return send_reply(obj, err);
- return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout));
+ return send_reply(obj, login(obj, pwd, afp_uam->u.uam_login.logout, ((err==AFPERR_PWDEXPR)?1:0)));
}
*rbuflen = 0;
ibuf += 2;
+ /* check if password change is allowed, OS-X ignores the flag.
+ * we shouldn't trust the client on this anyway.
+ * not sure about the "right" error code, NOOP for now */
+ if (!(obj->options.passwdbits & PASSWD_SET))
+ return AFPERR_NOOP;
+
/* make sure we can deal w/ this uam */
len = (unsigned char) *ibuf++;
if ((uam = auth_uamfind(UAM_SERVER_CHANGEPW, ibuf, len)) == NULL)
LOG(log_info, logtype_afpd, "password change %s.",
(ret == AFPERR_AUTHCONT) ? "continued" :
(ret ? "failed" : "succeeded"));
+ if ( ret == AFP_OK )
+ set_auth_switch(obj, 0);
+
return ret;
}
return -1;
if (!(start = UAM_LIST(type)))
- return 0; /* silently fail */
+ return 1; /* we don't know what to do with it, caller must free it */
uam_attach(start, uam);
return 0;
if (!path || !*path || !list || (len = strlen(path)) > sizeof(name) - 2)
return -1;
- strncpy(buf, list, sizeof(buf));
+ strlcpy(buf, list, sizeof(buf));
if ((p = strtok(buf, ",")) == NULL)
return -1;
}
while (p) {
- strncpy(name + len, p, sizeof(name) - len);
+ strlcpy(name + len, p, sizeof(name) - len);
LOG(log_debug, logtype_afpd, "uam: loading (%s)", name);
/*
if ((stat(name, &st) == 0) && (mod = uam_load(name, p))) {