Annotation of libaitcfg/inc/aitpwd.h, revision 1.1.2.5
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.5 ! misho 6: * $Id: aitpwd.h,v 1.1.2.4 2012/09/18 13:32:48 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>
51:
52:
1.1.2.5 ! misho 53: #define PWD_CRIT_NAME 0
! 54: #define PWD_CRIT_UID 1
! 55: #define PWD_CRIT_GID 2
! 56:
! 57:
1.1.2.1 misho 58: struct tagAcctDB {
59: unsigned short db_ver;
60: unsigned char db_lock;
61: unsigned char db_wrap;
62:
63: unsigned int db_rmin;
64: unsigned int db_rmax;
65: uint64_t db_rsize;
66:
67: uint64_t db_since;
68:
69: int db_h; /* optional */
70: } __packed;
71:
72: /* Search callback function, compare to match argument to record match ...
73: * (return: -1 error, 0 not match or 1 match)
74: */
75: typedef int (*cb_acct_f)(void * /*current db_record*/, void * /*argument*/);
76:
77:
78: struct tagUser {
1.1.2.3 misho 79: int usr_fields;
80:
1.1.2.1 misho 81: ait_val_t usr_name;
82: ait_val_t usr_pass;
83: ait_val_t usr_uid;
84: ait_val_t usr_gid;
85: ait_val_t usr_class;
86: ait_val_t usr_change;
87: ait_val_t usr_expire;
88: ait_val_t usr_realm;
89: ait_val_t usr_home;
90: ait_val_t usr_shell;
91:
1.1.2.3 misho 92: SLIST_ENTRY(tagUser) usr_next;
93: RB_ENTRY(tagUser) usr_node;
1.1.2.1 misho 94: };
1.1.2.2 misho 95: typedef struct tagPWD {
96: pthread_mutex_t pwd_mtx;
1.1.2.1 misho 97:
1.1.2.2 misho 98: struct tagUser *slh_first;
99: struct tagUser *rbh_root;
100: } pwd_root_t;
101: #define PWD_LOCK(x) pthread_mutex_lock(&(x)->pwd_mtx)
102: #define PWD_UNLOCK(x) pthread_mutex_unlock(&(x)->pwd_mtx)
103:
104: #define PWD_ISEMPTY(x) RB_EMPTY((x))
1.1.2.1 misho 105:
106: typedef enum { ALL = -1,
107: Username,
108: Password,
109: UID,
110: GID,
111: Class,
112: Change,
113: Expire,
114: Realm,
115: Home,
116: Shell
117: } passwd_attr_t;
118:
119:
120: /*
1.1.2.2 misho 121: * cfgInitPasswd() - Init password root
122: *
123: * @pwd = Password root
124: * return: -1 error or 0 ok
125: */
126: int cfgInitPasswd(pwd_root_t * __restrict pwd);
1.1.2.1 misho 127: /*
1.1.2.2 misho 128: * cfgLoadPasswd() - Load passwords from file
129: *
130: * @pwdName = Passwords filename
131: * @pwd = Password root
132: * return: -1 error or 0 ok
133: */
134: int cfgLoadPasswd(const char *pwdName, pwd_root_t * __restrict pwd);
1.1.2.1 misho 135: /*
1.1.2.2 misho 136: * cfgClearPasswd() - Clear passwords and free resources
137: *
138: * @cfg = Password root
139: * return: none
140: */
141: void cfgClearPasswd(pwd_root_t * __restrict pwd);
142: /*
143: * cfgUnloadPasswd() - Unload passwords from memory and destroy resources
144: *
145: * @pwd = Password root
146: * return: none
147: */
148: void cfgUnloadPasswd(pwd_root_t * __restrict pwd);
149: /*
150: * cfgCreatePasswd() - Create password file from memory
151: *
152: * @pwdName = New password filename
153: * @pwd = Password root
154: * return: -1 error or 0 ok
155: */
156: int cfgCreatePasswd(const char *pwdName, pwd_root_t * __restrict pwd);
1.1.2.1 misho 157:
1.1.2.3 misho 158: /*
159: * cfgReadPasswd() - Read file and add new item at password root
160: *
161: * @f = File resource
162: * @pwd = Password root
163: * return: -1 error or 0 ok
164: */
165: int cfgReadPasswd(FILE *f, pwd_root_t * __restrict pwd);
166: /*
167: * cfgWritePasswd() - Write passwords from memory
168: *
169: * @f = File handle
170: * @pwd = Password root
171: * return: -1 error or 0 ok
172: */
173: int cfgWritePasswd(FILE *f, pwd_root_t * __restrict pwd);
1.1.2.1 misho 174: /*
1.1.2.4 misho 175: * cfgConcatPasswd() - Concat two password roots into one
176: *
177: * @pwd = Password root
178: * @add_pwd = Concated password root will be destroy after merge
179: * return: -1 error or 0 ok
180: */
181: int cfgConcatPasswd(pwd_root_t * __restrict pwd, pwd_root_t * __restrict add_pwd);
1.1.2.1 misho 182:
1.1.2.5 ! misho 183: /*
! 184: * cfg_findPasswdBy() - Find user by criteria position in list
! 185: *
! 186: * @pwd = Password root
! 187: * @criteria = Search criteria [PWD_CRIT_NAME|PWD_CRIT_UID|PWD_CRIT_GID]
! 188: * @arg1 = Username | UID | GID
! 189: * return: NULL not found item or error and !=NULL found item
! 190: */
! 191: struct tagUser *cfg_findPasswdBy(pwd_root_t * __restrict pwd, int criteria, ...);
! 192: /*
! 193: * cfg_unsetPasswd() - Unset item from passwords and free resources
! 194: *
! 195: * @pwd = Password root
! 196: * @criteria = Search criteria [PWD_CRIT_NAME|PWD_CRIT_UID]
! 197: * @arg1 = Username | UID
! 198: * return: 0 item not found, -1 error or 1 removed item
! 199: */
! 200: int cfg_unsetPasswd(pwd_root_t * __restrict pwd, int criteria, ...);
! 201:
1.1.2.4 misho 202: #if 0
1.1.2.1 misho 203: /*
204: * pwdFreeValue() Free passwd_t value
205: * @ppwd = User object
206: * @idx = Index of attribute, if ALL == idx is free all structure
207: * return: 0 ok, -1 error
208: */
209: inline int pwdFreeValue(passwd_t * __restrict ppwd, passwd_attr_t idx);
210: /*
211: * pwdSetValue() Set passwd_t value
212: * @ppwd = User object
213: * @idx = Index of attribute, if ALL == idx clean User object and set username!
214: * @Value = Value to set
215: * return: number of fields in passwd_t; -1 error:: can`t set passwd_t
216: */
217: inline int pwdSetValue(passwd_t * __restrict ppwd, passwd_attr_t idx, unsigned char *Value);
218: /*
219: * pwdGetValue() Get passwd_t value
220: * @pwd = User object
221: * @idx = Index of attribute, if ALL == idx is error!
222: * @Value = Value to get
223: * @valLen = Size of Value string
224: * return: number of fields in passwd_t; -1 error:: can`t get passwd_t
225: */
226: inline int pwdGetValue(passwd_t __restrict pwd, passwd_attr_t idx, unsigned char *Value, int valLen);
227:
228:
229: /*
230: * pwd_FindAttribute() Find by attribute position in user array
231: * @pwd = User array
232: * @idx = Index of attribute, if ALL == idx return number of user array elements
233: * @csAttr = User attribute
234: * return: 0 not found item; -1 error: null parameters; >0 position in array + 1
235: */
236: inline int pwd_FindAttribute(passwd_t __restrict pwd, passwd_attr_t idx, const unsigned char *csAttr);
237: /*
238: * pwd_SetAttribute() Set user in array or add new user if not exists
239: * @ppwd = User array
240: * @idx = Index of attribute to set
241: * @val = User structure for setup
242: * return: 0 nothing changed, -1 error: not enough memory; 1 find and update item; 2 added new item
243: */
244: int pwd_SetAttribute(passwd_t * __restrict ppwd, passwd_attr_t idx, passwd_t val);
245: /*
246: * pwd_GetAttribute() Get user from array, set username in val
247: * @pwd = User array
248: * @idx = Index of attribute to get, if idx == ALL return full element items
249: * @val = User structure
250: * return: 0 not found, -1 error; >0 found at position in array + 1
251: */
252: int pwd_GetAttribute(passwd_t __restrict pwd, passwd_attr_t idx, passwd_t val);
253: /*
254: * pwd_UnsetAttribute() Unset user from array and free resources!
255: * @ppwd = User array
256: * @idx = Index of attribute to unset, if idx == ALL unset(delete) all items in element
257: * @val = User structure
258: * return: 0 item not found, -1 error: null parameters; >0 number of elements leave in array
259: */
260: int pwd_UnsetAttribute(passwd_t * __restrict ppwd, passwd_attr_t idx, passwd_t val);
261: /*
262: * pwd_Authenticate() Authenticate user, set username and password in val
263: * @pwd = User array
264: * @val = User structure for authenticate, set username & password
265: after authentication fill other fields if exists
266: * return: 0 not found, -1 error; >0 found at position in array + 1
267: */
268: int pwd_Authenticate(passwd_t __restrict pwd, passwd_t val);
269:
270:
271: /*
272: * pwd_openAcct() Open accounting aDat binary database
273: * @csName - DB name
274: * @minR - Minimum records in database
275: * @maxR - Maximum records in database(round-robin db), if 0 unlimited grow
276: * @recSize - Size of record element
277: * @wrapR - If maxR >0 give ability to wrap round-robin db
278: * return: NULL error or !=NULL opened db handle
279: */
280: struct tagAcctDB *pwd_openAcct(const char *csName, unsigned int minR, unsigned int maxR,
281: size_t recSize, unsigned char wrapR);
282: /*
283: * pwd_closeAcct() Close accounting aDat binary database
284: * @db - DB handle
285: * return: none
286: */
287: void pwd_closeAcct(struct tagAcctDB ** __restrict db);
288: /*
289: * pwd_writeAcct() Write accounting record to aDat binary database
290: * @db - DB handle
291: * @posR - At position number, if db is unlimited grow (-1) write at last free record
292: * @rec - Record data
293: * return: -1 error or 0 ok
294: */
295: int pwd_writeAcct(struct tagAcctDB * __restrict db, unsigned int posR, void *rec);
296: /*
297: * pwd_readAcct() Read accounting record from aDat binary database
298: * @db - DB handle
299: * @posR - From position number
300: * @rec - Record data buffer
301: * @recsize - Record data buffer size
302: * return: -1 error or 0 ok
303: */
304: int pwd_readAcct(struct tagAcctDB * __restrict db, unsigned int posR, void *rec, int recsize);
305:
306: /*
307: * pwd_findAcct() Find accounting record from aDat binary database
308: * @db - DB handle
309: * @from - From position
310: * @to - To position, if 0 search to end-of-file
311: * @func - Check for match callback function
312: * @arg - Argument passthrough to callback as argument for search
313: * return: -1 error, 0 not found or >1 founded at position! (p.s:start from 1)
314: */
315: int64_t pwd_findAcct(struct tagAcctDB * __restrict db, unsigned int from, unsigned int to,
316: cb_acct_f func, void *arg);
317: #endif
318:
319:
320: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>