s3:smbd: split ID_CACHE_* message handling into parent and child parts
authorStefan Metzmacher <metze@samba.org>
Wed, 14 Dec 2011 09:23:30 +0000 (10:23 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 15 Dec 2011 07:16:31 +0000 (08:16 +0100)
metze

source3/Makefile.in
source3/smbd/msg_idmap.c [deleted file]
source3/smbd/process.c
source3/smbd/proto.h
source3/smbd/server.c
source3/wscript_build

index b0c17f6cff00a4ef041ac7b9021a3e493fbe9587..1389293ad8d9bd5f2a9cb751c8a6e312f2555a48 100644 (file)
@@ -914,7 +914,7 @@ AUTH_OBJ = auth/auth.o @AUTH_STATIC@ auth/auth_util.o auth/token_util.o \
 
 MANGLE_OBJ = smbd/mangle.o smbd/mangle_hash.o smbd/mangle_hash2.o
 
-SMBD_OBJ_MAIN = smbd/server.o smbd/server_exit.o smbd/msg_idmap.o
+SMBD_OBJ_MAIN = smbd/server.o smbd/server_exit.o
 
 BUILDOPT_OBJ = smbd/build_options.o
 
diff --git a/source3/smbd/msg_idmap.c b/source3/smbd/msg_idmap.c
deleted file mode 100644 (file)
index 757cac0..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Samba Unix/Linux SMB client library
- *
- * Copyright (C) Gregor Beck 2011
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "includes.h"
-#include "smbd/globals.h"
-#include "smbd/smbd.h"
-#include "../libcli/security/dom_sid.h"
-#include "../libcli/security/security_token.h"
-#include "idmap_cache.h"
-#include "passdb/lookup_sid.h"
-#include "auth.h"
-#include "messages.h"
-#include "lib/id_cache.h"
-
-static bool uid_in_use(const struct user_struct *user, uid_t uid)
-{
-       while (user) {
-               if (user->session_info &&
-                   (user->session_info->unix_token->uid == uid)) {
-                       return true;
-               }
-               user = user->next;
-       }
-       return false;
-}
-
-static bool gid_in_use(const struct user_struct *user, gid_t gid)
-{
-       while (user) {
-               if (user->session_info != NULL) {
-                       int i;
-                       struct security_unix_token *utok;
-
-                       utok = user->session_info->unix_token;
-                       if (utok->gid == gid) {
-                               return true;
-                       }
-                       for(i=0; i<utok->ngroups; i++) {
-                               if (utok->groups[i] == gid) {
-                                       return true;
-                               }
-                       }
-               }
-               user = user->next;
-       }
-       return false;
-}
-
-static bool sid_in_use(const struct user_struct *user,
-                      const struct dom_sid *psid)
-{
-       while (user) {
-               struct security_token *tok;
-
-               if (user->session_info == NULL) {
-                       continue;
-               }
-               tok = user->session_info->security_token;
-               if (tok == NULL) {
-                       /*
-                        * Not sure session_info->security_token can
-                        * ever be NULL. This check might be not
-                        * necessary.
-                        */
-                       continue;
-               }
-               if (security_token_has_sid(tok, psid)) {
-                       return true;
-               }
-               user = user->next;
-       }
-       return false;
-}
-
-static bool id_in_use(const struct user_struct *user,
-                     const struct id_cache_ref *id)
-{
-       switch(id->type) {
-       case UID:
-               return uid_in_use(user, id->id.uid);
-       case GID:
-               return gid_in_use(user, id->id.gid);
-       case SID:
-               return sid_in_use(user, &id->id.sid);
-       default:
-               break;
-       }
-       return false;
-}
-
-static void id_cache_kill(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 smbd_server_connection *sconn;
-       struct user_struct *validated_users;
-       struct id_cache_ref id;
-
-       sconn = msg_ctx_to_sconn(msg_ctx);
-       if (sconn == NULL) {
-               DEBUG(1, ("could not find sconn\n"));
-               return;
-       }
-
-       validated_users = sconn->smb1.sessions.validated_users;
-
-       if (!id_cache_ref_parse(msg, &id)) {
-               DEBUG(0, ("Invalid ?ID: %s\n", msg));
-               return;
-       }
-
-       if (am_parent) {
-               messaging_send_to_children(msg_ctx, msg_type, data);
-       }
-
-       if (id_in_use(validated_users, &id)) {
-               exit_server_cleanly(msg);
-       }
-       id_cache_delete_from_cache(&id);
-}
-
-static void id_cache_flush(struct messaging_context *ctx,
-                          void* data,
-                          uint32_t msg_type,
-                          struct server_id srv_id,
-                          DATA_BLOB* msg_data)
-{
-       id_cache_flush_message(ctx, data, msg_type, srv_id, msg_data);
-
-       if (am_parent) {
-               messaging_send_to_children(ctx, msg_type, msg_data);
-       }
-}
-
-static void id_cache_delete(struct messaging_context *ctx,
-                           void* data,
-                           uint32_t msg_type,
-                           struct server_id srv_id,
-                           DATA_BLOB* msg_data)
-{
-       id_cache_delete_message(ctx, data, msg_type, srv_id, msg_data);
-
-       if (am_parent) {
-               messaging_send_to_children(ctx, msg_type, msg_data);
-       }
-}
-
-
-void msg_idmap_register_msg(struct messaging_context *ctx)
-{
-       messaging_register(ctx, NULL, ID_CACHE_FLUSH,  id_cache_flush);
-       messaging_register(ctx, NULL, ID_CACHE_DELETE, id_cache_delete);
-       messaging_register(ctx, NULL, ID_CACHE_KILL, id_cache_kill);
-}
index b3e4d0d9fbbf69782a6e11f1c1fd051d68cdfb28..e57faf197826a63face6f71ddd025a9a0308e57d 100644 (file)
@@ -36,6 +36,9 @@
 #include "rpc_server/spoolss/srv_spoolss_nt.h"
 #include "libsmb/libsmb.h"
 #include "../lib/util/tevent_ntstatus.h"
+#include "../libcli/security/dom_sid.h"
+#include "../libcli/security/security_token.h"
+#include "lib/id_cache.h"
 
 extern bool global_machine_password_needs_changing;
 
@@ -2960,6 +2963,109 @@ static NTSTATUS smbd_register_ips(struct smbd_server_connection *sconn,
 
 #endif
 
+static bool uid_in_use(const struct user_struct *user, uid_t uid)
+{
+       while (user) {
+               if (user->session_info &&
+                   (user->session_info->unix_token->uid == uid)) {
+                       return true;
+               }
+               user = user->next;
+       }
+       return false;
+}
+
+static bool gid_in_use(const struct user_struct *user, gid_t gid)
+{
+       while (user) {
+               if (user->session_info != NULL) {
+                       int i;
+                       struct security_unix_token *utok;
+
+                       utok = user->session_info->unix_token;
+                       if (utok->gid == gid) {
+                               return true;
+                       }
+                       for(i=0; i<utok->ngroups; i++) {
+                               if (utok->groups[i] == gid) {
+                                       return true;
+                               }
+                       }
+               }
+               user = user->next;
+       }
+       return false;
+}
+
+static bool sid_in_use(const struct user_struct *user,
+                      const struct dom_sid *psid)
+{
+       while (user) {
+               struct security_token *tok;
+
+               if (user->session_info == NULL) {
+                       continue;
+               }
+               tok = user->session_info->security_token;
+               if (tok == NULL) {
+                       /*
+                        * Not sure session_info->security_token can
+                        * ever be NULL. This check might be not
+                        * necessary.
+                        */
+                       continue;
+               }
+               if (security_token_has_sid(tok, psid)) {
+                       return true;
+               }
+               user = user->next;
+       }
+       return false;
+}
+
+static bool id_in_use(const struct user_struct *user,
+                     const struct id_cache_ref *id)
+{
+       switch(id->type) {
+       case UID:
+               return uid_in_use(user, id->id.uid);
+       case GID:
+               return gid_in_use(user, id->id.gid);
+       case SID:
+               return sid_in_use(user, &id->id.sid);
+       default:
+               break;
+       }
+       return false;
+}
+
+static void smbd_id_cache_kill(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 user_struct *validated_users;
+       struct id_cache_ref id;
+       struct smbd_server_connection *sconn =
+               talloc_get_type_abort(private_data,
+               struct smbd_server_connection);
+
+       validated_users = sconn->smb1.sessions.validated_users;
+
+       if (!id_cache_ref_parse(msg, &id)) {
+               DEBUG(0, ("Invalid ?ID: %s\n", msg));
+               return;
+       }
+
+       if (id_in_use(validated_users, &id)) {
+               exit_server_cleanly(msg);
+       }
+       id_cache_delete_from_cache(&id);
+}
+
 /****************************************************************************
  Process commands from the client
 ****************************************************************************/
@@ -3143,6 +3249,11 @@ void smbd_process(struct tevent_context *ev_ctx,
        messaging_register(sconn->msg_ctx, sconn,
                           MSG_SMB_FILE_RENAME, msg_file_was_renamed);
 
+       id_cache_register_msgs(sconn->msg_ctx);
+       messaging_deregister(sconn->msg_ctx, ID_CACHE_KILL, NULL);
+       messaging_register(sconn->msg_ctx, sconn,
+                          ID_CACHE_KILL, smbd_id_cache_kill);
+
        /*
         * Use the default MSG_DEBUG handler to avoid rebroadcasting
         * MSGs to all child processes
index 0123e7dffb1059c3b8b40857853efd4a60724fa2..2fd59a1f47132b0c71a89977e4c5f9b86c1ba28a 100644 (file)
@@ -1182,8 +1182,4 @@ NTSTATUS vfs_streaminfo(connection_struct *conn,
 void *avahi_start_register(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
                           uint16_t port);
 
-/* The following definitions come from smbd/msg_idmap.c */
-
-void msg_idmap_register_msg(struct messaging_context *ctx);
-
 #endif /* _SMBD_PROTO_H_ */
index 07d2b3ebff4b455e1cfe054adcd9fdd60daf1fc6..7e1bddd23bf10422935b2ae77dc44384008db1d8 100644 (file)
@@ -230,6 +230,48 @@ static void smbd_msg_debug(struct messaging_context *msg_ctx,
        messaging_send_to_children(msg_ctx, MSG_DEBUG, data);
 }
 
+static void smbd_parent_id_cache_kill(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;
+
+       if (!id_cache_ref_parse(msg, &id)) {
+               DEBUG(0, ("Invalid ?ID: %s\n", msg));
+               return;
+       }
+
+       id_cache_delete_from_cache(&id);
+
+       messaging_send_to_children(msg_ctx, msg_type, data);
+}
+
+static void smbd_parent_id_cache_flush(struct messaging_context *ctx,
+                                      void* data,
+                                      uint32_t msg_type,
+                                      struct server_id srv_id,
+                                      DATA_BLOB* msg_data)
+{
+       id_cache_flush_message(ctx, data, msg_type, srv_id, msg_data);
+
+       messaging_send_to_children(ctx, msg_type, msg_data);
+}
+
+static void smbd_parent_id_cache_delete(struct messaging_context *ctx,
+                                       void* data,
+                                       uint32_t msg_type,
+                                       struct server_id srv_id,
+                                       DATA_BLOB* msg_data)
+{
+       id_cache_delete_message(ctx, data, msg_type, srv_id, msg_data);
+
+       messaging_send_to_children(ctx, msg_type, msg_data);
+}
+
 static void add_child_pid(struct smbd_parent_context *parent,
                          pid_t pid)
 {
@@ -768,7 +810,12 @@ static bool open_sockets_smbd(struct smbd_parent_context *parent,
        messaging_register(msg_ctx, NULL, MSG_SMB_BRL_VALIDATE,
                           brl_revalidate);
 
-       msg_idmap_register_msg(msg_ctx);
+       messaging_register(msg_ctx, NULL,
+                          ID_CACHE_FLUSH, smbd_parent_id_cache_flush);
+       messaging_register(msg_ctx, NULL,
+                          ID_CACHE_DELETE, smbd_parent_id_cache_delete);
+       messaging_register(msg_ctx, NULL,
+                          ID_CACHE_KILL, smbd_parent_id_cache_kill);
 
 #ifdef CLUSTER_SUPPORT
        if (lp_clustering()) {
index b07539f7f642c80469e3e5047bad126ba69c1113..4fe432bf5015624df658486f38fff966b7833cdc 100755 (executable)
@@ -339,7 +339,7 @@ WINBINDD_SRC = '''${WINBINDD_SRC1}
 
 MANGLE_SRC = '''smbd/mangle.c smbd/mangle_hash.c smbd/mangle_hash2.c'''
 
-SMBD_SRC_MAIN = '''smbd/server.c smbd/msg_idmap.c'''
+SMBD_SRC_MAIN = '''smbd/server.c'''
 
 BUILDOPT_SRC = '''smbd/build_options.c'''