/daten/src/linux-2.4.27-rsbac-v1.2.3/include/rsbac/lists.h

Go to the documentation of this file.
00001 /*************************************************** */ 00002 /* Rule Set Based Access Control */ 00003 /* Author and (c) 1999-2001: Amon Ott <ao@rsbac.org> */ 00004 /* Generic List Management */ 00005 /* Last modified: 23/Apr/2001 */ 00006 /*************************************************** */ 00007 00008 /* Note: lol = list of lists, a two-level list structure */ 00009 00010 #ifndef __RSBAC_LISTS_H 00011 #define __RSBAC_LISTS_H 00012 00013 #include <linux/init.h> 00014 #include <linux/vmalloc.h> 00015 #include <rsbac/types.h> 00016 #include <rsbac/rkmem.h> 00017 00018 #define RSBAC_LIST_VERSION 3 00019 00020 typedef void * rsbac_list_handle_t; 00021 typedef __u32 rsbac_list_key_t; 00022 00023 /* Maximum length for list (file)names */ 00024 #define RSBAC_LIST_MAX_FILENAME 15 00025 00026 /* Limit for max_age_in_seconds: ca. 10 years */ 00027 #define RSBAC_LIST_MAX_AGE_LIMIT (3600 * 24 * 366 * 10) 00028 00029 /* Maximum desc_size + data_size: Max rkmalloc size - some space for metadata */ 00030 #define RSBAC_LIST_MAX_ITEM_SIZE (RSBAC_MAX_KMALLOC - 64) 00031 00032 /****************************/ 00033 /* List Registration Flags: */ 00034 00035 /* Make persistent, i.e., save to and restore from disk */ 00036 #define RSBAC_LIST_PERSIST 1 00037 00038 /* Ignore old list contents (still checks key, if list exists on disk) */ 00039 #define RSBAC_LIST_IGNORE_OLD 2 00040 00041 /* Ignore old list contents, if version upconversion is not supported 00042 * (no get_conv, or get_conv returned NULL) - without this flag, registration fails, if 00043 * list cannot be converted. 00044 */ 00045 #define RSBAC_LIST_IGNORE_UNSUPP_VERSION 4 00046 00047 /* Temporarily disallow writing list to disk, e.g. for upgrade tests */ 00048 #define RSBAC_LIST_NO_WRITE 8 00049 00050 /* Provide a binary backup file as /proc/rsbac-info/backup/filename */ 00051 #define RSBAC_LIST_BACKUP 16 00052 00053 /* Use provided default data, return it for unexisting items and 00054 automatically create and cleanup items with default data as necessary. 00055 (only items with 0 ttl (unlimited) get removed) 00056 (lol items with default data only get removed, if they have no subitems) */ 00057 #define RSBAC_LIST_DEF_DATA 32 00058 00059 /* Use provided default subitem data, return it for unexisting subitems and 00060 automatically create and cleanup subitems with default data as necessary. 00061 (only subitems with 0 ttl (unlimited) get removed) */ 00062 #define RSBAC_LIST_DEF_SUBDATA 64 00063 00064 /****************************/ 00065 /* Function prototypes */ 00066 00067 /* Function to compare two descriptors, returns 0, if equal, a negative value, 00068 * if desc1 < desc2 and a positive value, if desc1 > desc2 (like memcmp). 00069 * Used for lookup and list optimization. 00070 * Note: Non-0 values are only used for list optimization and do not necessarily 00071 * imply a real order of values. 00072 */ 00073 typedef int rsbac_list_compare_function_t(void * desc1, void * desc2); 00074 00075 /* Compare function for __u32 values */ 00076 int rsbac_list_compare_u32(void * desc1, void * desc2); 00077 00078 /* Function to compare two datas, returns 0, if equal, and another value, 00079 * if not. 00080 * Used for lookup by data. 00081 * Note: list optimization is based on descriptors, so data lookup is always 00082 * linear search from first to last element in list order. 00083 */ 00084 typedef int rsbac_list_data_compare_function_t(void * data1, void * data2); 00085 00086 /* conversion function to upconvert old on-disk descs and datas to actual version */ 00087 /* must return 0 on success or error otherwise */ 00088 /* Attention: if old or new data_size is 0, the respective data pointer is NULL! */ 00089 typedef int rsbac_list_conv_function_t( 00090 void * old_desc, 00091 void * old_data, 00092 void * new_desc, 00093 void * new_data); 00094 00095 /* callback function to return an upconvert function for on-disk-version, if versions differ */ 00096 /* Note: Lists implementation does not assume anything about your version number apart 00097 from being of type rsbac_version_t. Use it as you like. */ 00098 typedef rsbac_list_conv_function_t * rsbac_list_get_conv_t(rsbac_version_t old_version); 00099 00100 /* get generic list registration version */ 00101 rsbac_version_t rsbac_list_version(void); 00102 00103 00104 /* List info: This struct will be written to disk */ 00105 /* 00106 * list_version: a simple __u32 version number for the list. If old on-disk version is 00107 different, conversion is tried (depending on flags and get_conv function) 00108 * key: secret __u32 key, which must be the same as in on-disk version, if persistent 00109 * desc_size: size of the descriptor (error is returned, if list exists and value differs) 00110 internally reset to sizeof(__u32) for u32 call variants 00111 * data_size: size of data (error is returned, if list exists and value differs) 00112 set to 0 for sets without data 00113 * subdesc_size: size of the descriptor of the sublist (error is returned, if list exists 00114 and value differs), internally reset to sizeof(__u32) for u32 call variants 00115 * subdata_size: size of sublist data (error is returned, if list exists and value differs) 00116 set to 0 for sets without data 00117 * max_age: seconds until unchanged list file (no add or remove) will be purged. 00118 Maximum value is RSBAC_LIST_MAX_AGE_LIMIT (s.a.), use 0 for unlimited lifetime. 00119 (purging not yet implemented - only reused without key, please cleanup by hand) 00120 */ 00121 struct rsbac_list_info_t 00122 { 00123 rsbac_version_t version; 00124 rsbac_list_key_t key; 00125 __u32 desc_size; 00126 __u32 data_size; 00127 rsbac_time_t max_age; 00128 }; 00129 00130 struct rsbac_list_lol_info_t 00131 { 00132 rsbac_version_t version; 00133 rsbac_list_key_t key; 00134 __u32 desc_size; 00135 __u32 data_size; 00136 __u32 subdesc_size; 00137 __u32 subdata_size; 00138 rsbac_time_t max_age; 00139 }; 00140 00141 00142 /* register a new list */ 00143 /* 00144 * If list with same name exists in memory, error -RSBAC_EEXISTS is returned. 00145 * If list with same name and key exists on device, it is restored depending on 00146 the flags. 00147 * If list with same name, but different key exists on disk, access is denied 00148 (error -EPERM). 00149 * 00150 * ds_version: for binary modules, must be RSBAC_LIST_VERSION. If version 00151 differs, return error. 00152 * handle_p: for all list accesses, an opaque handle is put into *handle_p. 00153 * flags: see flag values 00154 * compare: for lookup and list optimization, can be NULL, then 00155 memcmp(desc1, desc2, desc_size) is used 00156 * subcompare: for item lookup and optimization of sublist, can be NULL, then 00157 memcmp(desc1, desc2, desc_size) is used 00158 * get_conv: function to deliver conversion function for given version 00159 * get_subconv: function to deliver sublist item conversion function for given 00160 version 00161 * def_data: default data value for flag RSBAC_LIST_DEF_DATA 00162 (if NULL, flag is cleared) 00163 * def_subdata: default subdata value for flag RSBAC_LIST_DEF_SUBDATA 00164 (if NULL, flag is cleared) 00165 * name: the on-disk name, should be distinct and max. 7 or 8.2 chars 00166 (maxlen of RSBAC_LIST_MAX_FILENAME supported) (only used for statistics, if 00167 non-persistent) 00168 * device: the device to read list from or to save list to - use 0 for root dev 00169 (ignored, if non-persistent) 00170 */ 00171 00172 int rsbac_list_register( 00173 rsbac_version_t ds_version, 00174 rsbac_list_handle_t *handle_p, 00175 struct rsbac_list_info_t * info_p, 00176 u_int flags, 00177 rsbac_list_compare_function_t * compare, 00178 rsbac_list_get_conv_t * get_conv, 00179 void * def_data, 00180 char * name, 00181 kdev_t device); 00182 00183 int rsbac_list_lol_register( 00184 rsbac_version_t ds_version, 00185 rsbac_list_handle_t *handle_p, 00186 struct rsbac_list_lol_info_t * info_p, 00187 u_int flags, 00188 rsbac_list_compare_function_t * compare, 00189 rsbac_list_compare_function_t * subcompare, 00190 rsbac_list_get_conv_t * get_conv, 00191 rsbac_list_get_conv_t * get_subconv, 00192 void * def_data, 00193 void * def_subdata, 00194 char * name, 00195 kdev_t device); 00196 00197 /* destroy list */ 00198 /* list is destroyed, disk file is deleted */ 00199 /* list must have been opened with register */ 00200 int rsbac_list_destroy(rsbac_list_handle_t * handle_p, rsbac_list_key_t key); 00201 00202 int rsbac_list_lol_destroy(rsbac_list_handle_t * handle_p, rsbac_list_key_t key); 00203 00204 /* detach from list */ 00205 /* list is saved (if persistent) and removed from memory. Call register for new access. */ 00206 int rsbac_list_detach(rsbac_list_handle_t * handle_p, rsbac_list_key_t key); 00207 00208 int rsbac_list_lol_detach(rsbac_list_handle_t * handle_p, rsbac_list_key_t key); 00209 00210 /* set list's no_write flag */ 00211 /* TRUE: do not write to disk, FALSE: writing allowed */ 00212 int rsbac_list_no_write 00213 (rsbac_list_handle_t handle, rsbac_list_key_t key, boolean no_write); 00214 00215 int rsbac_list_lol_no_write 00216 (rsbac_list_handle_t handle, rsbac_list_key_t key, boolean no_write); 00217 00218 /* Single list checking, good for cleanup of items with ttl in the past. */ 00219 /* This functionality is also included in the big rsbac_check(). */ 00220 00221 int rsbac_list_check( 00222 rsbac_list_handle_t handle, 00223 int correct); 00224 00225 int rsbac_list_lol_check( 00226 rsbac_list_handle_t handle, 00227 int correct); 00228 00229 /* add item */ 00230 /* if item for desc exists, the data is updated */ 00231 /* data can be NULL, if list is registered with data_size 0 (used as set) */ 00232 int rsbac_list_add(rsbac_list_handle_t handle, void * desc, void * data); 00233 00234 /* simple wrapper for 32Bit desc to allow using const values */ 00235 int rsbac_list_add_u32(rsbac_list_handle_t handle, __u32 desc, void * data); 00236 00237 /* add with time-to-live - after this time in seconds the item gets automatically removed */ 00238 /* set to 0 for unlimited (default), RSBAC_LIST_TTL_KEEP to keep previous setting */ 00239 int rsbac_list_add_ttl( 00240 rsbac_list_handle_t handle, 00241 rsbac_time_t ttl, 00242 void * desc, 00243 void * data); 00244 00245 int rsbac_list_add_ttl_u32(rsbac_list_handle_t handle, 00246 rsbac_time_t ttl, 00247 __u32 desc, 00248 void * data); 00249 00250 /* Add list of lists sublist item, item for desc must exist */ 00251 int rsbac_list_lol_subadd( 00252 rsbac_list_handle_t handle, 00253 void * desc, 00254 void * subdesc, 00255 void * subdata); 00256 00257 int rsbac_list_lol_subadd_u32(rsbac_list_handle_t handle, 00258 __u32 desc, 00259 __u32 subdesc, 00260 void * subdata); 00261 00262 /* add with time-to-live - after this time in seconds the item gets automatically removed */ 00263 int rsbac_list_lol_subadd_ttl( 00264 rsbac_list_handle_t handle, 00265 rsbac_time_t ttl, 00266 void * desc, 00267 void * subdesc, 00268 void * subdata); 00269 00270 int rsbac_list_lol_subadd_ttl_u32(rsbac_list_handle_t handle, 00271 rsbac_time_t ttl, 00272 __u32 desc, 00273 __u32 subdesc, 00274 void * subdata); 00275 00276 /* Add list of lists top level item */ 00277 int rsbac_list_lol_add( 00278 rsbac_list_handle_t handle, 00279 void * desc, 00280 void * data); 00281 00282 int rsbac_list_lol_add_u32(rsbac_list_handle_t handle, __u32 desc, void * data); 00283 00284 /* add with time-to-live - after this time in seconds the item gets automatically removed */ 00285 int rsbac_list_lol_add_ttl( 00286 rsbac_list_handle_t handle, 00287 rsbac_time_t ttl, 00288 void * desc, 00289 void * data); 00290 00291 int rsbac_list_lol_add_ttl_u32(rsbac_list_handle_t handle, 00292 rsbac_time_t ttl, 00293 __u32 desc, 00294 void * data); 00295 00296 00297 /* remove item */ 00298 int rsbac_list_remove(rsbac_list_handle_t handle, void * desc); 00299 00300 /* simple wrapper for 32Bit desc to allow using const values */ 00301 int rsbac_list_remove_u32(rsbac_list_handle_t handle, __u32 desc); 00302 00303 00304 /* remove all items */ 00305 int rsbac_list_remove_all(rsbac_list_handle_t handle); 00306 00307 /* remove item from sublist - also succeeds, if item for desc or subdesc does not exist */ 00308 int rsbac_list_lol_subremove( 00309 rsbac_list_handle_t handle, 00310 void * desc, 00311 void * subdesc); 00312 00313 int rsbac_list_lol_subremove_u32(rsbac_list_handle_t handle, __u32 desc, __u32 subdesc); 00314 00315 /* remove same subitem from all sublists */ 00316 int rsbac_list_lol_subremove_from_all( 00317 rsbac_list_handle_t handle, 00318 void * subdesc); 00319 00320 int rsbac_list_lol_subremove_from_all_u32(rsbac_list_handle_t handle, __u32 subdesc); 00321 00322 /* remove all subitems from list */ 00323 int rsbac_list_lol_subremove_all(rsbac_list_handle_t handle, void * desc); 00324 00325 int rsbac_list_lol_subremove_all_u32(rsbac_list_handle_t handle, __u32 desc); 00326 00327 int rsbac_list_lol_remove( 00328 rsbac_list_handle_t handle, 00329 void * desc); 00330 00331 int rsbac_list_lol_remove_u32(rsbac_list_handle_t handle, __u32 desc); 00332 00333 int rsbac_list_lol_remove_all(rsbac_list_handle_t handle); 00334 00335 00336 /* get item data */ 00337 /* Item data is copied - we cannot give a pointer, because item could be 00338 * removed */ 00339 int rsbac_list_get_data(rsbac_list_handle_t handle, void * desc, void * data); 00340 00341 /* simple wrapper for 32Bit desc to allow using const values */ 00342 int rsbac_list_get_data_u32(rsbac_list_handle_t handle, __u32 desc, void * data); 00343 00344 /* also get time-to-live - after this time in seconds the item gets automatically removed */ 00345 /* both ttl_p and data can be NULL, they are then simply not returned */ 00346 int rsbac_list_get_data_ttl(rsbac_list_handle_t handle, 00347 rsbac_time_t * ttl_p, 00348 void * desc, 00349 void * data); 00350 00351 int rsbac_list_get_data_ttl_u32(rsbac_list_handle_t handle, 00352 rsbac_time_t * ttl_p, 00353 __u32 desc, 00354 void * data); 00355 00356 /* get data from a subitem */ 00357 int rsbac_list_lol_get_subdata( 00358 rsbac_list_handle_t handle, 00359 void * desc, 00360 void * subdesc, 00361 void * subdata); 00362 00363 int rsbac_list_lol_get_subdata_u32( 00364 rsbac_list_handle_t handle, 00365 __u32 desc, 00366 __u32 subdesc, 00367 void * data); 00368 00369 /* also get time-to-live - after this time in seconds the item gets automatically removed */ 00370 /* both ttl_p and data can be NULL, they are then simply not returned */ 00371 int rsbac_list_lol_get_subdata_ttl( 00372 rsbac_list_handle_t handle, 00373 rsbac_time_t * ttl_p, 00374 void * desc, 00375 void * subdesc, 00376 void * subdata); 00377 00378 int rsbac_list_lol_get_subdata_ttl_u32(rsbac_list_handle_t handle, 00379 rsbac_time_t * ttl_p, 00380 __u32 desc, 00381 __u32 subdesc, 00382 void * data); 00383 00384 00385 int rsbac_list_lol_get_data(rsbac_list_handle_t handle, void * desc, void * data); 00386 00387 int rsbac_list_lol_get_data_u32(rsbac_list_handle_t handle, __u32 desc, void * data); 00388 00389 /* also get time-to-live - after this time in seconds the item gets automatically removed */ 00390 /* both ttl_p and data can be NULL, they are then simply not returned */ 00391 int rsbac_list_lol_get_data_ttl(rsbac_list_handle_t handle, 00392 rsbac_time_t * ttl_p, 00393 void * desc, 00394 void * data); 00395 00396 int rsbac_list_lol_get_data_ttl_u32(rsbac_list_handle_t handle, 00397 rsbac_time_t * ttl_p, 00398 __u32 desc, 00399 void * data); 00400 00401 00402 /* get item desc by data */ 00403 /* Item desc is copied - we cannot give a pointer, because item could be 00404 * removed. 00405 * If no compare function is provided (NULL value), memcmp is used. 00406 * Note: The data value given here is always used as second parameter to the 00407 * compare function, so you can use different types for storage and 00408 * lookup. 00409 */ 00410 int rsbac_list_get_desc(rsbac_list_handle_t handle, 00411 void * desc, 00412 void * data, 00413 rsbac_list_data_compare_function_t compare); 00414 00415 /* simple wrapper for 32Bit data to allow using const values */ 00416 int rsbac_list_get_desc_u32(rsbac_list_handle_t handle, void * desc, __u32 data); 00417 00418 /* get maximum desc (uses compare function) */ 00419 int rsbac_list_get_max_desc(rsbac_list_handle_t handle, void * desc); 00420 00421 /* does item exist? */ 00422 /* returns TRUE, if item exists, FALSE, if not or error */ 00423 int rsbac_list_exist(rsbac_list_handle_t handle, void * desc); 00424 00425 /* simple wrapper for 32Bit desc to allow using const values */ 00426 int rsbac_list_exist_u32(rsbac_list_handle_t handle, __u32 desc); 00427 00428 int rsbac_list_lol_subexist( 00429 rsbac_list_handle_t handle, 00430 void * desc, 00431 void * subdesc); 00432 00433 int rsbac_list_lol_subexist_u32(rsbac_list_handle_t handle, __u32 desc, __u32 subdesc); 00434 00435 int rsbac_list_lol_exist( 00436 rsbac_list_handle_t handle, 00437 void * desc); 00438 00439 int rsbac_list_lol_exist_u32(rsbac_list_handle_t handle, __u32 desc); 00440 00441 /* 00442 * Note: The subdesc/data value given here is always used as second parameter to the 00443 * given subdesc compare function, so you can use different types for storage and 00444 * lookup. If compare is NULL, call is forwarded to rsbac_list_lol_subexist. 00445 * Warning: This function does not use the list optimization when searching the sublist! 00446 */ 00447 int rsbac_list_lol_subexist_compare( 00448 rsbac_list_handle_t handle, 00449 void * desc, 00450 void * subdesc, 00451 rsbac_list_compare_function_t compare); 00452 00453 int rsbac_list_lol_subexist_compare_u32(rsbac_list_handle_t handle, 00454 __u32 desc, 00455 __u32 subdesc, 00456 rsbac_list_compare_function_t compare); 00457 00458 00459 /* count number of elements */ 00460 /* returns number of elements or negative error code */ 00461 long rsbac_list_count(rsbac_list_handle_t handle); 00462 00463 long rsbac_list_lol_subcount(rsbac_list_handle_t handle, void * desc); 00464 00465 long rsbac_list_lol_all_subcount(rsbac_list_handle_t handle); 00466 00467 long rsbac_list_lol_count(rsbac_list_handle_t handle); 00468 00469 00470 /* Get array of all descriptors */ 00471 /* Returns number of elements or negative error code */ 00472 /* If return value > 0, *array_p contains a pointer to a vmalloc'd array of descs, 00473 otherwise *array_p is set to NULL. If *array_p has been set, caller must call 00474 vfree(*array_p) after use! */ 00475 00476 long rsbac_list_get_all_desc(rsbac_list_handle_t handle, void ** array_p); 00477 00478 long rsbac_list_lol_get_all_subdesc(rsbac_list_handle_t handle, void * desc, void ** array_p); 00479 00480 long rsbac_list_lol_get_all_subdesc_ttl(rsbac_list_handle_t handle, 00481 void * desc, 00482 void ** array_p, 00483 rsbac_time_t ** ttl_array_p); 00484 00485 long rsbac_list_lol_get_all_desc(rsbac_list_handle_t handle, void ** array_p); 00486 00487 00488 /* Get array of all datas */ 00489 /* Returns number of elements or negative error code */ 00490 /* If return value > 0, *array_p contains a pointer to a vmalloc'd array of datas, 00491 otherwise *array_p is set to NULL. If *array_p has been set, caller must call 00492 vfree(*array_p) after use! */ 00493 00494 long rsbac_list_get_all_data(rsbac_list_handle_t handle, void ** array_p); 00495 00496 long rsbac_list_lol_get_all_subdata(rsbac_list_handle_t handle, void * desc, void ** array_p); 00497 00498 long rsbac_list_lol_get_all_data(rsbac_list_handle_t handle, void ** array_p); 00499 00500 00501 /* Get item size */ 00502 00503 int rsbac_list_get_item_size(rsbac_list_handle_t handle); 00504 00505 int rsbac_list_lol_get_subitem_size(rsbac_list_handle_t handle); 00506 00507 int rsbac_list_lol_get_item_size(rsbac_list_handle_t handle); 00508 00509 /* Get array of all items */ 00510 /* Returns number of items or negative error code */ 00511 /* If return value > 0, *array_p contains a pointer to a vmalloc'd array of items, 00512 where desc and data are placed directly behind each other. 00513 If *array_p has been set, caller must call vfree(*array_p) after use! */ 00514 00515 long rsbac_list_get_all_items(rsbac_list_handle_t handle, void ** array_p); 00516 00517 long rsbac_list_get_all_items_ttl(rsbac_list_handle_t handle, 00518 void ** array_p, 00519 rsbac_time_t ** ttl_array_p); 00520 00521 long rsbac_list_lol_get_all_subitems(rsbac_list_handle_t handle, void * desc, void ** array_p); 00522 00523 long rsbac_list_lol_get_all_subitems_ttl(rsbac_list_handle_t handle, 00524 void * desc, 00525 void ** array_p, 00526 rsbac_time_t ** ttl_array_p); 00527 00528 long rsbac_list_lol_get_all_items(rsbac_list_handle_t handle, void ** array_p); 00529 00530 00531 #endif 00532 /* end of lists.h */

Generated on Tue Aug 31 10:05:22 2004 for RSBAC by doxygen 1.3.8