Minimize spurious changes, so that we match debian more closely.
[hcoop/debian/courier-authlib.git] / preauthpam.c
CommitLineData
d9898ee8 1/*
2** Copyright 1998 - 1999 Double Precision, Inc. See COPYING for
3** distribution information.
4*/
5
6#if HAVE_CONFIG_H
7#include "courier_auth_config.h"
8#endif
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12#include <errno.h>
13#include <pwd.h>
14#include "auth.h"
15#include "courierauthdebug.h"
16
17#if HAVE_SHADOW_H
18#include <shadow.h>
19#endif
20
21static const char rcsid[]="$Id: preauthpam.c,v 1.12 2005/02/20 04:41:20 mrsam Exp $";
22
23int auth_pam_pre(const char *userid, const char *service,
24 int (*callback)(struct authinfo *, void *),
25 void *arg)
26{
27struct authinfo auth;
28struct passwd *pw;
29#if HAVE_GETSPENT
30struct spwd *spw;
31#endif
32
33 memset(&auth, 0, sizeof(auth));
34
35 if ((pw=getpwnam(userid)) == 0)
36 {
37 if (errno == ENOMEM) return (1);
38 DPRINTF("authpam: username '%s' not found in password file", userid);
39 errno=EPERM;
40 return (-1);
41 }
42
43 auth.sysusername=userid;
44 auth.sysgroupid=pw->pw_gid;
45 auth.homedir=pw->pw_dir;
46 auth.address=userid;
47 auth.fullname=pw->pw_gecos;
48 auth.passwd=pw->pw_passwd;
49
50#if HAVE_GETSPENT
51 if ((spw=getspnam(userid)) != 0)
52 auth.passwd=spw->sp_pwdp;
53#endif
54 courier_authdebug_authinfo("DEBUG: authpam: ", &auth, 0, pw->pw_passwd);
55
56 return ((*callback)(&auth, arg));
57}