- found_user = getuser(&CC->usersupp, username);
- if (found_user != 0) {
- p = (struct passwd *) getpwnam(username);
- if (p != NULL) {
- strcpy(autoname, p->pw_gecos);
- for (a = 0; a < strlen(autoname); ++a)
- if (autoname[a] == ',')
- autoname[a] = 0;
- found_user = getuser(&CC->usersupp, autoname);
+
+ if (trythisname == NULL) return login_not_found;
+ safestrncpy(username, trythisname, USERNAME_SIZE);
+ striplt(username);
+
+ if (strlen(username) == 0) {
+ return login_not_found;
+ }
+
+ if (config.c_auth_mode == 1) {
+
+ /* host auth mode */
+
+ struct passwd pd;
+ struct passwd *tempPwdPtr;
+ char pwdbuffer[256];
+
+ lprintf(CTDL_DEBUG, "asking host about <%s>\n", username);
+#ifdef SOLARIS_GETPWUID
+ tempPwdPtr = getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer);
+#else
+ getpwnam_r(username, &pd, pwdbuffer, sizeof pwdbuffer, &tempPwdPtr);
+#endif
+ if (tempPwdPtr == NULL) {
+ return login_not_found;
+ }
+ lprintf(CTDL_DEBUG, "found it! uid=%ld, gecos=%s\n", (long)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 {
+ /* native auth mode */
+
+ struct recptypes *valid = NULL;
+
+ /* First, try to log in as if the supplied name is a display name */
+ found_user = getuser(&CC->user, username);
+
+ /* If that didn't work, try to log in as if the supplied name
+ * is an e-mail address
+ */
+ if (found_user != 0) {
+ valid = validate_recipients(username);
+ if (valid != NULL) {
+ if (valid->num_local == 1) {
+ found_user = getuser(&CC->user, valid->recp_local);
+ }
+ free_recipients(valid);
+ }