Lines Matching refs:ctx
52 static int sss_ncache_set_ent(struct sss_nc_ctx *ctx, bool permanent,
69 struct sss_nc_ctx *ctx;
71 ctx = talloc_zero(memctx, struct sss_nc_ctx);
72 if (!ctx) return ENOMEM;
76 ctx->tdb = tdb_open("memcache", 0, TDB_INTERNAL, O_RDWR|O_CREAT, 0);
77 if (!ctx->tdb) return errno;
79 ctx->timeout = timeout;
80 ctx->local_timeout = local_timeout;
82 *_ctx = ctx;
86 uint32_t sss_ncache_get_timeout(struct sss_nc_ctx *ctx)
88 return ctx->timeout;
91 static int sss_ncache_check_str(struct sss_nc_ctx *ctx, char *str)
107 data = tdb_fetch(ctx->tdb, key);
139 tdb_delete(ctx->tdb, key);
147 static int sss_ncache_set_str(struct sss_nc_ctx *ctx, char *str,
160 timest = talloc_strdup(ctx, "0");
162 if (use_local_negative == true && ctx->local_timeout > ctx->timeout) {
163 timell = ctx->local_timeout;
166 if (ctx->timeout == 0) {
169 timell = ctx->timeout;
172 timest = talloc_asprintf(ctx, "%llu", timell);
182 ret = tdb_store(ctx->tdb, key, data, TDB_REPLACE);
185 tdb_errorstr(ctx->tdb));
194 static int sss_ncache_check_user_int(struct sss_nc_ctx *ctx, const char *domain,
202 str = talloc_asprintf(ctx, "%s/%s/%s", NC_USER_PREFIX, domain, name);
205 ret = sss_ncache_check_str(ctx, str);
211 static int sss_ncache_check_group_int(struct sss_nc_ctx *ctx,
219 str = talloc_asprintf(ctx, "%s/%s/%s", NC_GROUP_PREFIX, domain, name);
222 ret = sss_ncache_check_str(ctx, str);
228 static int sss_ncache_check_netgr_int(struct sss_nc_ctx *ctx,
236 str = talloc_asprintf(ctx, "%s/%s/%s", NC_NETGROUP_PREFIX, domain, name);
239 ret = sss_ncache_check_str(ctx, str);
245 static int sss_ncache_check_service_int(struct sss_nc_ctx *ctx,
254 str = talloc_asprintf(ctx, "%s/%s/%s",
260 ret = sss_ncache_check_str(ctx, str);
269 static int sss_cache_check_ent(struct sss_nc_ctx *ctx,
277 lower = sss_tc_utf8_str_tolower(ctx, name);
279 ret = checker(ctx, dom->name, lower);
282 ret = checker(ctx, dom->name, name);
288 int sss_ncache_check_user(struct sss_nc_ctx *ctx, struct sss_domain_info *dom,
291 return sss_cache_check_ent(ctx, dom, name, sss_ncache_check_user_int);
294 int sss_ncache_check_upn(struct sss_nc_ctx *ctx, struct sss_domain_info *dom,
300 neg_cache_name = talloc_asprintf(ctx, "@%s", name);
305 ret = sss_cache_check_ent(ctx, dom, neg_cache_name,
312 int sss_ncache_check_group(struct sss_nc_ctx *ctx, struct sss_domain_info *dom,
315 return sss_cache_check_ent(ctx, dom, name, sss_ncache_check_group_int);
318 int sss_ncache_check_netgr(struct sss_nc_ctx *ctx, struct sss_domain_info *dom,
321 return sss_cache_check_ent(ctx, dom, name, sss_ncache_check_netgr_int);
324 static int sss_ncache_set_service_int(struct sss_nc_ctx *ctx, bool permanent,
332 str = talloc_asprintf(ctx, "%s/%s/%s", NC_SERVICE_PREFIX, domain, name);
335 ret = sss_ncache_set_str(ctx, str, permanent, false);
341 int sss_ncache_set_service_name(struct sss_nc_ctx *ctx, bool permanent,
346 char *service_and_protocol = talloc_asprintf(ctx, "%s:%s",
351 ret = sss_ncache_set_ent(ctx, permanent, dom,
358 int sss_ncache_check_service(struct sss_nc_ctx *ctx,struct sss_domain_info *dom,
362 char *service_and_protocol = talloc_asprintf(ctx, "%s:%s",
367 ret = sss_cache_check_ent(ctx, dom, service_and_protocol,
373 int sss_ncache_set_service_port(struct sss_nc_ctx *ctx, bool permanent,
378 char *service_and_protocol = talloc_asprintf(ctx, "%ul:%s",
383 ret = sss_ncache_set_ent(ctx, permanent, dom,
390 int sss_ncache_check_service_port(struct sss_nc_ctx *ctx,
396 char *service_and_protocol = talloc_asprintf(ctx, "%ul:%s",
401 ret = sss_cache_check_ent(ctx, dom, service_and_protocol,
409 int sss_ncache_check_uid(struct sss_nc_ctx *ctx, struct sss_domain_info *dom,
416 str = talloc_asprintf(ctx, "%s/%s/%"SPRIuid, NC_UID_PREFIX, dom->name,
419 str = talloc_asprintf(ctx, "%s/%"SPRIuid, NC_UID_PREFIX, uid);
423 ret = sss_ncache_check_str(ctx, str);
429 int sss_ncache_check_gid(struct sss_nc_ctx *ctx, struct sss_domain_info *dom,
436 str = talloc_asprintf(ctx, "%s/%s/%"SPRIgid, NC_GID_PREFIX, dom->name,
439 str = talloc_asprintf(ctx, "%s/%"SPRIgid, NC_GID_PREFIX, gid);
443 ret = sss_ncache_check_str(ctx, str);
449 int sss_ncache_check_sid(struct sss_nc_ctx *ctx, const char *sid)
454 str = talloc_asprintf(ctx, "%s/%s", NC_SID_PREFIX, sid);
457 ret = sss_ncache_check_str(ctx, str);
463 int sss_ncache_check_cert(struct sss_nc_ctx *ctx, const char *cert)
468 str = talloc_asprintf(ctx, "%s/%s", NC_CERT_PREFIX, cert);
471 ret = sss_ncache_check_str(ctx, str);
478 static int sss_ncache_set_user_int(struct sss_nc_ctx *ctx, bool permanent,
487 str = talloc_asprintf(ctx, "%s/%s/%s", NC_USER_PREFIX, domain, name);
490 if (ctx->local_timeout > 0) {
493 ret = sss_ncache_set_str(ctx, str, permanent, use_local_negative);
499 static int sss_ncache_set_group_int(struct sss_nc_ctx *ctx, bool permanent,
508 str = talloc_asprintf(ctx, "%s/%s/%s", NC_GROUP_PREFIX, domain, name);
511 if (ctx->local_timeout > 0) {
514 ret = sss_ncache_set_str(ctx, str, permanent, use_local_negative);
520 static int sss_ncache_set_netgr_int(struct sss_nc_ctx *ctx, bool permanent,
528 str = talloc_asprintf(ctx, "%s/%s/%s", NC_NETGROUP_PREFIX, domain, name);
531 ret = sss_ncache_set_str(ctx, str, permanent, false);
537 static int sss_ncache_set_ent(struct sss_nc_ctx *ctx, bool permanent,
545 lower = sss_tc_utf8_str_tolower(ctx, name);
547 ret = setter(ctx, permanent, dom->name, lower);
550 ret = setter(ctx, permanent, dom->name, name);
557 int sss_ncache_set_user(struct sss_nc_ctx *ctx, bool permanent,
560 return sss_ncache_set_ent(ctx, permanent, dom, name, sss_ncache_set_user_int);
563 int sss_ncache_set_upn(struct sss_nc_ctx *ctx, bool permanent,
569 neg_cache_name = talloc_asprintf(ctx, "@%s", name);
574 ret = sss_ncache_set_ent(ctx, permanent, dom, neg_cache_name,
581 int sss_ncache_set_group(struct sss_nc_ctx *ctx, bool permanent,
584 return sss_ncache_set_ent(ctx, permanent, dom, name, sss_ncache_set_group_int);
587 int sss_ncache_set_netgr(struct sss_nc_ctx *ctx, bool permanent,
590 return sss_ncache_set_ent(ctx, permanent, dom, name, sss_ncache_set_netgr_int);
593 int sss_ncache_set_uid(struct sss_nc_ctx *ctx, bool permanent,
601 str = talloc_asprintf(ctx, "%s/%s/%"SPRIuid, NC_UID_PREFIX, dom->name,
604 str = talloc_asprintf(ctx, "%s/%"SPRIuid, NC_UID_PREFIX, uid);
608 if (ctx->local_timeout > 0) {
611 ret = sss_ncache_set_str(ctx, str, permanent, use_local_negative);
617 int sss_ncache_set_gid(struct sss_nc_ctx *ctx, bool permanent,
625 str = talloc_asprintf(ctx, "%s/%s/%"SPRIgid, NC_GID_PREFIX, dom->name,
628 str = talloc_asprintf(ctx, "%s/%"SPRIgid, NC_GID_PREFIX, gid);
632 if (ctx->local_timeout > 0) {
635 ret = sss_ncache_set_str(ctx, str, permanent, use_local_negative);
641 int sss_ncache_set_sid(struct sss_nc_ctx *ctx, bool permanent, const char *sid)
646 str = talloc_asprintf(ctx, "%s/%s", NC_SID_PREFIX, sid);
649 ret = sss_ncache_set_str(ctx, str, permanent, false);
655 int sss_ncache_set_cert(struct sss_nc_ctx *ctx, bool permanent,
661 str = talloc_asprintf(ctx, "%s/%s", NC_CERT_PREFIX, cert);
664 ret = sss_ncache_set_str(ctx, str, permanent, false);
681 int sss_ncache_set_domain_locate_type(struct sss_nc_ctx *ctx,
688 str = domain_lookup_type_str(ctx, dom, lookup_type);
695 ret = sss_ncache_set_str(ctx, str, true, false);
700 int sss_ncache_check_domain_locate_type(struct sss_nc_ctx *ctx,
707 str = domain_lookup_type_str(ctx, dom, lookup_type);
710 ret = sss_ncache_check_str(ctx, str);
727 int sss_ncache_set_locate_gid(struct sss_nc_ctx *ctx,
738 str = locate_gid_str(ctx, dom, gid);
743 ret = sss_ncache_set_str(ctx, str, false, false);
748 int sss_ncache_check_locate_gid(struct sss_nc_ctx *ctx,
759 str = locate_gid_str(ctx, dom, gid);
764 ret = sss_ncache_check_str(ctx, str);
769 static char *locate_uid_str(struct sss_nc_ctx *ctx,
773 return talloc_asprintf(ctx,
781 int sss_ncache_set_locate_uid(struct sss_nc_ctx *ctx,
792 str = locate_uid_str(ctx, dom, uid);
797 ret = sss_ncache_set_str(ctx, str, false, false);
802 int sss_ncache_check_locate_uid(struct sss_nc_ctx *ctx,
813 str = locate_uid_str(ctx, dom, uid);
818 ret = sss_ncache_check_str(ctx, str);
857 int sss_ncache_reset_permanent(struct sss_nc_ctx *ctx)
861 ret = tdb_traverse(ctx->tdb, delete_permanent, NULL);
881 static int sss_ncache_reset_pfx(struct sss_nc_ctx *ctx,
891 ret = tdb_traverse(ctx->tdb,
902 int sss_ncache_reset_users(struct sss_nc_ctx *ctx)
910 return sss_ncache_reset_pfx(ctx, prefixes);
913 int sss_ncache_reset_groups(struct sss_nc_ctx *ctx)
921 return sss_ncache_reset_pfx(ctx, prefixes);