| 1 | #ifndef courierauth_h |
| 2 | #define courierauth_h |
| 3 | |
| 4 | /* |
| 5 | ** Copyright 2004 Double Precision, Inc. See COPYING for |
| 6 | ** distribution information. |
| 7 | */ |
| 8 | |
| 9 | #include "courier_auth_config.h" |
| 10 | #include <sys/types.h> |
| 11 | |
| 12 | #ifdef __cplusplus |
| 13 | extern "C" { |
| 14 | #endif |
| 15 | |
| 16 | static const char courierauth_h_rcsid[]="$Id: courierauth.h,v 1.4 2005/02/21 03:34:19 mrsam Exp $"; |
| 17 | |
| 18 | /* |
| 19 | Callback authentication structure: |
| 20 | */ |
| 21 | |
| 22 | struct authinfo { |
| 23 | const char *sysusername; |
| 24 | const uid_t *sysuserid; |
| 25 | gid_t sysgroupid; |
| 26 | const char *homedir; |
| 27 | |
| 28 | const char *address; |
| 29 | const char *fullname; |
| 30 | const char *maildir; |
| 31 | const char *quota; |
| 32 | |
| 33 | const char *passwd; |
| 34 | const char *clearpasswd; /* For authldap */ |
| 35 | |
| 36 | const char *options; |
| 37 | |
| 38 | } ; |
| 39 | /* |
| 40 | Either sysusername or sysuserid may be NULL, but not both of them. |
| 41 | They, and sysgroupid, specify the authenticated user's system |
| 42 | userid and groupid. homedir points to the authenticated user's |
| 43 | home directory. address, fullname, and maildir, are obvious. |
| 44 | quota is populated with any maildir quota (see |
| 45 | maildir/README.maildirquota). |
| 46 | |
| 47 | 'options' is an optional string that contains per-user custom settings. |
| 48 | See "OPTIONS" above. |
| 49 | |
| 50 | After populating this tructure, the lookup function calls the |
| 51 | callback function that's specified in its second argument. The |
| 52 | callback function receives a pointer to the authinfo structure. |
| 53 | |
| 54 | The callback function also receives a context pointer, which is |
| 55 | the third argument to the lookup function. |
| 56 | |
| 57 | The lookup function should return a negative value if he userid |
| 58 | does not exist, a positive value if there was a temporary error |
| 59 | looking up the userid, or whatever is the return code from the |
| 60 | callback function, if the user exists. |
| 61 | */ |
| 62 | |
| 63 | |
| 64 | #define AUTHTYPE_LOGIN "login" /* authdata is userid\npassword\n */ |
| 65 | #define AUTHTYPE_CRAMMD5 "cram-md5" /* authdata is challenge\nresponse\n */ |
| 66 | #define AUTHTYPE_CRAMSHA1 "cram-sha1" /* authdata is challenge\nresponse\n */ |
| 67 | #define AUTHTYPE_CRAMSHA256 "cram-sha256" /* authdata is challenge\nresponse\n */ |
| 68 | |
| 69 | /* auth_generic: INTERNAL */ |
| 70 | |
| 71 | int auth_generic(const char *service, |
| 72 | const char *authtype, |
| 73 | char *authdata, |
| 74 | int (*callback_func)(struct authinfo *, void *), |
| 75 | void *callback_arg); |
| 76 | |
| 77 | /* Login request: */ |
| 78 | int auth_login(const char *service, |
| 79 | const char *userid, |
| 80 | const char *passwd, |
| 81 | int (*callback_func)(struct authinfo *, void *), |
| 82 | void *callback_arg); |
| 83 | |
| 84 | /* Return account info: */ |
| 85 | int auth_getuserinfo(const char *service, const char *uid, |
| 86 | int (*callback)(struct authinfo *, void *), |
| 87 | void *arg); |
| 88 | |
| 89 | /* Enumerate accounts */ |
| 90 | void auth_enumerate( void(*cb_func)(const char *name, |
| 91 | uid_t uid, |
| 92 | gid_t gid, |
| 93 | const char *homedir, |
| 94 | const char *maildir, |
| 95 | const char *options, |
| 96 | void *void_arg), |
| 97 | void *void_arg); |
| 98 | |
| 99 | /* Change the password */ |
| 100 | int auth_passwd(const char *service, |
| 101 | const char *uid, |
| 102 | const char *opwd, |
| 103 | const char *npwd); |
| 104 | |
| 105 | /* Utility function: parse OPTIONS string for a particular keyword */ |
| 106 | |
| 107 | extern int auth_getoptionenvint(const char *keyword); |
| 108 | extern char *auth_getoptionenv(const char *keyword); |
| 109 | extern char *auth_getoption(const char *options, const char *keyword); |
| 110 | |
| 111 | |
| 112 | /* |
| 113 | ** Utility function: typical action in a callback for auth_generic |
| 114 | ** or auth_login. Does the following: |
| 115 | ** |
| 116 | ** Drops root, takes uid/gid in ainfo. |
| 117 | ** |
| 118 | ** Changes current directory to the home directory. |
| 119 | ** |
| 120 | ** Returns: <0 - fatal error before dropping root. |
| 121 | ** >0 - fatal error after dropping root. |
| 122 | ** =0 - all's OK. |
| 123 | */ |
| 124 | |
| 125 | int auth_callback_default(struct authinfo *ainfo); |
| 126 | |
| 127 | #ifdef __cplusplus |
| 128 | } |
| 129 | #endif |
| 130 | |
| 131 | #endif |