nsauth.h 12 KB

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