nsauth.h 12 KB

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