abac0-leakabac0-meimei-idmei-rt0-ntvf-new-xml
Last change
on this file since 8f53997 was
461541a,
checked in by Mei <mei@…>, 11 years ago
|
1) updated original rt0 to remove libstrongswan dependency
a) identity credential being made/accessed with openssl api calls
(X509/EVP_PKEY pem)
b) attribute credential being made/access via xmlsec1 (custom XML
structure)
2) refactored libcreddy into libabac and now one ABAC namespace for
libabac
3) added attribute_rule suboption to creddy's attribute as another way
to insert access rule
4) added some regression tests into example directory
5) updated some docs.
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Rev | Line | |
---|
[461541a] | 1 | |
---|
| 2 | /* abac_util.c */ |
---|
| 3 | |
---|
[7f25a67f] | 4 | #include <err.h> |
---|
| 5 | #include <stdlib.h> |
---|
| 6 | #include <string.h> |
---|
[461541a] | 7 | #include <assert.h> |
---|
| 8 | #include <ctype.h> |
---|
[7f25a67f] | 9 | |
---|
| 10 | /** |
---|
| 11 | * Malloc, fatal on error. |
---|
| 12 | */ |
---|
[3c251d0] | 13 | void *abac_xmalloc(size_t size) { |
---|
[7f25a67f] | 14 | void *ret; |
---|
| 15 | |
---|
| 16 | ret = malloc(size); |
---|
| 17 | if (ret == NULL) |
---|
| 18 | err(1, "malloc"); |
---|
| 19 | |
---|
| 20 | return ret; |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | /** |
---|
| 24 | * strdup fatal on error |
---|
| 25 | */ |
---|
[3c251d0] | 26 | char *abac_xstrdup(char *source) { |
---|
[7f25a67f] | 27 | char *ret; |
---|
| 28 | |
---|
[ff3d104] | 29 | if (source == NULL) |
---|
| 30 | return NULL; |
---|
| 31 | |
---|
[7f25a67f] | 32 | ret = strdup(source); |
---|
| 33 | if (ret == NULL) |
---|
| 34 | err(1, "strdup"); |
---|
| 35 | |
---|
| 36 | return ret; |
---|
| 37 | } |
---|
[9a411d7] | 38 | |
---|
[461541a] | 39 | void *abac_xrealloc(void *ptr, size_t size) { |
---|
| 40 | void *ret = realloc(ptr, size); |
---|
| 41 | if (ret == NULL) |
---|
| 42 | err(1, "couldn't realloc %d bytes\n", size); |
---|
| 43 | return ret; |
---|
| 44 | } |
---|
| 45 | |
---|
[9a411d7] | 46 | /** |
---|
| 47 | * Split a string based on the given delimiter. |
---|
| 48 | */ |
---|
| 49 | void abac_split(char *string, char *delim, char **ret, int *num) { |
---|
| 50 | int len = strlen(delim); |
---|
| 51 | char *start = string; |
---|
| 52 | int count = 0; |
---|
| 53 | |
---|
| 54 | // split the string by the delim |
---|
| 55 | while ((start = strstr(string, delim)) != NULL) { |
---|
| 56 | *start = 0; |
---|
| 57 | ret[count++] = string; |
---|
| 58 | string = start + len; |
---|
| 59 | } |
---|
| 60 | ret[count++] = string; |
---|
| 61 | |
---|
| 62 | *num = count; |
---|
| 63 | } |
---|
[461541a] | 64 | |
---|
| 65 | int abac_clean_name(char *string) { |
---|
| 66 | int i; |
---|
| 67 | |
---|
| 68 | assert(string != NULL); |
---|
| 69 | |
---|
| 70 | // must start with a letter/number |
---|
| 71 | if (!isalnum(string[0])) return 0; |
---|
| 72 | |
---|
| 73 | // Name must be alphanumeric or - or _ or : |
---|
| 74 | for (i = 1; string[i] != '\0'; ++i) |
---|
| 75 | if (!isalnum(string[i]) && string[i] != '-' && string[i] != '_' && |
---|
| 76 | string[i] != ':') |
---|
| 77 | return 0; |
---|
| 78 | |
---|
| 79 | return 1; |
---|
| 80 | } |
---|
| 81 | |
---|
Note: See
TracBrowser
for help on using the repository browser.