Import Upstream version 0.69.0
[hcoop/debian/courier-authlib.git] / preauthmysql.cpp
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 extern "C" {
19 #include "auth.h"
20 }
21 #include "authmysql.h"
22
23 int auth_mysql_pre(const char *user, const char *service,
24 int (*callback)(struct authinfo *, void *), void *arg)
25 {
26 authmysqluserinfo authinfo;
27 struct authinfo aa;
28
29 if (!auth_mysql_getuserinfo(user, service, authinfo))
30 /* Fatal error - such as MySQL being down */
31 return (1);
32
33 if (authinfo.home.size() == 0) /* User not found */
34 return (-1);
35
36 memset(&aa, 0, sizeof(aa));
37
38 /*aa.sysusername=user;*/
39 aa.sysuserid= &authinfo.uid;
40 aa.sysgroupid= authinfo.gid;
41
42 #define STR(z) (authinfo.z.size() ? authinfo.z.c_str():0)
43
44 aa.homedir=STR(home);
45 aa.maildir=STR(maildir);
46 aa.address=STR(username);
47 aa.passwd=STR(cryptpw);
48 aa.clearpasswd=STR(clearpw);
49 aa.fullname=STR(fullname);
50 aa.quota=STR(quota);
51 aa.options=STR(options);
52 return ((*callback)(&aa, arg));
53 }