Imported Upstream version 0.66.1
[hcoop/debian/courier-authlib.git] / preauthpwd.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#if HAVE_UNISTD_H
15#include <unistd.h>
16#endif
17
18#include "auth.h"
19#include "courierauthdebug.h"
20
d9898ee8 21
22int auth_pwd_pre(const char *userid, const char *service,
23 int (*callback)(struct authinfo *, void *),
24 void *arg)
25{
26struct authinfo auth;
27struct passwd *pw;
28
29 memset(&auth, 0, sizeof(auth));
30
31 if ((pw=getpwnam(userid)) == 0)
32 {
33 if (errno == ENOMEM) return (1);
34 return (-1);
35 }
36
37 auth.sysusername=userid;
38 auth.sysgroupid=pw->pw_gid;
39 auth.homedir=pw->pw_dir;
40 auth.address=userid;
41 auth.fullname=pw->pw_gecos;
42 auth.passwd=pw->pw_passwd;
43
44 courier_authdebug_authinfo("DEBUG: authpwd: ", &auth, 0, pw->pw_passwd);
45 return ((*callback)(&auth, arg));
46}