/*
- * $Id: auth.c,v 1.44.2.3.2.7 2003-11-14 14:37:37 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.
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);
+ 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;
}
}
/* 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;
}
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 (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;
}
#endif /* TRU64 */
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);
-
- *rbuflen += sizeof(tklen);
+ case 8: /* Panther Kerberos Token */
+ tklen = obj->sinfo.cryptedkey_len;
+ token = obj->sinfo.cryptedkey;
+ break;
+ default:
+ return AFPERR_NOOP;
+ break;
- /* use 8 bytes for token as OSX, don't know if it helps */
- if ( sizeof(pid_t) > 8) {
- LOG(log_error, logtype_afpd, "sizeof(pid_t) > 8" );
- return AFPERR_MISC;
}
- tklen = 8;
- tp = htons(tklen);
+ if (tklen == 0)
+ return AFPERR_MISC;
+
+ 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;
}
*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 ( sizeof(pid_t) > 8) {
- LOG(log_error, logtype_afpd, "sizeof(pid_t) > 8" );
+ if ( sizeof(pid_t) > SESSIONTOKEN_LEN) {
+ LOG(log_error, logtype_afpd, "sizeof(pid_t) > %u", SESSIONTOKEN_LEN );
return AFPERR_MISC;
}
- if (tklen != 8) {
+ if (tklen != SESSIONTOKEN_LEN) {
return AFPERR_MISC;
}
tklen = sizeof(pid_t);
/* our stuff is pid + zero pad */
ibuf += tklen;
- for (i = tklen; i < 8; i++, ibuf++) {
+ for (i = tklen; i < SESSIONTOKEN_LEN; i++, ibuf++) {
if (*ibuf != 0) {
return AFPERR_MISC;
}
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 (!pwd || ( i != AFP_OK && i != AFPERR_PWDEXPR))
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);
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 (!pwd || ( err != AFP_OK && err != AFPERR_PWDEXPR))
*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)
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))) {