nsauth.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. #include <config.h>
  11. #endif
  12. #ifndef __nsauth_h
  13. #define __nsauth_h
  14. /*
  15. * Description (nsauth.h)
  16. *
  17. * This file defines types and interfaces which pertain to client
  18. * authentication. The key types are Realm_t, which describes a
  19. * context for authentication, and ClAuth_t, which is used to
  20. * pass authentication information about a particular client
  21. * into and out of authentication interface functions.
  22. */
  23. #include "ssl.h"
  24. #include "cert.h" /* CERTCertificate for new ns security bin */
  25. #include "usi.h" /* identifier list support */
  26. #include "attrec.h" /* attribute record types */
  27. #include "nserror.h" /* error frame list support */
  28. #include "nsautherr.h" /* authentication error codes */
  29. /* Define a scalar IP address value */
  30. #ifndef __IPADDR_T_
  31. #define __IPADDR_T_
  32. typedef unsigned long IPAddr_t;
  33. #endif /* __IPADDR_T_ */
  34. /*
  35. * Description (UserObj_t)
  36. *
  37. * This type defines the structure of a user object. A user object
  38. * contains information about a user which might be contained in
  39. * an authentication database, including user name, password, user id,
  40. * and group membership.
  41. */
  42. typedef struct UserObj_s UserObj_t;
  43. struct UserObj_s
  44. {
  45. NTS_t uo_name; /* user account name */
  46. NTS_t uo_pwd; /* encrypted password */
  47. USI_t uo_uid; /* user id */
  48. USI_t uo_flags; /* bit flags */
  49. #define UOF_DBFLAGS 0x1f /* mask for flags stored in DB file */
  50. #define UOF_ERROR 0x20 /* error on last operation */
  51. #define UOF_NEW 0x40 /* new user object */
  52. #define UOF_MODIFIED 0x80 /* internal object modified */
  53. #define UOF_DELPEND 0x100 /* delete pending */
  54. NTS_t uo_rname; /* real user name (gecos string) */
  55. USIList_t uo_groups; /* list of group ids containing user */
  56. };
  57. /*
  58. * Description (GroupObj_t)
  59. *
  60. * This type defines the structure of a group object. A group object
  61. * contains information about a group which might be contained in
  62. * an authentication database, including group name, group id, and
  63. * relationships to other groups.
  64. */
  65. typedef struct GroupObj_s GroupObj_t;
  66. struct GroupObj_s
  67. {
  68. NTS_t go_name; /* group name */
  69. USI_t go_gid; /* group id */
  70. USI_t go_flags; /* bit flags */
  71. #define GOF_DBFLAGS 0x3f /* mask for flags stored in DB file */
  72. #define GOF_NEW 0x40 /* new group object */
  73. #define GOF_MODIFIED 0x80 /* internal object modified */
  74. #define GOF_DELPEND 0x100 /* delete pending */
  75. NTS_t go_desc; /* group description */
  76. USIList_t go_users; /* list of user members (uids) */
  77. USIList_t go_groups; /* list of group members (gids) */
  78. USIList_t go_pgroups; /* list of parent groups (gids) */
  79. };
  80. /*
  81. * Description (AuthIF_t)
  82. *
  83. * This type describes a structure containing pointers to functions
  84. * which provide a standard interface to an authentication database.
  85. * The functions are described below.
  86. *
  87. * Description (aif_close)
  88. *
  89. * The referenced function closes an authentication database which
  90. * was previously opened via the aif_open function.
  91. *
  92. * Arguments:
  93. *
  94. * authdb - handle for database returned by aif_open
  95. * flags - close flags (unused - must be zero)
  96. *
  97. *
  98. * Description (aif_findid)
  99. *
  100. * The referenced function looks up a specified user or group id
  101. * in a given authentication database. Flags can be specified to
  102. * search for only matching user ids, only matching group ids,
  103. * or both. The result value for a successful search indicates
  104. * whether a matching user or group id was found, and a pointer to
  105. * a user or group object is returned accordingly.
  106. *
  107. * Arguments:
  108. *
  109. * authdb - handle for database returned by aif_open
  110. * id - user/group id value
  111. * flags - bit flags to control search
  112. * rptr - pointer to returned user or group object
  113. * pointer (may be null)
  114. *
  115. * Returns:
  116. *
  117. * If successful, the result value is greater than zero, and contains
  118. * a subset of the search flags, indicating what was found, and a user
  119. * or group object pointer is returned through 'rptr' if it is non-null.
  120. * An unsuccessful search is indicated by a return value of zero. An
  121. * error is indicated by a negative return value (defined in
  122. * nsautherr.h).
  123. *
  124. *
  125. * Description (aif_findname)
  126. *
  127. * The referenced function looks up a specified user or group name
  128. * in a given authentication database. Flags can be specified to
  129. * search for only matching user names, only matching group names,
  130. * or both. The result value for a successful search indicates
  131. * whether a matching user or group was found, and a pointer to a
  132. * user or group object is returned accordingly.
  133. *
  134. * Arguments:
  135. *
  136. * authdb - handle for database returned by aif_open
  137. * name - user/group name string pointer
  138. * flags - bit flags to control search
  139. * rptr - pointer to returned user or group object
  140. * pointer (may be null)
  141. *
  142. * Returns:
  143. *
  144. * If successful, the result value is greater than zero, and contains
  145. * a subset of the search flags, indicating what was found, and a user
  146. * or group object pointer is returned through 'rptr' if it is non-null.
  147. * An unsuccessful search is indicated by a return value of zero. An
  148. * error is indicated by a negative return value (defined in
  149. * nsautherr.h).
  150. *
  151. *
  152. * Description (aif_idtoname)
  153. *
  154. * The referenced function looks up a specified user or group id
  155. * in a given authentication database, and returns the associated
  156. * user or group name. Flags can be specified to search for only
  157. * matching user ids, only matching group ids, or both. The result
  158. * value for a successful search indicates whether a matching user
  159. * or group id was found, and a pointer to the user or group name
  160. * is returned accordingly.
  161. *
  162. * Arguments:
  163. *
  164. * authdb - handle for database returned by aif_open
  165. * id - user/group id value
  166. * flags - bit flags to control search
  167. * rptr - pointer to returned user or group name
  168. * pointer (may be null)
  169. *
  170. * Returns:
  171. *
  172. * If successful, the result value is greater than zero, and contains
  173. * a subset of the search flags, indicating what was found, and a user
  174. * or group name pointer is returned through 'rptr' if it is non-null.
  175. * An unsuccessful search is indicated by a return value of zero. An
  176. * error is indicated by a negative return value (defined in
  177. * nsautherr.h).
  178. *
  179. *
  180. * Description (aif_open)
  181. *
  182. * The referenced function opens a named authentication database of
  183. * the type supported by this interface. The actual effect of the
  184. * open function depends on the particular type of database, but a
  185. * call to the aif_open function should generally be followed by a
  186. * call to the aif_close function at some point.
  187. *
  188. * Arguments:
  189. *
  190. * adbname - authentication database name string pointer
  191. * flags - open flags (definitions below)
  192. * rptr - pointer to returned handle for the database
  193. *
  194. * Returns:
  195. *
  196. * The return value is zero if the operation is successful, and a
  197. * handle for the authentication database is returned through 'rptr'.
  198. * An error is indicated by a negative return value (defined in
  199. * nsautherr.h).
  200. */
  201. typedef struct AuthIF_s AuthIF_t;
  202. struct AuthIF_s
  203. {
  204. int (*aif_findid)(NSErr_t *errp,
  205. void *authdb,
  206. USI_t id,
  207. int flags,
  208. void **rptr);
  209. int (*aif_findname)(NSErr_t *errp,
  210. void *authdb,
  211. char *name,
  212. int flags,
  213. void **rptr);
  214. int (*aif_idtoname)(NSErr_t *errp,
  215. void *authdb,
  216. USI_t id,
  217. int flags,
  218. char **rptr);
  219. int (*aif_open)(NSErr_t *errp, char *adbname, int flags, void **rptr);
  220. void (*aif_close)(void *authdb, int flags);
  221. int (*aif_addmember)(void **pmlist, char *name, int flags);
  222. int (*aif_ismember)(void *mlist, char *name, int flags);
  223. };
  224. /* Define flags for the aif_open function */
  225. #define AIF_CREATE 0x1 /* new database (create it) */
  226. /*
  227. * Define bits for flags and return value of aif_findid, aif_findid,
  228. * and aif_idtoname functions.
  229. */
  230. #define AIF_NONE 0 /* no matching group or user name */
  231. #define AIF_GROUP 0x1 /* matching group name/id found */
  232. #define AIF_USER 0x2 /* matching user name/id found */
  233. /*
  234. * Description (Realm_t)
  235. *
  236. * This type defines a structure which represents an authentication
  237. * realm. Each realm has a unique name, which is accessed through
  238. * a Symbol_t structure, which in turn references a Realm_t as the
  239. * symbol value. This structure specifies an authentication
  240. * method and an authentication database.
  241. */
  242. typedef struct Realm_s Realm_t;
  243. struct Realm_s
  244. {
  245. int rlm_ameth; /* authentication method type */
  246. char *rlm_dbname; /* authentication database name */
  247. AuthIF_t *rlm_aif; /* authentication interface pointer */
  248. void *rlm_authdb; /* authentication database handle */
  249. char *rlm_prompt; /* realm prompt string */
  250. };
  251. /* Define supported authentication method codes for rlm_ameth */
  252. #define AUTH_METHOD_BASIC 1 /* basic authentication */
  253. #define AUTH_METHOD_SSL 2 /* SSL client authentication */
  254. /*
  255. * Description (ClAuth_t)
  256. *
  257. * This type describes a structure containing information about a
  258. * particular client. It is used to pass information into and out
  259. * of authentication support functions, as well as to other functions
  260. * needing access to client authentication information.
  261. * FUTURE:
  262. * - add client certificate pointer
  263. */
  264. typedef struct ClAuth_s ClAuth_t;
  265. struct ClAuth_s
  266. {
  267. Realm_t *cla_realm; /* authentication realm pointer */
  268. IPAddr_t cla_ipaddr; /* IP address */
  269. char *cla_dns; /* DNS name string pointer */
  270. UserObj_t *cla_uoptr; /* authenticated user object pointer */
  271. GroupObj_t *cla_goptr; /* pointer to list of group objects */
  272. CERTCertificate *cla_cert; /* certificate from SSL client auth */
  273. };
  274. #endif /* __nsauth_h */