| 37 #include "log.h" |
37 #include "log.h" |
| 38 #include "acl.h" |
38 #include "acl.h" |
| 39 |
39 |
| 40 #define AUTH_TYPE_BASIC "basic" |
40 #define AUTH_TYPE_BASIC "basic" |
| 41 |
41 |
| 42 void acllist_createhandle(Session *sn, Request *rq) { |
42 int acllist_createhandle(Session *sn, Request *rq) { |
| 43 ACLListHandle *handle = pool_malloc(sn->pool, sizeof(ACLListHandle)); |
43 ACLListHandle *handle = pool_malloc(sn->pool, sizeof(ACLListHandle)); |
| |
44 if(!handle) { |
| |
45 return 1; |
| |
46 } |
| 44 handle->defaultauthdb = NULL; |
47 handle->defaultauthdb = NULL; |
| 45 handle->listhead = NULL; |
48 handle->listhead = NULL; |
| 46 handle->listtail = NULL; |
49 handle->listtail = NULL; |
| 47 rq->acllist = handle; |
50 rq->acllist = handle; |
| |
51 return 0; |
| 48 } |
52 } |
| 49 |
53 |
| 50 /* |
54 /* |
| 51 * append or prepend an ACL |
55 * append or prepend an ACL |
| 52 */ |
56 */ |
| 53 void acllist_add(Session *sn, Request *rq, ACLList *acl, int append) { |
57 int acllist_add(Session *sn, Request *rq, ACLList *acl, int append) { |
| 54 if(!rq->acllist) { |
58 if(!rq->acllist) { |
| 55 acllist_createhandle(sn, rq); |
59 if(acllist_createhandle(sn, rq)) { |
| |
60 return 1; |
| |
61 } |
| 56 } |
62 } |
| 57 ACLListHandle *list = rq->acllist; |
63 ACLListHandle *list = rq->acllist; |
| 58 |
64 |
| 59 if(!list->defaultauthdb && acl->authdb) { |
65 if(!list->defaultauthdb && acl->authdb) { |
| 60 list->defaultauthdb = acl->authdb; |
66 list->defaultauthdb = acl->authdb; |
| 61 } |
67 } |
| 62 |
68 |
| 63 ACLListElm *elm = pool_malloc(sn->pool, sizeof(ACLListElm)); |
69 ACLListElm *elm = pool_malloc(sn->pool, sizeof(ACLListElm)); |
| |
70 if(!elm) { |
| |
71 return 1; |
| |
72 } |
| 64 elm->acl = acl; |
73 elm->acl = acl; |
| 65 elm->next = NULL; |
74 elm->next = NULL; |
| 66 if(list->listhead == NULL) { |
75 if(list->listhead == NULL) { |
| 67 list->listhead = elm; |
76 list->listhead = elm; |
| 68 list->listtail = elm; |
77 list->listtail = elm; |
| 73 } else { |
82 } else { |
| 74 elm->next = list->listhead; |
83 elm->next = list->listhead; |
| 75 list->listhead = elm; |
84 list->listhead = elm; |
| 76 } |
85 } |
| 77 } |
86 } |
| 78 } |
87 return 0; |
| 79 |
88 } |
| 80 void acllist_append(Session *sn, Request *rq, ACLList *acl) { |
89 |
| 81 acllist_add(sn, rq, acl, 1); |
90 int acllist_append(Session *sn, Request *rq, ACLList *acl) { |
| 82 } |
91 return acllist_add(sn, rq, acl, 1); |
| 83 |
92 } |
| 84 void acllist_prepend(Session *sn, Request *rq, ACLList *acl) { |
93 |
| 85 acllist_add(sn, rq, acl, 0); |
94 int acllist_prepend(Session *sn, Request *rq, ACLList *acl) { |
| |
95 return acllist_add(sn, rq, acl, 0); |
| 86 } |
96 } |
| 87 |
97 |
| 88 uint32_t acl_oflag2mask(int oflags) { |
98 uint32_t acl_oflag2mask(int oflags) { |
| 89 /* TODO: |
99 /* TODO: |
| 90 * maybe there is a plattform where O_RDWR is not O_RDONLY | O_WRONLY |
100 * maybe there is a plattform where O_RDWR is not O_RDONLY | O_WRONLY |