[e95d652] | 1 | #ifndef __ABAC_H__ |
---|
| 2 | #define __ABAC_H__ |
---|
| 3 | |
---|
| 4 | #include <abac_common.h> |
---|
| 5 | |
---|
| 6 | typedef struct _abac_context_t abac_context_t; |
---|
| 7 | typedef struct _abac_credential_t abac_credential_t; |
---|
| 8 | typedef struct _abac_role_t abac_role_t; |
---|
| 9 | |
---|
| 10 | /* |
---|
| 11 | * ABAC functions, operating on an ABAC context. |
---|
| 12 | */ |
---|
| 13 | abac_context_t *abac_context_new(void); |
---|
| 14 | void abac_context_free(abac_context_t *ctx); |
---|
| 15 | |
---|
| 16 | /* see the bottom of the file for possible return codes */ |
---|
| 17 | int abac_context_load_id_file(abac_context_t *ctx, char *filename); |
---|
| 18 | int abac_context_load_id_chunk(abac_context_t *ctx, abac_chunk_t cert); |
---|
| 19 | int abac_context_load_attribute_file(abac_context_t *ctx, char *filename); |
---|
| 20 | int abac_context_load_attribute_chunk(abac_context_t *ctx, abac_chunk_t cert); |
---|
| 21 | |
---|
| 22 | /* load an entire directory full of certs */ |
---|
| 23 | void abac_context_load_directory(abac_context_t *ctx, char *path); |
---|
| 24 | |
---|
| 25 | /* abac query, returns a NULL-terminated array of credentials on success, NULL on fail */ |
---|
| 26 | abac_credential_t **abac_context_query(abac_context_t *ctx, char *role, char *principal, int *success); |
---|
| 27 | |
---|
| 28 | /* get all the credentials from the context, returns a NULL-terminated array of credentials */ |
---|
| 29 | abac_credential_t **abac_context_credentials(abac_context_t *ctx); |
---|
| 30 | |
---|
| 31 | /* use this to free the results of either of the previous two functions */ |
---|
| 32 | void abac_context_credentials_free(abac_credential_t **credentials); |
---|
| 33 | |
---|
| 34 | /* |
---|
| 35 | * Operations on credentials |
---|
| 36 | */ |
---|
| 37 | abac_role_t *abac_credential_head(abac_credential_t *cred); |
---|
| 38 | abac_role_t *abac_credential_tail(abac_credential_t *cred); |
---|
| 39 | abac_chunk_t abac_credential_attribute_cert(abac_credential_t *cred); |
---|
| 40 | abac_chunk_t abac_credential_issuer_cert(abac_credential_t *cred); |
---|
| 41 | abac_credential_t *abac_credential_lookup(char *cred_string); |
---|
| 42 | char* abac_credential_clause(abac_credential_t *cred); |
---|
| 43 | |
---|
| 44 | abac_credential_t *abac_credential_dup(abac_credential_t *cred); |
---|
| 45 | void abac_credential_free(abac_credential_t *cred); |
---|
| 46 | |
---|
| 47 | /* |
---|
| 48 | * Operations on roles. |
---|
| 49 | */ |
---|
| 50 | abac_role_t *abac_role_principal_new(char *principal); |
---|
| 51 | abac_role_t *abac_role_role_new(char *principal, char *abac_role_name); |
---|
| 52 | abac_role_t *abac_role_linking_new(char *principal, char *linked_role, char *abac_role_name); |
---|
| 53 | |
---|
| 54 | void abac_role_free(abac_role_t *role); |
---|
| 55 | |
---|
| 56 | abac_role_t *abac_role_from_string(char *string); |
---|
| 57 | abac_role_t *abac_role_dup(abac_role_t *role); |
---|
| 58 | |
---|
| 59 | int abac_role_is_principal(abac_role_t *role); |
---|
| 60 | int abac_role_is_role(abac_role_t *role); |
---|
| 61 | int abac_role_is_linking(abac_role_t *role); |
---|
| 62 | int abac_role_is_intersection(abac_role_t *role); |
---|
| 63 | |
---|
| 64 | char *abac_role_string(abac_role_t *role); |
---|
| 65 | char *abac_role_linked_role(abac_role_t *role); |
---|
| 66 | char *abac_role_role_name(abac_role_t *role); |
---|
| 67 | char *abac_role_principal(abac_role_t *role); |
---|
| 68 | |
---|
| 69 | char *abac_role_attr_key(abac_role_t *head_role, abac_role_t *tail_role); |
---|
| 70 | |
---|
| 71 | /* |
---|
| 72 | * Error codes for loading certificates. |
---|
| 73 | */ |
---|
| 74 | #define ABAC_CERT_SUCCESS 0 // certificate loaded, all is well |
---|
| 75 | #define ABAC_CERT_INVALID -1 // invalid format; also file not found |
---|
| 76 | #define ABAC_CERT_BAD_SIG -2 // invalid signature |
---|
| 77 | #define ABAC_CERT_MISSING_ISSUER -3 // missing ID cert that issued the attribute cert |
---|
| 78 | #define ABAC_CERT_BAD_CN -4 // ID cert is not matching CN=principal format |
---|
| 79 | #define ABAC_CERT_BAD_YAP -5 // failed to insert into prolog engine |
---|
| 80 | |
---|
| 81 | #endif /* __ABAC_H__ */ |
---|