static bool fetch_map_from_gencache(TALLOC_CTX *ctx, const char *user_in, char **p_user_out) { char *key, *value; bool found; if (lp_username_map_cache_time() == 0) { return false; } key = talloc_asprintf_strupper_m(ctx, "USERNAME_MAP/%s", user_in); if (key == NULL) { return false; } found = gencache_get(key, &value, NULL); TALLOC_FREE(key); if (!found) { return false; } TALLOC_FREE(*p_user_out); *p_user_out = talloc_strdup(ctx, value); SAFE_FREE(value); if (!*p_user_out) { return false; } return true; }
bool trustdom_cache_fetch(const char* name, struct dom_sid* sid) { char *key = NULL, *value = NULL; time_t timeout; /* exit now if null pointers were passed as they're required further */ if (!sid) return False; /* prepare a key and get the value */ key = trustdom_cache_key(name); if (!key) return False; if (!gencache_get(key, &value, &timeout)) { DEBUG(5, ("no entry for trusted domain %s found.\n", name)); SAFE_FREE(key); return False; } else { SAFE_FREE(key); DEBUG(5, ("trusted domain %s found (%s)\n", name, value)); } /* convert sid string representation into struct dom_sid structure */ if(! string_to_sid(sid, value)) { sid = NULL; SAFE_FREE(value); return False; } SAFE_FREE(value); return True; }
static bool idmap_cache_del_sid2xid(TALLOC_CTX* mem_ctx, char t, const char* sid) { const char* sid_key = key_sid2xid_str(mem_ctx, t, sid); char* xid_str; time_t timeout; bool ret = true; if (!gencache_get(sid_key, &xid_str, &timeout)) { ret = false; goto done; } if (atoi(xid_str) != -1) { const char* xid_key = key_xid2sid_str(mem_ctx, t, xid_str); if (!gencache_del(xid_key)) { DEBUG(2, ("failed to delete: %s\n", xid_key)); ret = false; } else { DEBUG(5, ("delete: %s\n", xid_key)); } } if (!gencache_del(sid_key)) { DEBUG(2, ("failed to delete: %s\n", sid_key)); ret = false; } else { DEBUG(5, ("delete: %s\n", sid_key)); } done: return ret; }
bool idmap_cache_find_uid2sid(uid_t uid, struct dom_sid *sid, bool *expired) { char *key; char *value; time_t timeout; bool ret = true; key = talloc_asprintf(talloc_tos(), "IDMAP/UID2SID/%d", (int)uid); if (key == NULL) { return false; } ret = gencache_get(key, &value, &timeout); TALLOC_FREE(key); if (!ret) { return false; } ZERO_STRUCTP(sid); if (value[0] != '-') { ret = string_to_sid(sid, value); } SAFE_FREE(value); if (ret) { *expired = (timeout <= time(NULL)); } return ret; }
bool idmap_cache_find_sid2uid(const struct dom_sid *sid, uid_t *puid, bool *expired) { fstring sidstr; char *key; char *value; char *endptr; time_t timeout; uid_t uid; bool ret; key = talloc_asprintf(talloc_tos(), "IDMAP/SID2UID/%s", sid_to_fstring(sidstr, sid)); if (key == NULL) { return false; } ret = gencache_get(key, &value, &timeout); TALLOC_FREE(key); if (!ret) { return false; } uid = strtol(value, &endptr, 10); ret = (*endptr == '\0'); SAFE_FREE(value); if (ret) { *puid = uid; *expired = (timeout <= time(NULL)); } return ret; }
bool namecache_status_fetch(const char *keyname, int keyname_type, int name_type, const struct sockaddr_storage *keyip, char *srvname_out) { char *key = NULL; char *value = NULL; time_t timeout; if (!gencache_init()) return False; key = namecache_status_record_key(keyname, keyname_type, name_type, keyip); if (!key) return False; if (!gencache_get(key, &value, &timeout)) { DEBUG(5, ("namecache_status_fetch: no entry for %s found.\n", key)); SAFE_FREE(key); return False; } else { DEBUG(5, ("namecache_status_fetch: key %s -> %s\n", key, value )); } strlcpy(srvname_out, value, 16); SAFE_FREE(key); SAFE_FREE(value); return True; }
bool namecache_fetch(const char *name, int name_type, struct ip_service **ip_list, int *num_names) { char *key, *value; time_t timeout; /* exit now if null pointers were passed as they're required further */ if (!ip_list || !num_names) { return False; } if (!gencache_init()) { return False; } if (name_type > 255) { return False; /* Don't fetch non-real name types. */ } *num_names = 0; /* * Use gencache interface - lookup the key */ key = namecache_key(name, name_type); if (!key) { return False; } if (!gencache_get(key, &value, &timeout)) { DEBUG(5, ("no entry for %s#%02X found.\n", name, name_type)); SAFE_FREE(key); return False; } else { DEBUG(5, ("name %s#%02X found.\n", name, name_type)); } /* * Split up the stored value into the list of IP adresses */ *num_names = ipstr_list_parse(value, ip_list); SAFE_FREE(key); SAFE_FREE(value); return *num_names > 0; /* true only if some ip has been fetched */ }
bool wins_srv_is_dead(struct in_addr wins_ip, struct in_addr src_ip) { char *keystr = wins_srv_keystr(wins_ip, src_ip); bool result; /* If the key exists then the WINS server has been marked as dead */ result = gencache_get(keystr, NULL, NULL); SAFE_FREE(keystr); DEBUG(4, ("wins_srv_is_dead: %s is %s\n", inet_ntoa(wins_ip), result ? "dead" : "alive")); return result; }
uint32 trustdom_cache_fetch_timestamp( void ) { char *value = NULL; time_t timeout; uint32 timestamp; if (!gencache_get(TDOMTSKEY, &value, &timeout)) { DEBUG(5, ("no timestamp for trusted domain cache located.\n")); SAFE_FREE(value); return 0; } timestamp = atoi(value); SAFE_FREE(value); return timestamp; }
/** * Get and display an entry from the cache * * @param argv key to search an entry of * @return 0 on success, otherwise failure **/ static int net_cache_get(int argc, const char **argv) { const char* keystr = argv[0]; char* valuestr; time_t timeout; if (argc < 1) { d_printf("\nUsage: net cache get <key>\n"); return -1; } if (gencache_get(keystr, &valuestr, &timeout)) { print_cache_entry(keystr, valuestr, timeout, NULL); return 0; } d_fprintf(stderr, "Failed to find entry\n"); return -1; }
BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout) { int ret = -1; TDB_DATA keybuf, databuf; char *old_valstr, *datastr; time_t old_timeout; /* fail completely if get null pointers passed */ SMB_ASSERT(keystr && valstr); if (!gencache_init()) return False; /* * Check whether entry exists in the cache * Don't verify gencache_get exit code, since the entry may be expired */ gencache_get(keystr, &old_valstr, &old_timeout); if (!(old_valstr && old_timeout)) return False; DEBUG(10, ("Setting cache entry with key = %s; old value = %s and old timeout \ = %s\n", keystr, old_valstr, ctime(&old_timeout))); asprintf(&datastr, CACHE_DATA_FMT, (int)timeout, valstr); keybuf.dptr = strdup(keystr); keybuf.dsize = strlen(keystr)+1; databuf.dptr = strdup(datastr); databuf.dsize = strlen(datastr)+1; DEBUGADD(10, ("New value = %s, new timeout = %s (%d seconds %s)", valstr, ctime(&timeout), (int)(timeout - time(NULL)), timeout > time(NULL) ? "ahead" : "in the past")); ret = tdb_store(cache, keybuf, databuf, TDB_REPLACE); SAFE_FREE(datastr); SAFE_FREE(old_valstr); SAFE_FREE(keybuf.dptr); SAFE_FREE(databuf.dptr); return ret == 0; }
/** * Get and display an entry from the cache * * @param c A net_context structure * @param argv key to search an entry of * @return 0 on success, otherwise failure **/ static int net_cache_get(struct net_context *c, int argc, const char **argv) { const char* keystr = argv[0]; char* valuestr = NULL; time_t timeout; if (argc < 1 || c->display_usage) { d_printf("\nUsage: net cache get <key>\n"); return -1; } if (gencache_get(keystr, &valuestr, &timeout)) { print_cache_entry(keystr, valuestr, timeout, NULL); SAFE_FREE(valuestr); return 0; } d_fprintf(stderr, "Failed to find entry\n"); return -1; }
static bool idmap_cache_del_xid(char t, int xid) { TALLOC_CTX* mem_ctx = talloc_stackframe(); const char* key = key_xid2sid(mem_ctx, t, xid); char* sid_str = NULL; time_t timeout; bool ret = true; if (!gencache_get(key, &sid_str, &timeout)) { DEBUG(3, ("no entry: %s\n", key)); ret = false; goto done; } if (sid_str[0] != '-') { const char* sid_key = key_sid2xid_str(mem_ctx, t, sid_str); if (!gencache_del(sid_key)) { DEBUG(2, ("failed to delete: %s\n", sid_key)); ret = false; } else { DEBUG(5, ("delete: %s\n", sid_key)); } } if (!gencache_del(key)) { DEBUG(1, ("failed to delete: %s\n", key)); ret = false; } else { DEBUG(5, ("delete: %s\n", key)); } done: talloc_free(mem_ctx); return ret; }