nsauth.h 12 KB

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