int auth_shadow_pre(const char *userid, const char *service, int (*callback)(struct authinfo *, void *), void *arg) { struct authinfo auth; struct passwd *pw; struct spwd *spw; long today; memset(&auth, 0, sizeof(auth)); if ((pw=getpwnam(userid)) == NULL) { if (errno == ENOMEM) return 1; return -1; } if ((spw=getspnam(userid)) == NULL) { if (errno == ENOMEM) return 1; return -1; } today = (long)time(NULL)/(24L*60*60); if ((spw->sp_expire > 0) && (today > spw->sp_expire)) { DPRINTF("authshadow: %s - account expired", userid); return -1; /* account expired */ } if ((spw->sp_lstchg != -1) && (spw->sp_max != -1) && ((spw->sp_lstchg + spw->sp_max) < today)) { DPRINTF("authshadow: %s - password expired", userid); return -1; /* password expired */ } auth.sysusername=userid; auth.sysgroupid=pw->pw_gid; auth.homedir=pw->pw_dir; auth.address=userid; auth.fullname=pw->pw_gecos; auth.passwd=spw->sp_pwdp; courier_authdebug_authinfo("DEBUG: authshadow: ", &auth, 0, pw->pw_passwd); return ((*callback)(&auth, arg)); }
static int auth_sqlite_login(const char *service, char *authdata, int (*callback_func)(struct authinfo *, void *), void *callback_arg) { char *user, *pass; authsqliteuserinfo authinfo; struct authinfo aa; if ((user=strtok(authdata, "\n")) == 0 || (pass=strtok(0, "\n")) == 0) { errno=EPERM; return (-1); } if (!auth_sqlite_getuserinfo(user, service, authinfo)) // Fatal error - such as Sqlite being down { errno=EACCES; return (1); } if (!docheckpw(authinfo, pass)) return (-1); memset(&aa, 0, sizeof(aa)); aa.sysuserid= &authinfo.uid; aa.sysgroupid= authinfo.gid; aa.homedir=authinfo.home.c_str(); aa.maildir=authinfo.maildir.empty() ? NULL:authinfo.maildir.c_str(); aa.address=authinfo.username.c_str(); aa.quota=authinfo.quota.empty() ? NULL:authinfo.quota.c_str(); aa.fullname=authinfo.fullname.c_str(); aa.options=authinfo.options.c_str(); aa.clearpasswd=pass; aa.passwd=authinfo.cryptpw.c_str(); courier_authdebug_authinfo("DEBUG: authsqlite: ", &aa, authinfo.clearpw.c_str(), authinfo.cryptpw.c_str()); return (*callback_func)(&aa, callback_arg); }