Lines Matching refs:ctx

73 static char *idmap_strdup(struct sss_idmap_ctx *ctx, const char *str)
78 CHECK_IDMAP_CTX(ctx, NULL);
82 new = ctx->alloc_func(len, ctx->alloc_pvt);
109 construct_range(struct sss_idmap_ctx *ctx,
120 dst = ctx->alloc_func(sizeof(struct idmap_range_params), ctx->alloc_pvt);
245 struct sss_idmap_ctx *ctx;
251 ctx = alloc_func(sizeof(struct sss_idmap_ctx), alloc_pvt);
252 if (ctx == NULL) {
255 memset(ctx, 0, sizeof(struct sss_idmap_ctx));
257 ctx->alloc_func = alloc_func;
258 ctx->alloc_pvt = alloc_pvt;
259 ctx->free_func = (free_func == NULL) ? default_free : free_func;
262 ctx->idmap_opts.autorid_mode = SSS_IDMAP_DEFAULT_AUTORID;
263 ctx->idmap_opts.idmap_lower = SSS_IDMAP_DEFAULT_LOWER;
264 ctx->idmap_opts.idmap_upper = SSS_IDMAP_DEFAULT_UPPER;
265 ctx->idmap_opts.rangesize = SSS_IDMAP_DEFAULT_RANGESIZE;
266 ctx->idmap_opts.extra_slice_init = SSS_IDMAP_DEFAULT_EXTRA_SLICE_INIT;
268 *_ctx = ctx;
273 static void free_helpers(struct sss_idmap_ctx *ctx,
287 ctx->free_func(it->range_id, ctx->alloc_pvt);
288 ctx->free_func(it, ctx->alloc_pvt);
308 static void sss_idmap_free_domain(struct sss_idmap_ctx *ctx,
311 if (ctx == NULL || dom == NULL) {
315 ctx->free_func(dom->range_params.range_id, ctx->alloc_pvt);
317 free_helpers(ctx, dom->helpers, dom->helpers_owner);
319 ctx->free_func(dom->name, ctx->alloc_pvt);
320 ctx->free_func(dom->sid, ctx->alloc_pvt);
321 ctx->free_func(dom, ctx->alloc_pvt);
324 enum idmap_error_code sss_idmap_free(struct sss_idmap_ctx *ctx)
329 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
331 next = ctx->idmap_domain_info;
335 sss_idmap_free_domain(ctx, dom);
338 ctx->free_func(ctx, ctx->alloc_pvt);
343 static enum idmap_error_code sss_idmap_free_ptr(struct sss_idmap_ctx *ctx,
346 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
349 ctx->free_func(ptr, ctx->alloc_pvt);
355 enum idmap_error_code sss_idmap_free_sid(struct sss_idmap_ctx *ctx,
358 return sss_idmap_free_ptr(ctx, sid);
361 enum idmap_error_code sss_idmap_free_dom_sid(struct sss_idmap_ctx *ctx,
364 return sss_idmap_free_ptr(ctx, dom_sid);
367 enum idmap_error_code sss_idmap_free_smb_sid(struct sss_idmap_ctx *ctx,
370 return sss_idmap_free_ptr(ctx, smb_sid);
373 enum idmap_error_code sss_idmap_free_bin_sid(struct sss_idmap_ctx *ctx,
376 return sss_idmap_free_ptr(ctx, bin_sid);
395 enum idmap_error_code sss_idmap_calculate_range(struct sss_idmap_ctx *ctx,
412 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
414 idmap_lower = ctx->idmap_opts.idmap_lower;
415 idmap_upper = ctx->idmap_opts.idmap_upper;
416 rangesize = ctx->idmap_opts.rangesize;
417 autorid_mode = ctx->idmap_opts.autorid_mode;
431 for (dom = ctx->idmap_domain_info; dom != NULL; dom = dom->next) {
462 for (dom = ctx->idmap_domain_info; dom != NULL; dom = dom->next) {
559 enum idmap_error_code sss_idmap_check_collision(struct sss_idmap_ctx *ctx,
570 for (dom = ctx->idmap_domain_info; dom != NULL; dom = dom->next) {
621 generate_sec_slice_name(struct sss_idmap_ctx *ctx,
633 slice_name = ctx->alloc_func(len + 1, ctx->alloc_pvt);
641 ctx->free_func(slice_name, ctx->alloc_pvt);
649 generate_slice(struct sss_idmap_ctx *ctx, char *slice_name, uint32_t first_rid,
656 slice = ctx->alloc_func(sizeof(struct idmap_range_params), ctx->alloc_pvt);
663 err = sss_idmap_calculate_range(ctx, slice_name, NULL, &tmp_range);
665 ctx->free_func(slice, ctx->alloc_pvt);
679 get_helpers(struct sss_idmap_ctx *ctx,
690 for (int i = 0; i < ctx->idmap_opts.extra_slice_init; i++) {
691 secondary_name = generate_sec_slice_name(ctx, domain_sid, first_rid);
697 err = generate_slice(ctx, secondary_name, first_rid, &slice);
702 first_rid += ctx->idmap_opts.rangesize;
719 ctx->free_func(secondary_name, ctx->alloc_pvt);
722 free_helpers(ctx, sec_slices, true);
727 enum idmap_error_code sss_idmap_add_domain_ex(struct sss_idmap_ctx *ctx,
738 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
757 dom = ctx->alloc_func(sizeof(struct idmap_domain_info), ctx->alloc_pvt);
763 dom->name = idmap_strdup(ctx, domain_name);
770 dom->sid = idmap_strdup(ctx, domain_sid);
781 dom->range_params.range_id = idmap_strdup(ctx, range_id);
791 err = dom_check_collision(ctx->idmap_domain_info, dom);
796 dom->next = ctx->idmap_domain_info;
797 ctx->idmap_domain_info = dom;
802 sss_idmap_free_domain(ctx, dom);
808 sss_idmap_add_auto_domain_ex(struct sss_idmap_ctx *ctx,
820 err = sss_idmap_add_domain_ex(ctx, domain_name, domain_sid, range,
829 ctx->idmap_domain_info->auto_add_ranges = false;
833 if ((range->max - range->min + 1) != ctx->idmap_opts.rangesize) {
841 if (ctx->idmap_opts.extra_slice_init == 0) {
842 ctx->idmap_domain_info->auto_add_ranges = false;
847 rid += ctx->idmap_opts.rangesize;
848 err = get_helpers(ctx, domain_sid, rid,
849 &ctx->idmap_domain_info->helpers);
851 ctx->idmap_domain_info->auto_add_ranges = true;
852 ctx->idmap_domain_info->helpers_owner = true;
859 ctx->idmap_domain_info->auto_add_ranges = false;
862 ctx->idmap_domain_info->cb = cb;
863 ctx->idmap_domain_info->pvt = pvt;
868 enum idmap_error_code sss_idmap_add_domain(struct sss_idmap_ctx *ctx,
873 return sss_idmap_add_domain_ex(ctx, domain_name, domain_sid, range, NULL,
939 get_range(struct sss_idmap_ctx *ctx,
951 first_rid = (rid / ctx->idmap_opts.rangesize) * ctx->idmap_opts.rangesize;
953 secondary_name = generate_sec_slice_name(ctx, dom_sid, first_rid);
962 err = construct_range(ctx, helper, secondary_name, &range);
965 err = generate_slice(ctx, secondary_name, first_rid, &range);
976 ctx->free_func(secondary_name, ctx->alloc_pvt);
981 spawn_dom(struct sss_idmap_ctx *ctx,
992 err = sss_idmap_add_domain_ex(ctx,
1001 it = ctx->idmap_domain_info;
1042 add_dom_for_sid(struct sss_idmap_ctx *ctx,
1056 err = get_range(ctx, matched_dom->helpers, matched_dom->sid, rid, &range);
1061 err = spawn_dom(ctx, matched_dom, range);
1075 ctx->free_func(range->range_id, ctx->alloc_pvt);
1077 ctx->free_func(range, ctx->alloc_pvt);
1081 enum idmap_error_code sss_idmap_sid_to_unix(struct sss_idmap_ctx *ctx,
1094 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1096 idmap_domain_info = ctx->idmap_domain_info;
1126 return add_dom_for_sid(ctx, matched_dom, sid, _id);
1132 enum idmap_error_code sss_idmap_check_sid_unix(struct sss_idmap_ctx *ctx,
1144 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1146 if (ctx->idmap_domain_info == NULL) {
1150 idmap_domain_info = ctx->idmap_domain_info;
1177 static enum idmap_error_code generate_sid(struct sss_idmap_ctx *ctx,
1191 sid = ctx->alloc_func(len + 1, ctx->alloc_pvt);
1198 ctx->free_func(sid, ctx->alloc_pvt);
1206 enum idmap_error_code sss_idmap_unix_to_sid(struct sss_idmap_ctx *ctx,
1214 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1216 idmap_domain_info = ctx->idmap_domain_info;
1226 return generate_sid(ctx, idmap_domain_info->sid, rid, _sid);
1233 idmap_domain_info = ctx->idmap_domain_info;
1252 err = spawn_dom(ctx, idmap_domain_info, it);
1257 return generate_sid(ctx, idmap_domain_info->sid, rid, _sid);
1267 enum idmap_error_code sss_idmap_dom_sid_to_unix(struct sss_idmap_ctx *ctx,
1274 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1276 err = sss_idmap_dom_sid_to_sid(ctx, dom_sid, &sid);
1281 err = sss_idmap_sid_to_unix(ctx, sid, id);
1284 ctx->free_func(sid, ctx->alloc_pvt);
1289 enum idmap_error_code sss_idmap_bin_sid_to_unix(struct sss_idmap_ctx *ctx,
1297 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1299 err = sss_idmap_bin_sid_to_sid(ctx, bin_sid, length, &sid);
1304 err = sss_idmap_sid_to_unix(ctx, sid, id);
1307 ctx->free_func(sid, ctx->alloc_pvt);
1312 enum idmap_error_code sss_idmap_smb_sid_to_unix(struct sss_idmap_ctx *ctx,
1319 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1321 err = sss_idmap_smb_sid_to_sid(ctx, smb_sid, &sid);
1326 err = sss_idmap_sid_to_unix(ctx, sid, id);
1329 ctx->free_func(sid, ctx->alloc_pvt);
1334 enum idmap_error_code sss_idmap_check_dom_sid_to_unix(struct sss_idmap_ctx *ctx,
1341 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1343 err = sss_idmap_dom_sid_to_sid(ctx, dom_sid, &sid);
1348 err = sss_idmap_check_sid_unix(ctx, sid, id);
1351 ctx->free_func(sid, ctx->alloc_pvt);
1356 enum idmap_error_code sss_idmap_check_bin_sid_unix(struct sss_idmap_ctx *ctx,
1364 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1366 err = sss_idmap_bin_sid_to_sid(ctx, bin_sid, length, &sid);
1371 err = sss_idmap_check_sid_unix(ctx, sid, id);
1374 ctx->free_func(sid, ctx->alloc_pvt);
1379 enum idmap_error_code sss_idmap_check_smb_sid_unix(struct sss_idmap_ctx *ctx,
1386 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1388 err = sss_idmap_smb_sid_to_sid(ctx, smb_sid, &sid);
1393 err = sss_idmap_check_sid_unix(ctx, sid, id);
1396 ctx->free_func(sid, ctx->alloc_pvt);
1400 enum idmap_error_code sss_idmap_unix_to_dom_sid(struct sss_idmap_ctx *ctx,
1408 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1410 err = sss_idmap_unix_to_sid(ctx, id, &sid);
1415 err = sss_idmap_sid_to_dom_sid(ctx, sid, &dom_sid);
1424 ctx->free_func(sid, ctx->alloc_pvt);
1426 ctx->free_func(dom_sid, ctx->alloc_pvt);
1432 enum idmap_error_code sss_idmap_unix_to_bin_sid(struct sss_idmap_ctx *ctx,
1442 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1444 err = sss_idmap_unix_to_sid(ctx, id, &sid);
1449 err = sss_idmap_sid_to_bin_sid(ctx, sid, &bin_sid, &length);
1459 ctx->free_func(sid, ctx->alloc_pvt);
1461 ctx->free_func(bin_sid, ctx->alloc_pvt);
1469 sss_idmap_ctx_set_autorid(struct sss_idmap_ctx *ctx, bool use_autorid)
1471 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1472 ctx->idmap_opts.autorid_mode = use_autorid;
1477 sss_idmap_ctx_set_lower(struct sss_idmap_ctx *ctx, id_t lower)
1479 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1480 ctx->idmap_opts.idmap_lower = lower;
1485 sss_idmap_ctx_set_upper(struct sss_idmap_ctx *ctx, id_t upper)
1487 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1488 ctx->idmap_opts.idmap_upper = upper;
1493 sss_idmap_ctx_set_rangesize(struct sss_idmap_ctx *ctx, id_t rangesize)
1495 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1496 ctx->idmap_opts.rangesize = rangesize;
1501 sss_idmap_ctx_set_extra_slice_init(struct sss_idmap_ctx *ctx,
1504 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1505 ctx->idmap_opts.extra_slice_init = extra_slice_init;
1510 sss_idmap_ctx_get_autorid(struct sss_idmap_ctx *ctx, bool *_autorid)
1512 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1513 *_autorid = ctx->idmap_opts.autorid_mode;
1518 sss_idmap_ctx_get_lower(struct sss_idmap_ctx *ctx, id_t *_lower)
1520 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1521 *_lower = ctx->idmap_opts.idmap_lower;
1526 sss_idmap_ctx_get_upper(struct sss_idmap_ctx *ctx, id_t *_upper)
1528 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1529 *_upper = ctx->idmap_opts.idmap_upper;
1534 sss_idmap_ctx_get_rangesize(struct sss_idmap_ctx *ctx, id_t *_rangesize)
1536 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1537 *_rangesize = ctx->idmap_opts.rangesize;
1542 sss_idmap_domain_has_algorithmic_mapping(struct sss_idmap_ctx *ctx,
1554 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1556 if (ctx->idmap_domain_info == NULL) {
1560 idmap_domain_info = ctx->idmap_domain_info;
1583 sss_idmap_domain_by_name_has_algorithmic_mapping(struct sss_idmap_ctx *ctx,
1593 CHECK_IDMAP_CTX(ctx, IDMAP_CONTEXT_INVALID);
1595 if (ctx->idmap_domain_info == NULL) {
1599 idmap_domain_info = ctx->idmap_domain_info;