#include <rsbac/types.h>#include <rsbac/error.h>#include <rsbac/helpers.h>#include <rsbac/rc_types.h>#include <rsbac/getname.h>#include <rsbac/cap_getname.h>#include <stdio.h>#include <string.h>#include <errno.h>#include <pwd.h>#include <grp.h>Go to the source code of this file.
Functions | |
| int | rsbac_u32_compare (__u32 *a, __u32 *b) |
| int | rsbac_user_compare (const void *a, const void *b) |
| int | rsbac_group_compare (const void *a, const void *b) |
| int | rsbac_nettemp_id_compare (const void *a, const void *b) |
| int | rsbac_dev_compare (const void *desc1, const void *desc2) |
| char * | inttostr (char *str, int i) |
| char * | ulongtostr (char *str, u_long i) |
| char * | longtostr (char *str, long i) |
| char * | u64tostrmac (char *str, __u64 i) |
| void | error_exit (int error) |
| void | show_error (int error) |
| int | rsbac_get_uid_name (rsbac_uid_t *uid, char *name, char *sourcename) |
| int | rsbac_get_fullname (char *fullname, rsbac_uid_t uid) |
| char * | get_user_name (rsbac_uid_t user, char *name) |
| char * | get_group_name (rsbac_gid_t group, char *name) |
| int | rsbac_get_gid_name (rsbac_gid_t *gid, char *name, char *sourcename) |
| char * | u64tostrlog (char *str, __u64 i) |
| __u64 | strtou64log (char *str, __u64 *i_p) |
| char * | u64tostrrc (char *str, __u64 i) |
| __u64 | strtou64rc (char *str, __u64 *i_p) |
| char * | u64tostrrcr (char *str, __u64 i) |
| __u64 | strtou64rcr (char *str, __u64 *i_p) |
| __u64 | strtou64mac (char *str, __u64 *i_p) |
| __u64 | strtou64acl (char *str, __u64 *i_p) |
| int | strtodevdesc (char *str, struct rsbac_dev_desc_t *dev_p) |
| char * | devdesctostr (char *str, struct rsbac_dev_desc_t dev) |
| char * | u64tostracl (char *str, __u64 i) |
| char * | u32tostrcap (char *str, __u32 i) |
| __u32 | strtou32cap (char *str, __u32 *i_p) |
|
||||||||||||
|
Definition at line 595 of file helpers.c. References D_block, D_block_major, D_char, D_char_major, rsbac_dev_desc_t::major, rsbac_dev_desc_t::minor, RSBAC_IS_ZERO_DEV_DESC, and rsbac_dev_desc_t::type. 00596 {
00597 if(RSBAC_IS_ZERO_DEV_DESC(dev))
00598 {
00599 sprintf(str, ":DEFAULT:");
00600 return str;
00601 }
00602 switch(dev.type)
00603 {
00604 case D_block:
00605 case D_char:
00606 sprintf(str, "%c%u:%u", 'b' + dev.type, dev.major, dev.minor);
00607 break;
00608 case D_block_major:
00609 case D_char_major:
00610 sprintf(str, "%c%u",
00611 'b' + dev.type - (D_block_major - D_block),
00612 dev.major);
00613 break;
00614 default:
00615 sprintf(str, "invalid!");
00616 }
00617 return str;
00618 }
|
|
|
Definition at line 216 of file helpers.c. References get_error_name(). 00217 {
00218 char tmp1[80];
00219
00220 if(error<0)
00221 {
00222 get_error_name(tmp1,error);
00223 fprintf(stderr, "Error: %s\n", tmp1);
00224 exit(1);
00225 }
00226 }
|
|
||||||||||||
|
Definition at line 305 of file helpers.c. 00306 {
00307 struct group * group_info_p;
00308
00309 if((group_info_p = getgrgid(group)))
00310 {
00311 strcpy(name, group_info_p->gr_name);
00312 }
00313 else
00314 {
00315 sprintf(name, "%u", group);
00316 }
00317 return name;
00318 }
|
|
||||||||||||
|
Definition at line 290 of file helpers.c. 00291 {
00292 struct passwd * user_info_p;
00293
00294 if((user_info_p = getpwuid(user)))
00295 {
00296 strcpy(name, user_info_p->pw_name);
00297 }
00298 else
00299 {
00300 sprintf(name, "%u", user);
00301 }
00302 return name;
00303 }
|
|
||||||||||||
|
Definition at line 85 of file helpers.c. References NULL. Referenced by acl_detach_fd_lists(), acl_register_fd_lists(), auth_detach_fd_lists(), auth_register_fd_lists(), get_error_name(), mac_detach_fd_lists(), and mac_register_fd_lists(). 00086 {
00087 int j = 0;
00088
00089 if(!str)
00090 return(NULL);
00091
00092 if (i<0)
00093 {
00094 str[j] = '-';
00095 j++;
00096 i = -i;
00097 }
00098 if (i>=10000)
00099 {
00100 str[j] = '0' + (i / 10000);
00101 j++;
00102 }
00103 if (i>=1000)
00104 {
00105 str[j] = '0' + ((i % 10000) / 1000);
00106 j++;
00107 }
00108 if (i>=100)
00109 {
00110 str[j] = '0' + ((i % 1000) / 100);
00111 j++;
00112 }
00113 if (i>=10)
00114 {
00115 str[j] = '0' + ((i % 100) / 10);
00116 j++;
00117 }
00118 str[j] = '0' + (i % 10);
00119 j++;
00120 str[j] = 0;
00121 return (str);
00122 };
|
|
||||||||||||
|
Definition at line 155 of file helpers.c. References NULL. 00156 {
00157 int j = 0;
00158 u_long k = 1000000000;
00159
00160 if(!str)
00161 return(NULL);
00162
00163 if (i<0)
00164 {
00165 str[0] = '-';
00166 j = 1;
00167 i = -i;
00168 }
00169 if (i>=k)
00170 {
00171 str[j] = '0' + ((i / k) % 100);
00172 j++;
00173 }
00174 k /= 10;
00175
00176 while (k>1)
00177 {
00178 if (i>=k)
00179 {
00180 str[j] = '0' + ((i % (k*10)) / k);
00181 j++;
00182 }
00183 k /= 10;
00184 };
00185
00186 str[j] = '0' + (i % 10);
00187 j++;
00188 str[j] = 0;
00189 return (str);
00190 };
|
|
||||||||||||
|
Definition at line 62 of file helpers.c. References rsbac_dev_desc_t::major, rsbac_dev_desc_t::minor, and rsbac_dev_desc_t::type. 00064 {
00065 struct rsbac_dev_desc_t * i_desc1 = desc1;
00066 struct rsbac_dev_desc_t * i_desc2 = desc2;
00067 int result;
00068
00069 result = memcmp(&i_desc1->type,
00070 &i_desc2->type,
00071 sizeof(i_desc1->type));
00072 if(result)
00073 return result;
00074 result = memcmp(&i_desc1->major,
00075 &i_desc2->major,
00076 sizeof(i_desc1->major));
00077 if(result)
00078 return result;
00079 return memcmp(&i_desc1->minor,
00080 &i_desc2->minor,
00081 sizeof(i_desc1->minor));
00082 }
|
|
||||||||||||
|
Definition at line 272 of file helpers.c. References RSBAC_EINVALIDPOINTER. 00273 {
00274 struct passwd * user_info_p;
00275 rsbac_uid_t uid_i;
00276
00277 if(!fullname)
00278 return -RSBAC_EINVALIDPOINTER;
00279 if(!(user_info_p = getpwuid(uid)))
00280 {
00281 sprintf(fullname, "%u", uid);
00282 }
00283 else
00284 {
00285 strcpy(fullname, user_info_p->pw_gecos);
00286 }
00287 return 0;
00288 }
|
|
||||||||||||||||
|
Definition at line 320 of file helpers.c. References RSBAC_EINVALIDVALUE. Referenced by rsbac_get_gid(). 00321 {
00322 struct group * group_info_p;
00323 rsbac_gid_t gid_i;
00324
00325 if(!(group_info_p = getgrnam(sourcename)))
00326 {
00327 gid_i = strtoul(sourcename,0,10);
00328 if( !gid_i
00329 && strcmp("0", sourcename)
00330 )
00331 {
00332 return -RSBAC_EINVALIDVALUE;
00333 }
00334 if(name)
00335 {
00336 if((group_info_p = getgrgid(gid_i)))
00337 strcpy(name, group_info_p->gr_name);
00338 else
00339 sprintf(name, "%u", gid_i);
00340 }
00341 }
00342 else
00343 {
00344 gid_i = group_info_p->gr_gid;
00345 if(name)
00346 strcpy(name, group_info_p->gr_name);
00347 }
00348 if(gid)
00349 *gid = gid_i;
00350 return 0;
00351 }
|
|
||||||||||||||||
|
Definition at line 239 of file helpers.c. References RSBAC_EINVALIDVALUE. Referenced by rsbac_get_uid(). 00240 {
00241 struct passwd * user_info_p;
00242 rsbac_uid_t uid_i;
00243
00244 if(!(user_info_p = getpwnam(sourcename)))
00245 {
00246 uid_i = strtoul(sourcename,0,10);
00247 if( !uid_i
00248 && strcmp("0", sourcename)
00249 )
00250 {
00251 return -RSBAC_EINVALIDVALUE;
00252 }
00253 if(name)
00254 {
00255 if((user_info_p = getpwuid(uid_i)))
00256 strcpy(name, user_info_p->pw_name);
00257 else
00258 sprintf(name, "%u", uid_i);
00259 }
00260 }
00261 else
00262 {
00263 uid_i = user_info_p->pw_uid;
00264 if(name)
00265 strcpy(name, user_info_p->pw_name);
00266 }
00267 if(uid)
00268 *uid = uid_i;
00269 return 0;
00270 }
|
|
||||||||||||
|
Definition at line 52 of file helpers.c. References rsbac_u32_compare(). 00053 {
00054 return rsbac_u32_compare((__u32 *) a, (__u32 *) b);
00055 }
|
|
||||||||||||
|
Definition at line 57 of file helpers.c. References rsbac_u32_compare(). 00058 {
00059 return rsbac_u32_compare((__u32 *) a, (__u32 *) b);
00060 }
|
|
||||||||||||
|
Definition at line 38 of file helpers.c. Referenced by rsbac_group_compare(), rsbac_nettemp_id_compare(), and rsbac_user_compare(). 00039 {
00040 if(*a < *b)
00041 return -1;
00042 if(*a > *b)
00043 return 1;
00044 return 0;
00045 }
|
|
||||||||||||
|
Definition at line 47 of file helpers.c. References rsbac_u32_compare(). 00048 {
00049 return rsbac_u32_compare((__u32 *) a, (__u32 *) b);
00050 }
|
|
|
Definition at line 228 of file helpers.c. References get_error_name(). 00229 {
00230 char tmp1[80];
00231
00232 if(error<0)
00233 {
00234 get_error_name(tmp1,error);
00235 fprintf(stderr, "Error: %s\n", tmp1);
00236 }
00237 }
|
|
||||||||||||
|
Definition at line 550 of file helpers.c. References D_block, D_block_major, D_char, D_char_major, rsbac_dev_desc_t::major, rsbac_dev_desc_t::minor, RSBAC_EINVALIDTARGET, RSBAC_EINVALIDVALUE, RSBAC_ZERO_DEV_DESC, and rsbac_dev_desc_t::type. 00551 {
00552 char * p;
00553 char * c;
00554
00555 if(!str)
00556 return -RSBAC_EINVALIDVALUE;
00557 if(!strcmp(str, ":DEFAULT:"))
00558 {
00559 *dev_p = RSBAC_ZERO_DEV_DESC;
00560 return 0;
00561 }
00562 p = str;
00563 c = strchr(p,':');
00564 switch(*p)
00565 {
00566 case 'b':
00567 case 'B':
00568 if(c)
00569 dev_p->type = D_block;
00570 else
00571 dev_p->type = D_block_major;
00572 break;
00573 case 'c':
00574 case 'C':
00575 if(c)
00576 dev_p->type = D_char;
00577 else
00578 dev_p->type = D_char_major;
00579 break;
00580 default:
00581 return -RSBAC_EINVALIDTARGET;
00582 }
00583 p++;
00584 dev_p->major = strtoul(p,0,0);
00585 if(c)
00586 {
00587 c++;
00588 dev_p->minor = strtoul(c,0,0);
00589 }
00590 else
00591 dev_p->minor = 0;
00592 return 0;
00593 }
|
|
||||||||||||
|
Definition at line 665 of file helpers.c. References CAP_NONE. 00666 {
00667 int j;
00668 __u32 k = 1, res=0;
00669
00670 if(!str)
00671 return(0);
00672
00673 if (strlen(str) < CAP_NONE)
00674 return(-1);
00675 for(j=CAP_NONE-1;j>=0;j--)
00676 {
00677 if(str[j] != '0')
00678 {
00679 res |= k;
00680 }
00681 k <<= 1;
00682 }
00683 for(j=CAP_NONE;j<32;j++)
00684 {
00685 res |= k;
00686 k <<= 1;
00687 }
00688 *i_p = res;
00689 return(res);
00690 };
|
|
||||||||||||
|
Definition at line 523 of file helpers.c. References ACLR_NONE. 00524 {
00525 int j;
00526 __u64 k = 1, res=0;
00527
00528 if(!str)
00529 return(0);
00530
00531 if (strlen(str) < (ACLR_NONE - 1))
00532 return(-1);
00533 for(j=ACLR_NONE-1;j>=0;j--)
00534 {
00535 if(str[j] != '0')
00536 {
00537 res |= k;
00538 }
00539 k <<= 1;
00540 }
00541 for(j=ACLR_NONE-1;j<64;j++)
00542 {
00543 res |= k;
00544 k <<= 1;
00545 }
00546 *i_p = res;
00547 return(res);
00548 }
|
|
||||||||||||
|
Definition at line 376 of file helpers.c. References R_NONE. 00377 {
00378 int j;
00379 __u64 k = 1, res=0;
00380
00381 if(!str)
00382 return(0);
00383
00384 if (strlen(str) < R_NONE)
00385 return(-1);
00386 for(j=R_NONE-1;j>=0;j--)
00387 {
00388 if(str[j] != '0')
00389 {
00390 res |= k;
00391 }
00392 k <<= 1;
00393 }
00394 for(j=R_NONE;j<64;j++)
00395 {
00396 res |= k;
00397 k <<= 1;
00398 }
00399 *i_p = res;
00400 return(res);
00401 };
|
|
||||||||||||
|
Definition at line 496 of file helpers.c. References RSBAC_MAC_MAX_CAT, and RSBAC_MAC_NR_CATS. 00497 {
00498 int j;
00499 __u64 k = 1, res=0;
00500
00501 if(!str)
00502 return(0);
00503
00504 if (strlen(str) < RSBAC_MAC_NR_CATS)
00505 return(-1);
00506 for(j=RSBAC_MAC_MAX_CAT;j>=0;j--)
00507 {
00508 if(str[j] != '0')
00509 {
00510 res |= k;
00511 }
00512 k <<= 1;
00513 }
00514 for(j=RSBAC_MAC_NR_CATS;j<64;j++)
00515 {
00516 res |= k;
00517 k <<= 1;
00518 }
00519 *i_p = res;
00520 return(res);
00521 };
|
|
||||||||||||
|
Definition at line 425 of file helpers.c. 00426 {
00427 int j;
00428 __u64 k = 1, res=0;
00429
00430 if(!str)
00431 return(0);
00432
00433 if (strlen(str) < 64)
00434 return(-1);
00435 for(j=63;j>=0;j--)
00436 {
00437 if(str[j] != '0')
00438 {
00439 res |= k;
00440 }
00441 k <<= 1;
00442 }
00443 *i_p = res;
00444 return(res);
00445 };
|
|
||||||||||||
|
Definition at line 469 of file helpers.c. References RCR_NONE. 00470 {
00471 int j;
00472 __u64 k = 1, res=0;
00473
00474 if(!str)
00475 return(0);
00476
00477 if (strlen(str) < RCR_NONE)
00478 return(-1);
00479 for(j=RCR_NONE-1;j>=0;j--)
00480 {
00481 if(str[j] != '0')
00482 {
00483 res |= k;
00484 }
00485 k <<= 1;
00486 }
00487 for(j=RCR_NONE;j<64;j++)
00488 {
00489 res |= k;
00490 k <<= 1;
00491 }
00492 *i_p = res;
00493 return(res);
00494 };
|
|
||||||||||||
|
Definition at line 643 of file helpers.c. References CAP_NONE, and NULL. 00644 {
00645 int j = 0;
00646 __u32 k;
00647
00648 if(!str)
00649 return(NULL);
00650
00651 k = 1;
00652 for(j = CAP_NONE - 1;j >= 0;j--)
00653 {
00654 if (i & k)
00655 str[j] = '1';
00656 else
00657 str[j] = '0';
00658 k<<=1;
00659 };
00660
00661 str[CAP_NONE] = 0;
00662 return (str);
00663 };
|
|
||||||||||||
|
Definition at line 621 of file helpers.c. References ACLR_NONE, and NULL. Referenced by rsbac_acl_sys_add_to_acl_entry(), rsbac_acl_sys_remove_from_acl_entry(), rsbac_acl_sys_set_acl_entry(), and rsbac_acl_sys_set_mask(). 00622 {
00623 int j = 0;
00624 __u64 k;
00625
00626 if(!str)
00627 return(NULL);
00628
00629 k = 1;
00630 for(j = ACLR_NONE - 1;j >= 0;j--)
00631 {
00632 if (i & k)
00633 str[j] = '1';
00634 else
00635 str[j] = '0';
00636 k<<=1;
00637 };
00638
00639 str[ACLR_NONE] = 0;
00640 return (str);
00641 };
|
|
||||||||||||
|
Definition at line 354 of file helpers.c. 00355 {
00356 int j = 0;
00357 __u64 k;
00358
00359 if(!str)
00360 return(NULL);
00361
00362 k = 1;
00363 for(j = R_NONE - 1;j >= 0;j--)
00364 {
00365 if (i & k)
00366 str[j] = '1';
00367 else
00368 str[j] = '0';
00369 k<<=1;
00370 };
00371
00372 str[R_NONE] = 0;
00373 return (str);
00374 };
|
|
||||||||||||
|
Definition at line 192 of file helpers.c. References NULL, RSBAC_MAC_MAX_CAT, and RSBAC_MAC_NR_CATS. Referenced by auto_read_attr(), auto_read_write_attr(), auto_write_attr(), and rsbac_mac_set_curr_level(). 00193 {
00194 int j = 0;
00195 __u64 k;
00196
00197 if(!str)
00198 return(NULL);
00199
00200 k = 1;
00201 for(j = RSBAC_MAC_MAX_CAT;j >= 0;j--)
00202 {
00203 if (i & k)
00204 str[j] = '1';
00205 else
00206 str[j] = '0';
00207 k<<=1;
00208 };
00209
00210 str[RSBAC_MAC_NR_CATS] = 0;
00211 return (str);
00212 };
|
|
||||||||||||
|
Definition at line 403 of file helpers.c. References NULL. 00404 {
00405 int j = 0;
00406 __u64 k;
00407
00408 if(!str)
00409 return(NULL);
00410
00411 k = 1;
00412 for(j = 63;j >= 0;j--)
00413 {
00414 if (i & k)
00415 str[j] = '1';
00416 else
00417 str[j] = '0';
00418 k<<=1;
00419 };
00420
00421 str[64] = 0;
00422 return (str);
00423 };
|
|
||||||||||||
|
Definition at line 447 of file helpers.c. References NULL, and RCR_NONE. 00448 {
00449 int j = 0;
00450 __u64 k;
00451
00452 if(!str)
00453 return(NULL);
00454
00455 k = 1;
00456 for(j = RCR_NONE - 1;j >= 0;j--)
00457 {
00458 if (i & k)
00459 str[j] = '1';
00460 else
00461 str[j] = '0';
00462 k<<=1;
00463 };
00464
00465 str[RCR_NONE] = 0;
00466 return (str);
00467 };
|
|
||||||||||||
|
Definition at line 124 of file helpers.c. References NULL. 00125 {
00126 int j = 0;
00127 u_long k = 1000000000;
00128
00129 if(!str)
00130 return(NULL);
00131
00132 if (i>=k)
00133 {
00134 str[j] = '0' + ((i / k) % 100);
00135 j++;
00136 }
00137 k /= 10;
00138
00139 while (k>1)
00140 {
00141 if (i>=k)
00142 {
00143 str[j] = '0' + ((i % (k*10)) / k);
00144 j++;
00145 }
00146 k /= 10;
00147 };
00148
00149 str[j] = '0' + (i % 10);
00150 j++;
00151 str[j] = 0;
00152 return (str);
00153 };
|
1.4.2