2 * Samba Unix/Linux SMB client library
4 * Copyright (C) Gregor Beck 2011
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * @brief Notify smbd about idmap changes
23 * @author Gregor Beck <gb@sernet.de>
30 #include "lib/id_cache.h"
31 #include "include/memcache.h"
32 #include "idmap_cache.h"
33 #include "../librpc/gen_ndr/ndr_security.h"
34 #include "../libcli/security/dom_sid.h"
36 bool id_cache_ref_parse(const char* str, struct id_cache_ref* id)
42 if (sscanf(str, "%cID %lu%c", &c, &ul, &trash) == 2) {
55 } else if (string_to_sid(&sid, str)) {
59 } else if (strncmp(str, "USER ", 5) == 0) {
60 id->id.name = str + 5;
67 static bool delete_getpwnam_cache(const char *username)
69 DATA_BLOB name = data_blob_string_const_null(username);
70 DEBUG(6, ("Delete passwd struct for %s from memcache\n",
72 memcache_delete(NULL, GETPWNAM_CACHE, name);
76 void id_cache_delete_from_cache(const struct id_cache_ref* id)
80 idmap_cache_del_uid(id->id.uid);
83 idmap_cache_del_gid(id->id.gid);
86 idmap_cache_del_sid(&id->id.sid);
89 delete_getpwnam_cache(id->id.name);
95 void id_cache_delete_message(struct messaging_context *msg_ctx,
98 struct server_id server_id,
101 const char *msg = (data && data->data) ? (const char *)data->data : "<NULL>";
102 struct id_cache_ref id;
104 if (!id_cache_ref_parse(msg, &id)) {
105 DEBUG(0, ("Invalid ?ID: %s\n", msg));
109 id_cache_delete_from_cache(&id);
112 void id_cache_register_msgs(struct messaging_context *ctx)
114 messaging_register(ctx, NULL, ID_CACHE_DELETE, id_cache_delete_message);