42 conf->namedACLs = NULL; |
43 conf->namedACLs = NULL; |
43 conf->uriACLs = NULL; |
44 conf->uriACLs = NULL; |
44 conf->pathACLs = NULL; |
45 conf->pathACLs = NULL; |
45 |
46 |
46 int r = cfg_parse_basic_file((ConfigParser*)conf, in); |
47 int r = cfg_parse_basic_file((ConfigParser*)conf, in); |
47 UcxMempool *mp = conf->parser.mp; |
|
48 cfg_list_destr(mp, conf->namedACLs); |
|
49 cfg_list_destr(mp, conf->uriACLs); |
|
50 cfg_list_destr(mp, conf->pathACLs); |
|
51 if(r != 0) { |
48 if(r != 0) { |
52 free_acl_file(conf); |
49 free_acl_file(conf); |
53 return NULL; |
50 return NULL; |
54 } |
51 } |
55 |
52 |
57 |
54 |
58 return conf; |
55 return conf; |
59 } |
56 } |
60 |
57 |
61 void free_acl_file(ACLFile *conf) { |
58 void free_acl_file(ACLFile *conf) { |
62 ucx_mempool_destroy(conf->parser.mp); |
59 ucx_mempool_destroy(conf->parser.mp->pool); |
63 free(conf); |
60 free(conf); |
64 } |
61 } |
65 |
62 |
66 int acl_parse(void *p, ConfigLine *begin, ConfigLine *end, sstr_t line) { |
63 int acl_parse(void *p, ConfigLine *begin, ConfigLine *end, sstr_t line) { |
67 ACLFile *aclf = p; |
64 ACLFile *aclf = p; |
68 UcxMempool *mp = aclf->parser.mp; |
65 UcxAllocator *mp = aclf->parser.mp; |
69 |
66 |
70 if(sstr_startswith(line, sstr("ACL "))) { |
67 if(sstrsuffix(line, sstr("ACL "))) { |
71 sstr_t param = sstrsubs(line, 4); |
68 sstr_t param = sstrsubs(line, 4); |
72 UcxList *plist = cfg_param_list(param, mp); |
69 UcxList *plist = cfg_param_list(param, mp); |
73 ACLConfig *acl = OBJ_NEW(mp, ACLConfig); |
70 ACLConfig *acl = OBJ_NEW(mp, ACLConfig); |
74 acl->type.ptr = NULL; |
71 acl->type.ptr = NULL; |
75 acl->authparam = NULL; |
72 acl->authparam = NULL; |
81 sstr_t path = cfg_param_get(plist, sstr("path")); |
78 sstr_t path = cfg_param_get(plist, sstr("path")); |
82 sstr_t uri = cfg_param_get(plist, sstr("uri")); |
79 sstr_t uri = cfg_param_get(plist, sstr("uri")); |
83 |
80 |
84 if(name.ptr) { |
81 if(name.ptr) { |
85 acl->id = name; |
82 acl->id = name; |
86 aclf->namedACLs = ucx_list_append(aclf->namedACLs, acl); |
83 aclf->namedACLs = ucx_list_append_a(mp, aclf->namedACLs, acl); |
87 } else if(path.ptr) { |
84 } else if(path.ptr) { |
88 acl->id = path; |
85 acl->id = path; |
89 aclf->pathACLs = ucx_list_append(aclf->pathACLs, acl); |
86 aclf->pathACLs = ucx_list_append_a(mp, aclf->pathACLs, acl); |
90 } else if(uri.ptr) { |
87 } else if(uri.ptr) { |
91 acl->id = uri; |
88 acl->id = uri; |
92 aclf->uriACLs = ucx_list_append(aclf->uriACLs, acl); |
89 aclf->uriACLs = ucx_list_append_a(mp, aclf->uriACLs, acl); |
93 } |
90 } |
94 |
91 |
95 if(type.ptr) { |
92 if(type.ptr) { |
96 acl->type = type; |
93 acl->type = type; |
97 } |
94 } |
98 } else if(sstr_startswith(line, sstr("Authenticate "))) { |
95 } else if(sstrsuffix(line, sstr("Authenticate "))) { |
99 sstr_t param = sstrsubs(line, 13); |
96 sstr_t param = sstrsubs(line, 13); |
100 UcxList *plist = cfg_param_list(param, mp); |
97 UcxList *plist = cfg_param_list(param, mp); |
101 aclf->cur->authparam = plist; |
98 aclf->cur->authparam = plist; |
102 } else { |
99 } else { |
103 if(parse_ace(aclf, line)) { |
100 if(parse_ace(aclf, line)) { |
109 return 0; |
106 return 0; |
110 } |
107 } |
111 |
108 |
112 int parse_ace(ACLFile *f, sstr_t line) { |
109 int parse_ace(ACLFile *f, sstr_t line) { |
113 ACLConfig *cur = f->cur; |
110 ACLConfig *cur = f->cur; |
114 UcxMempool *mp = f->parser.mp; |
111 UcxAllocator *mp = f->parser.mp; |
115 |
112 |
116 size_t tkn = 0; |
113 size_t tkn = 0; |
117 sstr_t *tk = sstrsplit(line, sstr(":"), &tkn); |
114 sstr_t *tk = sstrsplit(line, sstr(":"), &tkn); |
118 if(!tk || tkn < 3) { |
115 if(!tk || tkn < 3) { |
119 fprintf(stderr, "parse_ace: to few tokens\n"); |
116 fprintf(stderr, "parse_ace: to few tokens\n"); |
131 |
128 |
132 if(!sstrcmp(s, sstr("user"))) { |
129 if(!sstrcmp(s, sstr("user"))) { |
133 // next token is the user name |
130 // next token is the user name |
134 s = tk[1]; |
131 s = tk[1]; |
135 n++; |
132 n++; |
136 ace->who = sstrdup_mp(mp, s); |
133 ace->who = sstrdup_a(mp, s); |
137 } else if(!sstrcmp(s, sstr("group"))) { |
134 } else if(!sstrcmp(s, sstr("group"))) { |
138 // next token is the group name |
135 // next token is the group name |
139 s = tk[1]; |
136 s = tk[1]; |
140 n++; |
137 n++; |
141 ace->who = sstrdup_mp(mp, s); |
138 ace->who = sstrdup_a(mp, s); |
142 ace->flags = ACLCFG_IDENTIFIER_GROUP; |
139 ace->flags = ACLCFG_IDENTIFIER_GROUP; |
143 } else if(!sstrcmp(s, sstr("owner@"))) { |
140 } else if(!sstrcmp(s, sstr("owner@"))) { |
144 ace->flags = ACLCFG_OWNER; |
141 ace->flags = ACLCFG_OWNER; |
145 } else if(!sstrcmp(s, sstr("group@"))) { |
142 } else if(!sstrcmp(s, sstr("group@"))) { |
146 ace->flags = ACLCFG_GROUP; |
143 ace->flags = ACLCFG_GROUP; |
147 } else if(!sstrcmp(s, sstr("everyone@"))) { |
144 } else if(!sstrcmp(s, sstr("everyone@"))) { |
148 ace->flags = ACLCFG_EVERYONE; |
145 ace->flags = ACLCFG_EVERYONE; |
149 } else { |
146 } else { |
150 // you can specify only the user name in the ace |
147 // you can specify only the user name in the ace |
151 ace->who = sstrdup_mp(mp, s); |
148 ace->who = sstrdup_a(mp, s); |
152 } |
149 } |
153 |
150 |
154 n++; //next token |
151 n++; //next token |
155 |
152 |
156 /* |
153 /* |