2 ** Copyright 1998 - 2000 Double Precision, Inc. See COPYING for
3 ** distribution information.
7 #include "courier_auth_config.h"
19 #include "authcustom.h"
20 #include "courierauthdebug.h"
23 int auth_custom_pre(const char *userid
, const char *service
,
24 int (*callback
)(struct authinfo
*, void *),
27 return (authcustomcommon(userid
, 0, callback
, arg
));
30 static int do_auth_custom(const char *, struct authinfo
*);
32 int authcustomcommon(const char *user
, const char *pass
,
33 int (*callback
)(struct authinfo
*, void *),
39 memset(&auth
, 0, sizeof(auth
));
41 rc
=do_auth_custom(user
, &auth
);
47 return (0); /* Just get the authentication info */
51 if (strcmp(pass
, auth
.clearpasswd
))
56 const char *p
=auth
.passwd
;
58 if (!p
|| authcheckpassword(pass
, p
))
62 auth
.clearpasswd
=pass
;
63 return ((*callback
)(&auth
, arg
));
66 static int do_auth_custom(const char *userid
, struct authinfo
*authinfo
)
69 ** Insert custom authentication code here. This code must obtain
70 ** authentication information for account 'userid'.
72 ** If you need to link with specific external libraries (-lnsl_s,
73 ** et al), you'll just have to bite the bullet, install automake
74 ** and autoconf, then set authcustom.libsdep and authcustom_LDADD
79 ** If userid does not exist, return (-1).
82 DPRINTF("authcustom: nothing implemented in do_auth_custom()");
86 ** If there is some kind of a system problem, that is you are
87 ** unable to check whether userid is valid (the back end database
88 ** is down, or something) return (1).
92 ** Otherwise, initialize the authinfo structure, and return (0).
94 ** NOTES: this function can be called repeated within a single
95 ** process, in certain contexts. Do not simply dynamically
96 ** allocate memory for all the character strings, each time, because
97 ** the caller WILL NOT free the memory of any dynamically allocated
98 ** strings. If you keep dynamically allocating memory, each time,
99 ** you're going to get a memory leak, somewhere, and YOU'LL FUCK
100 ** YOURSELF. What you should do is either use a static buffer,
101 ** or dynamically allocate some memory, and free that memory on
102 ** the next function call.
106 ** If you open any files, you MUST set FD_CLOEXEC bit on any
107 ** file descriptor you create (open files, sockets, whatnot).
109 ** Someone else might do a fork and an exec, so you need to make
110 ** sure things get cleaned up, in that event.
112 ** Fields in the auth structure:
114 ** sysusername - REQUIRED - user name, should simply be userid,
115 ** unless you know what you're doing.
116 ** sysuserid - REQUIRED - pointer to the user's uid_t (yes, it's
118 ** sysgroupid - REQUIRED - gid_t, the group ID of the user.
120 ** homedir - REQUIRED - home directory.
122 ** address - REQUIRED - the 'identity' of the authenticated user,
123 ** the e-mail address. It is acceptable to set
124 ** this field also to userid, if you can't think
125 ** of anything better to do.
127 ** fullname - OPTIONAL - user's full name.
129 ** maildir - OPTIONAL - user's primary maildir ($HOME/Maildir default)
131 ** quota - OPTIONAL - user's maildir quota (see a README somewhere)
133 ** passwd, clearpasswd - one of these fields must be initialized,
134 ** either one is ok. Initialize clearpasswd
135 ** if you store cleartext passwords. If you
136 ** store crypted passwords, initialize passwd.
140 void authcustomclose()
143 ** Place any cleanup here.