*
*/
-#ifdef DLL_EXPORT
-#define IN_LIBCIT
-#endif
-
#include "sysdep.h"
#include <errno.h>
#include <stdlib.h>
{
char usernamekey[USERNAME_SIZE];
- char sysuser_name[USERNAME_SIZE];
struct cdbdata *cdbus;
- int using_sysuser = 0;
if (usbuf != NULL) {
memset(usbuf, 0, sizeof(struct ctdluser));
}
-#ifdef ENABLE_AUTOLOGIN
- if (CtdlAssociateSystemUser(sysuser_name, name) == 0) {
- ++using_sysuser;
- }
-#endif
-
- if (using_sysuser) {
- makeuserkey(usernamekey, sysuser_name);
- }
- else {
- makeuserkey(usernamekey, name);
- }
-
+ makeuserkey(usernamekey, name);
cdbus = cdb_fetch(CDB_USERS, usernamekey, strlen(usernamekey));
+
if (cdbus == NULL) { /* user not found */
return(1);
}
}
+#ifdef ENABLE_AUTOLOGIN
/*
- * See if we can translate a system login name (i.e. from /etc/passwd)
- * to a Citadel screen name. Returns 0 if one is found.
+ * getuserbyuid() - get user by system uid (for PAM mode authentication)
+ * returns 0 if user was found
+ *
+ * WARNING: don't use this function unless you absolutely have to. It does
+ * a sequential search and therefore is computationally expensive.
*/
-int CtdlAssociateSystemUser(char *screenname, char *loginname) {
- struct passwd *p;
- int a;
+int getuserbyuid(struct ctdluser *usbuf, uid_t number)
+{
+ struct cdbdata *cdbus;
- p = (struct passwd *) getpwnam(loginname);
- if (p != NULL) {
- strcpy(screenname, p->pw_gecos);
- for (a = 0; a < strlen(screenname); ++a) {
- if (screenname[a] == ',') {
- screenname[a] = 0;
- }
+ cdb_rewind(CDB_USERS);
+
+ while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
+ memset(usbuf, 0, sizeof(struct ctdluser));
+ memcpy(usbuf, cdbus->ptr,
+ ((cdbus->len > sizeof(struct ctdluser)) ?
+ sizeof(struct ctdluser) : cdbus->len));
+ cdb_free(cdbus);
+ if (usbuf->uid == number) {
+ cdb_close_cursor(CDB_USERS);
+ return (0);
}
- return(0);
}
- return(1);
+ return (-1);
}
+#endif /* ENABLE_AUTOLOGIN */
{
char username[SIZ];
int found_user;
- struct recptypes *valid = NULL;
+
+ if ((CC->logged_in)) {
+ return login_already_logged_in;
+ }
if (trythisname == NULL) return login_not_found;
safestrncpy(username, trythisname, USERNAME_SIZE);
striplt(username);
- if ((CC->logged_in)) {
- return login_already_logged_in;
+ if (strlen(username) == 0) {
+ return login_not_found;
}
+#ifdef ENABLE_AUTOLOGIN
+
+ /* If this is an autologin build, the only valid auth source is the
+ * host operating system.
+ */
+ struct passwd pd;
+ struct passwd *tempPwdPtr;
+ char pwdbuffer[256];
+
+ lprintf(CTDL_DEBUG, "asking host about <%s>\n", username);
+ getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
+ if (tempPwdPtr == NULL) {
+ return login_not_found;
+ }
+ lprintf(CTDL_DEBUG, "found it! uid=%d, gecos=%s\n", pd.pw_uid, pd.pw_gecos);
+
+ /* Locate the associated Citadel account.
+ * If not found, make one attempt to create it.
+ */
+ found_user = getuserbyuid(&CC->user, pd.pw_uid);
+ if (found_user != 0) {
+ create_user(username, 0);
+ found_user = getuserbyuid(&CC->user, pd.pw_uid);
+ }
+
+#else /* ENABLE_AUTOLOGIN */
+ struct recptypes *valid = NULL;
+
/* First, try to log in as if the supplied name is a display name */
found_user = getuser(&CC->user, username);
}
}
-#ifdef ENABLE_AUTOLOGIN
- /* If we haven't found the account yet, and the supplied name
- * is a login name on the underlying host system, create the
- * account.
- */
- if (found_user != 0) {
- struct passwd *p = (struct passwd *) getpwnam(username);
-
- if (p != NULL) {
- create_user(username, 0);
- found_user = getuser(&CC->user, username);
- }
- }
#endif /* ENABLE_AUTOLOGIN */
/* Did we find something? */
if (!strcasecmp(CC->user.fullname, config.c_sysadm)) {
CC->user.axlevel = 6;
}
+
+#ifdef ENABLE_AUTOLOGIN
+ /* If we're authenticating off the host system, automatically give
+ * root the highest level of access.
+ */
+ if (CC->user.uid == 0) {
+ CC->user.axlevel = 6;
+ }
+#endif
+
lputuser(&CC->user);
/*
#ifdef ENABLE_AUTOLOGIN
- /* A uid of CTDLUID or -1 indicates that this user exists only in
- * Citadel, not in the underlying operating system.
- */
- if ( (CC->user.uid == CTDLUID) || (CC->user.uid == (-1)) ) {
- strproc(password);
- strproc(CC->user.password);
- code = strcasecmp(CC->user.password, password);
+
+ if (validpw(CC->user.uid, password)) {
+ code = 0;
+ /* we could get rid of this */
+ lgetuser(&CC->user, CC->curr_user);
+ safestrncpy(CC->user.password, password, sizeof CC->user.password);
+ lputuser(&CC->user);
+ /* */
}
- /* Any other uid means we have to check the system password database */
else {
- if (validpw(CC->user.uid, password)) {
- code = 0;
- lgetuser(&CC->user, CC->curr_user);
- safestrncpy(CC->user.password, password,
- sizeof CC->user.password);
- lputuser(&CC->user);
- }
+ code = (-1);
}
#else /* ENABLE_AUTOLOGIN */
+
+ strproc(password);
+ strproc(CC->user.password);
+ code = strcasecmp(CC->user.password, password);
strproc(password);
strproc(CC->user.password);
code = strcasecmp(CC->user.password, password);
cdb_delete(CDB_USERS, usernamekey, strlen(usernamekey));
/* remove the user's bio file */
- snprintf(filename, sizeof filename,
-#ifndef HAVE_DATA_DIR
- "."
-#else
- DATA_DIR
-#endif
- "/bio/%ld", usbuf.usernum);
+ snprintf(filename,
+ sizeof filename,
+ "%s/%ld",
+ ctdl_bio_dir,
+ usbuf.usernum);
unlink(filename);
/* remove the user's picture */
- snprintf(filename, sizeof filename,
-#ifndef HAVE_DATA_DIR
- "."
-#else
- DATA_DIR
-#endif
- "/userpics/%ld.gif", usbuf.usernum);
+ snprintf(filename,
+ sizeof filename,
+ "%s/%ld.gif",
+ ctdl_image_dir,
+ usbuf.usernum);
unlink(filename);
return (0);
struct ctdlroom qrbuf;
char username[256];
char mailboxname[ROOMNAMELEN];
- uid_t uid;
+ uid_t uid = (-1);
safestrncpy(username, newusername, sizeof username);
strproc(username);
#ifdef ENABLE_AUTOLOGIN
- {
- struct passwd *p = (struct passwd *) getpwnam(username);
+ struct passwd pd;
+ struct passwd *tempPwdPtr;
+ char pwdbuffer[256];
- if (p != NULL) {
- extract_token(username, p->pw_gecos, 0, ',', sizeof username);
- uid = p->pw_uid;
- } else {
- uid = (-1);
- }
+ getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
+ if (tempPwdPtr != NULL) {
+ extract_token(username, pd.pw_gecos, 0, ',', sizeof username);
+ uid = pd.pw_uid;
+ }
+ else {
+ return (ERROR + NO_SUCH_USER);
}
-#else
- uid = (-1);
#endif
if (!getuser(&usbuf, username)) {
int a;
char username[26];
+#ifdef ENABLE_AUTOLOGIN
+ cprintf("%d This system does not use native mode authentication.\n",
+ ERROR + NOT_HERE);
+ return;
+#endif /* ENABLE_AUTOLOGIN */
+
if (config.c_disable_newu) {
cprintf("%d Self-service user account creation "
"is disabled on this system.\n", ERROR + NOT_HERE);
CtdlSetRelationship(&vbuf, &USscratch, &CC->room);
/* post a message in Aide> saying what we just did */
- snprintf(bbb, sizeof bbb, "%s %s %s> by %s\n",
+ snprintf(bbb, sizeof bbb, "%s has been %s \"%s\" by %s.\n",
iuser,
((op == 1) ? "invited to" : "kicked out of"),
CC->room.QRname,
CC->user.fullname);
- aide_message(bbb);
+ aide_message(bbb,"User Admin Message");
return(0);
}
}
if (deleted) {
- sprintf(notify, "User <%s> deleted by %s\n",
+ sprintf(notify, "User \"%s\" has been deleted by %s.\n",
usbuf.fullname, CC->user.fullname);
- aide_message(notify);
+ aide_message(notify, "User Deletion Message");
}
cprintf("%d Ok", CIT_OK);