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