s3-passdb: Keep caches coherent
[idra/samba.git] / source3 / lib / id_cache.c
index 50649dd4095f98abb694b2f4d40cabd887a8341f..71693c14643fcf76ea211e2ea435f0a47e46a481 100644 (file)
@@ -56,6 +56,10 @@ bool id_cache_ref_parse(const char* str, struct id_cache_ref* id)
                id->id.sid = sid;
                id->type = SID;
                return true;
+       } else if (strncmp(str, "USER ", 5) == 0) {
+               id->id.name = str + 5;
+               id->type = USERNAME;
+               return true;
        }
        return false;
 }
@@ -112,6 +116,15 @@ static bool delete_sid_cache(const struct dom_sid* psid)
        return true;
 }
 
+static bool delete_getpwnam_cache(const char *username)
+{
+       DATA_BLOB name = data_blob_string_const_null(username);
+       DEBUG(6, ("Delete passwd struct for %s from memcache\n",
+                 username));
+       memcache_delete(NULL, GETPWNAM_CACHE, name);
+       return true;
+}
+
 static void flush_gid_cache(void)
 {
        DEBUG(3, ("Flush GID <-> SID memcache\n"));
@@ -140,17 +153,19 @@ static void delete_from_cache(const struct id_cache_ref* id)
                delete_sid_cache(&id->id.sid);
                idmap_cache_del_sid(&id->id.sid);
                break;
+       case USERNAME:
+               delete_getpwnam_cache(id->id.name);
        default:
                break;
        }
 }
 
 
-static void message_idmap_flush(struct messaging_context *msg_ctx,
-                               void* private_data,
-                               uint32_t msg_type,
-                               struct server_id server_id,
-                               DATA_BLOB* data)
+static void id_cache_flush(struct messaging_context *msg_ctx,
+                          void* private_data,
+                          uint32_t msg_type,
+                          struct server_id server_id,
+                          DATA_BLOB* data)
 {
        const char *msg = data ? (const char *)data->data : NULL;
 
@@ -166,11 +181,11 @@ static void message_idmap_flush(struct messaging_context *msg_ctx,
        }
 }
 
-static void message_idmap_delete(struct messaging_context *msg_ctx,
-                                void *private_data,
-                                uint32_t msg_type,
-                                struct server_id server_id,
-                                DATA_BLOB* data)
+static void id_cache_delete(struct messaging_context *msg_ctx,
+                           void *private_data,
+                           uint32_t msg_type,
+                           struct server_id server_id,
+                           DATA_BLOB* data)
 {
        const char *msg = (data && data->data) ? (const char *)data->data : "<NULL>";
        struct id_cache_ref id;
@@ -183,8 +198,8 @@ static void message_idmap_delete(struct messaging_context *msg_ctx,
        delete_from_cache(&id);
 }
 
-void msg_idmap_register_msgs(struct messaging_context *ctx)
+void id_cache_register_msgs(struct messaging_context *ctx)
 {
-       messaging_register(ctx, NULL, MSG_IDMAP_FLUSH,  message_idmap_flush);
-       messaging_register(ctx, NULL, MSG_IDMAP_DELETE, message_idmap_delete);
+       messaging_register(ctx, NULL, ID_CACHE_FLUSH,  id_cache_flush);
+       messaging_register(ctx, NULL, ID_CACHE_DELETE, id_cache_delete);
 }