Annotation of libaitcfg/inc/aitpwd.h, revision 1.1.2.11
1.1.2.1 misho 1: /*************************************************************************
2: * (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitbg.com>
3: * by Michael Pounov <misho@openbsd-bg.org>
4: *
5: * $Author: misho $
1.1.2.11! misho 6: * $Id: aitpwd.h,v 1.1.2.10 2012/09/19 13:02:58 misho Exp $
1.1.2.1 misho 7: *
8: **************************************************************************
9: The ELWIX and AITNET software is distributed under the following
10: terms:
11:
12: All of the documentation and software included in the ELWIX and AITNET
13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
14:
15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
16: by Michael Pounov <misho@elwix.org>. All rights reserved.
17:
18: Redistribution and use in source and binary forms, with or without
19: modification, are permitted provided that the following conditions
20: are met:
21: 1. Redistributions of source code must retain the above copyright
22: notice, this list of conditions and the following disclaimer.
23: 2. Redistributions in binary form must reproduce the above copyright
24: notice, this list of conditions and the following disclaimer in the
25: documentation and/or other materials provided with the distribution.
26: 3. All advertising materials mentioning features or use of this software
27: must display the following acknowledgement:
28: This product includes software developed by Michael Pounov <misho@elwix.org>
29: ELWIX - Embedded LightWeight unIX and its contributors.
30: 4. Neither the name of AITNET nor the names of its contributors
31: may be used to endorse or promote products derived from this software
32: without specific prior written permission.
33:
34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37: ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44: SUCH DAMAGE.
45: */
46: #ifndef __AITPWD_H
47: #define __AITPWD_H
48:
49:
50: #include <time.h>
1.1.2.7 misho 51: #include <sys/types.h>
52: #include <aitio.h>
1.1.2.1 misho 53:
54:
1.1.2.5 misho 55: #define PWD_CRIT_NAME 0
56: #define PWD_CRIT_UID 1
57: #define PWD_CRIT_GID 2
58:
59:
1.1.2.1 misho 60: struct tagAcctDB {
61: unsigned short db_ver;
62: unsigned char db_lock;
63: unsigned char db_wrap;
64:
65: unsigned int db_rmin;
66: unsigned int db_rmax;
67: uint64_t db_rsize;
68:
69: uint64_t db_since;
70:
71: int db_h; /* optional */
72: } __packed;
73:
74: /* Search callback function, compare to match argument to record match ...
75: * (return: -1 error, 0 not match or 1 match)
76: */
77: typedef int (*cb_acct_f)(void * /*current db_record*/, void * /*argument*/);
78:
79:
80: struct tagUser {
1.1.2.3 misho 81: int usr_fields;
82:
1.1.2.1 misho 83: ait_val_t usr_name;
84: ait_val_t usr_pass;
85: ait_val_t usr_uid;
86: ait_val_t usr_gid;
87: ait_val_t usr_class;
88: ait_val_t usr_change;
89: ait_val_t usr_expire;
90: ait_val_t usr_realm;
91: ait_val_t usr_home;
92: ait_val_t usr_shell;
93:
1.1.2.3 misho 94: SLIST_ENTRY(tagUser) usr_next;
95: RB_ENTRY(tagUser) usr_node;
1.1.2.1 misho 96: };
1.1.2.2 misho 97: typedef struct tagPWD {
98: pthread_mutex_t pwd_mtx;
1.1.2.1 misho 99:
1.1.2.2 misho 100: struct tagUser *slh_first;
101: struct tagUser *rbh_root;
102: } pwd_root_t;
103: #define PWD_LOCK(x) pthread_mutex_lock(&(x)->pwd_mtx)
104: #define PWD_UNLOCK(x) pthread_mutex_unlock(&(x)->pwd_mtx)
105:
106: #define PWD_ISEMPTY(x) RB_EMPTY((x))
1.1.2.1 misho 107:
108: typedef enum { ALL = -1,
109: Username,
110: Password,
111: UID,
112: GID,
113: Class,
114: Change,
115: Expire,
116: Realm,
117: Home,
118: Shell
119: } passwd_attr_t;
120:
121:
122: /*
1.1.2.2 misho 123: * cfgInitPasswd() - Init password root
124: *
125: * @pwd = Password root
126: * return: -1 error or 0 ok
127: */
128: int cfgInitPasswd(pwd_root_t * __restrict pwd);
1.1.2.1 misho 129: /*
1.1.2.2 misho 130: * cfgLoadPasswd() - Load passwords from file
131: *
132: * @pwdName = Passwords filename
133: * @pwd = Password root
134: * return: -1 error or 0 ok
135: */
136: int cfgLoadPasswd(const char *pwdName, pwd_root_t * __restrict pwd);
1.1.2.1 misho 137: /*
1.1.2.2 misho 138: * cfgClearPasswd() - Clear passwords and free resources
139: *
140: * @cfg = Password root
141: * return: none
142: */
143: void cfgClearPasswd(pwd_root_t * __restrict pwd);
144: /*
145: * cfgUnloadPasswd() - Unload passwords from memory and destroy resources
146: *
147: * @pwd = Password root
148: * return: none
149: */
150: void cfgUnloadPasswd(pwd_root_t * __restrict pwd);
151: /*
152: * cfgCreatePasswd() - Create password file from memory
153: *
154: * @pwdName = New password filename
155: * @pwd = Password root
156: * return: -1 error or 0 ok
157: */
158: int cfgCreatePasswd(const char *pwdName, pwd_root_t * __restrict pwd);
1.1.2.1 misho 159:
1.1.2.3 misho 160: /*
161: * cfgReadPasswd() - Read file and add new item at password root
162: *
163: * @f = File resource
164: * @pwd = Password root
165: * return: -1 error or 0 ok
166: */
167: int cfgReadPasswd(FILE *f, pwd_root_t * __restrict pwd);
168: /*
169: * cfgWritePasswd() - Write passwords from memory
170: *
171: * @f = File handle
172: * @pwd = Password root
173: * return: -1 error or 0 ok
174: */
175: int cfgWritePasswd(FILE *f, pwd_root_t * __restrict pwd);
1.1.2.1 misho 176: /*
1.1.2.4 misho 177: * cfgConcatPasswd() - Concat two password roots into one
178: *
179: * @pwd = Password root
180: * @add_pwd = Concated password root will be destroy after merge
181: * return: -1 error or 0 ok
182: */
183: int cfgConcatPasswd(pwd_root_t * __restrict pwd, pwd_root_t * __restrict add_pwd);
1.1.2.1 misho 184:
1.1.2.5 misho 185: /*
1.1.2.6 misho 186: * cfgAuthPasswd() - Authenticate user against passwords db
187: *
188: * @pwd = Password root
189: * @csName = Username
190: * @csPass = Password
1.1.2.11! misho 191: * return: =NULL deny or !=NULL allow
1.1.2.6 misho 192: */
1.1.2.11! misho 193: const struct tagUser *cfgAuthPasswd(pwd_root_t * __restrict pwd,
! 194: const char *csName, const char *csPass);
1.1.2.6 misho 195:
196: /*
1.1.2.5 misho 197: * cfg_findPasswdBy() - Find user by criteria position in list
198: *
199: * @pwd = Password root
200: * @criteria = Search criteria [PWD_CRIT_NAME|PWD_CRIT_UID|PWD_CRIT_GID]
201: * @arg1 = Username | UID | GID
202: * return: NULL not found item or error and !=NULL found item
203: */
1.1.2.8 misho 204: const struct tagUser *cfg_findPasswdBy(pwd_root_t * __restrict pwd, int criteria, ...);
1.1.2.5 misho 205: /*
206: * cfg_unsetPasswd() - Unset item from passwords and free resources
207: *
208: * @pwd = Password root
209: * @criteria = Search criteria [PWD_CRIT_NAME|PWD_CRIT_UID]
210: * @arg1 = Username | UID
211: * return: 0 item not found, -1 error or 1 removed item
212: */
213: int cfg_unsetPasswd(pwd_root_t * __restrict pwd, int criteria, ...);
1.1.2.1 misho 214: /*
1.1.2.6 misho 215: * cfg_setPasswd() - Set item in password or adding new item if not exists
216: *
217: * @cfg = Password root
1.1.2.9 misho 218: * @fields = Meaning continuous field
1.1.2.6 misho 219: * @csName = Username
1.1.2.10 misho 220: * @arg1 = Password
221: * @arg2 = UID
222: * @arg3 = GID
223: * @arg4 = Login class
224: * @arg5 = Chage date
225: * @arg6 = Expire date
226: * @arg7 = Realm
227: * @arg8 = Home dir
228: * @arg9 = Shell
1.1.2.6 misho 229: * return: 0 nothing changed, -1 error, 1 found and updated item or 2 added new item
230: */
1.1.2.10 misho 231: int cfg_setPasswd(pwd_root_t * __restrict pwd, u_char fields, const char *csName, ...);
1.1.2.1 misho 232: /*
1.1.2.6 misho 233: * cfg_getPasswd() - Get item from passwords and return structure from it
234: *
235: * @pwd = Password root
236: * @criteria = Search criteria [PWD_CRIT_NAME|PWD_CRIT_UID]
237: * @arg1 = Username | UID
238: * return: NULL item not found, !=NULL structure found
1.1.2.1 misho 239: */
1.1.2.6 misho 240: inline const struct tagUser *cfg_getPasswd(pwd_root_t * __restrict pwd, int criteria, ...);
1.1.2.1 misho 241:
242:
243: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>