nsauth.h 9.9 KB

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