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