[SCM] Samba Shared Repository - branch master updated
Michael Adam
obnox at samba.org
Mon Feb 28 06:08:02 MST 2011
The branch, master has been updated
via 5808188 s3: smbcontrol to notify smbd about idmap changes
via 42a4a9c s3: add functions to remove entries from idmap cache
via 6710561 s3: add functions to remove entries from idmap memcache
via 01e7611 s3: add functions to flush the idmap memcache
via d03631c WHATSNEW: document removed parameter "idmap alloc backend"
via 68f5f0a WHATSNEW: document new nfs quota backend for linux
from eeeae97 s3: Fix a typo
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 58081884f76ecd902e407a2cb24ab36261d2a507
Author: Gregor Beck <gbeck at sernet.de>
Date: Thu Feb 3 16:30:29 2011 +0100
s3: smbcontrol to notify smbd about idmap changes
Autobuild-User: Michael Adam <obnox at samba.org>
Autobuild-Date: Mon Feb 28 14:07:23 CET 2011 on sn-devel-104
commit 42a4a9cbc339ffcafc23969c03e02050e1394dfb
Author: Gregor Beck <gbeck at sernet.de>
Date: Fri Feb 18 14:47:03 2011 +0100
s3: add functions to remove entries from idmap cache
commit 6710561c273643af27c6f06a3fe7bacdb4a2f95e
Author: Gregor Beck <gbeck at sernet.de>
Date: Fri Feb 18 14:45:14 2011 +0100
s3: add functions to remove entries from idmap memcache
commit 01e76110501785a65387c360fcfee85fbf3a4fde
Author: Gregor Beck <gbeck at sernet.de>
Date: Fri Feb 18 14:42:18 2011 +0100
s3: add functions to flush the idmap memcache
commit d03631c43f7763bfaef22f93514b493169dd39f6
Author: Michael Adam <obnox at samba.org>
Date: Tue Feb 1 11:59:25 2011 +0100
WHATSNEW: document removed parameter "idmap alloc backend"
commit 68f5f0ae7b2600bba787a6f4a3028ab825bc2ace
Author: Michael Adam <obnox at samba.org>
Date: Tue Feb 1 12:06:11 2011 +0100
WHATSNEW: document new nfs quota backend for linux
-----------------------------------------------------------------------
Summary of changes:
WHATSNEW.txt | 10 ++
source3/Makefile.in | 2 +-
source3/include/proto.h | 9 ++
source3/lib/idmap_cache.c | 116 +++++++++++++++++++++
source3/lib/idmap_cache.h | 4 +
source3/librpc/idl/messaging.idl | 4 +
source3/passdb/lookup_sid.c | 66 ++++++++++++
source3/smbd/msg_idmap.c | 205 ++++++++++++++++++++++++++++++++++++++
source3/smbd/server.c | 2 +
source3/utils/smbcontrol.c | 49 +++++++++
10 files changed, 466 insertions(+), 1 deletions(-)
create mode 100644 source3/smbd/msg_idmap.c
Changeset truncated at 500 lines:
diff --git a/WHATSNEW.txt b/WHATSNEW.txt
index 9c44e75..0e5db2b 100644
--- a/WHATSNEW.txt
+++ b/WHATSNEW.txt
@@ -127,6 +127,15 @@ More information can be found on
http://holger123.wordpress.com/smb-traffic-analyzer/
+NFS quota backend on Linux
+--------------------------
+
+A new nfs quota backend for Linux has been added that is based
+on the existing Solaris/FreeBSD implementation. This allows samba
+to communicate correct diskfree information for nfs imports that
+are re-exported as samba shares.
+
+
######################################################################
Changes
#######
@@ -141,6 +150,7 @@ smb.conf changes
client ntlmv2 auth Changed Default Yes
client use spnego principal New No
ctdb locktime warn threshold New 0
+ idmap alloc backend Removed
idmap read only New No
log writeable files on exit New No
multicast dns register New Yes
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 2f3575f..b7a7a78 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -868,7 +868,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_OBJ_MAIN = smbd/server.o smbd/server_exit.o smbd/msg_idmap.o
BUILDOPT_OBJ = smbd/build_options.o
diff --git a/source3/include/proto.h b/source3/include/proto.h
index fdc2b7b..cf58cdf 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -3631,6 +3631,11 @@ NTSTATUS get_primary_group_sid(TALLOC_CTX *mem_ctx,
const char *username,
struct passwd **_pwd,
struct dom_sid **_group_sid);
+bool delete_uid_cache(uid_t uid);
+bool delete_gid_cache(gid_t gid);
+bool delete_sid_cache(const struct dom_sid* psid);
+void flush_uid_cache(void);
+void flush_gid_cache(void);
/* The following definitions come from passdb/machine_sid.c */
@@ -5452,6 +5457,10 @@ struct AvahiPoll *tevent_avahi_poll(TALLOC_CTX *mem_ctx,
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_msgs(struct messaging_context *ctx);
+
/* Misc protos */
struct fncall_context *fncall_context_init(TALLOC_CTX *mem_ctx,
diff --git a/source3/lib/idmap_cache.c b/source3/lib/idmap_cache.c
index fbe3a7e..e2270eb 100644
--- a/source3/lib/idmap_cache.c
+++ b/source3/lib/idmap_cache.c
@@ -260,3 +260,119 @@ void idmap_cache_set_sid2gid(const struct dom_sid *sid, gid_t gid)
gencache_set(key, value, now + timeout);
}
}
+
+static char* key_xid2sid_str(TALLOC_CTX* mem_ctx, char t, const char* id) {
+ return talloc_asprintf(mem_ctx, "IDMAP/%cID2SID/%s", t, id);
+}
+
+static char* key_xid2sid(TALLOC_CTX* mem_ctx, char t, int id) {
+ char str[32];
+ snprintf(str, sizeof(str), "%d", id);
+ return key_xid2sid_str(mem_ctx, t, str);
+}
+
+static char* key_sid2xid_str(TALLOC_CTX* mem_ctx, char t, const char* sid) {
+ return talloc_asprintf(mem_ctx, "IDMAP/SID2%cID/%s", t, sid);
+}
+
+/* static char* key_sid2xid(TALLOC_CTX* mem_ctx, char t, const struct dom_sid* sid) */
+/* { */
+/* char* sid_str = sid_string_talloc(mem_ctx, sid); */
+/* char* key = key_sid2xid_str(mem_ctx, t, sid_str); */
+/* talloc_free(sid_str); */
+/* return key; */
+/* } */
+
+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(0, ("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(0, ("failed to delete: %s\n", sid_key));
+ ret = false;
+ } else {
+ DEBUG(0, ("delete: %s\n", sid_key));
+ }
+
+ }
+
+ if (!gencache_del(key)) {
+ DEBUG(0, ("failed to delete: %s\n", key));
+ ret = false;
+ } else {
+ DEBUG(0, ("delete: %s\n", key));
+ }
+
+done:
+ talloc_free(mem_ctx);
+ return ret;
+}
+
+bool idmap_cache_del_uid(uid_t uid) {
+ return idmap_cache_del_xid('U', uid);
+}
+
+bool idmap_cache_del_gid(gid_t gid) {
+ return idmap_cache_del_xid('G', gid);
+}
+
+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(0, ("failed to delete: %s\n", xid_key));
+ ret = false;
+ } else {
+ DEBUG(0, ("delete: %s\n", xid_key));
+ }
+ }
+
+ if (!gencache_del(sid_key)) {
+ DEBUG(0, ("failed to delete: %s\n", sid_key));
+ ret = false;
+ } else {
+ DEBUG(0, ("delete: %s\n", sid_key));
+ }
+done:
+ return ret;
+}
+
+bool idmap_cache_del_sid(const struct dom_sid *sid)
+{
+ TALLOC_CTX* mem_ctx = talloc_stackframe();
+ const char* sid_str = sid_string_talloc(mem_ctx, sid);
+ bool ret = true;
+
+ if (!idmap_cache_del_sid2xid(mem_ctx, 'U', sid_str) &&
+ !idmap_cache_del_sid2xid(mem_ctx, 'G', sid_str))
+ {
+ DEBUG(0, ("no entry: %s\n", key_xid2sid_str(mem_ctx, '?', sid_str)));
+ ret = false;
+ }
+
+ talloc_free(mem_ctx);
+ return ret;
+}
diff --git a/source3/lib/idmap_cache.h b/source3/lib/idmap_cache.h
index f511780..af2ba82 100644
--- a/source3/lib/idmap_cache.h
+++ b/source3/lib/idmap_cache.h
@@ -8,3 +8,7 @@ bool idmap_cache_find_sid2gid(const struct dom_sid *sid, gid_t *pgid,
bool *expired);
bool idmap_cache_find_gid2sid(gid_t gid, struct dom_sid *sid, bool *expired);
void idmap_cache_set_sid2gid(const struct dom_sid *sid, gid_t gid);
+
+bool idmap_cache_del_uid(uid_t uid);
+bool idmap_cache_del_gid(gid_t gid);
+bool idmap_cache_del_sid(const struct dom_sid *sid);
diff --git a/source3/librpc/idl/messaging.idl b/source3/librpc/idl/messaging.idl
index 36f064f..8618d53 100644
--- a/source3/librpc/idl/messaging.idl
+++ b/source3/librpc/idl/messaging.idl
@@ -35,6 +35,10 @@ interface messaging
MSG_REQ_DMALLOC_LOG_CHANGED = 0x000C,
MSG_SHUTDOWN = 0x000D,
+ MSG_IDMAP_FLUSH = 0x000E,
+ MSG_IDMAP_DELETE = 0x000F,
+ MSG_IDMAP_KILL = 0x0010,
+
/* nmbd messages */
MSG_FORCE_ELECTION = 0x0101,
MSG_WINS_NEW_ENTRY = 0x0102,
diff --git a/source3/passdb/lookup_sid.c b/source3/passdb/lookup_sid.c
index 0e1b8d6..68072f3 100644
--- a/source3/passdb/lookup_sid.c
+++ b/source3/passdb/lookup_sid.c
@@ -1642,3 +1642,69 @@ done:
TALLOC_FREE(tmp_ctx);
return NT_STATUS_OK;
}
+
+bool delete_uid_cache(uid_t puid)
+{
+ DATA_BLOB uid = data_blob_const(&puid, sizeof(puid));
+ DATA_BLOB sid;
+
+ if (!memcache_lookup(NULL, UID_SID_CACHE, uid, &sid)) {
+ DEBUG(3, ("UID %d is not memcached!\n", (int)puid));
+ return false;
+ }
+ DEBUG(3, ("Delete mapping UID %d <-> %s from memcache\n", (int)puid,
+ sid_string_dbg((struct dom_sid*)sid.data)));
+ memcache_delete(NULL, SID_UID_CACHE, sid);
+ memcache_delete(NULL, UID_SID_CACHE, uid);
+ return true;
+}
+
+bool delete_gid_cache(gid_t pgid)
+{
+ DATA_BLOB gid = data_blob_const(&pgid, sizeof(pgid));
+ DATA_BLOB sid;
+ if (!memcache_lookup(NULL, GID_SID_CACHE, gid, &sid)) {
+ DEBUG(3, ("GID %d is not memcached!\n", (int)pgid));
+ return false;
+ }
+ DEBUG(3, ("Delete mapping GID %d <-> %s from memcache\n", (int)pgid,
+ sid_string_dbg((struct dom_sid*)sid.data)));
+ memcache_delete(NULL, SID_GID_CACHE, sid);
+ memcache_delete(NULL, GID_SID_CACHE, gid);
+ return true;
+}
+
+bool delete_sid_cache(const struct dom_sid* psid)
+{
+ DATA_BLOB sid = data_blob_const(psid, ndr_size_dom_sid(psid, 0));
+ DATA_BLOB id;
+ if (memcache_lookup(NULL, SID_GID_CACHE, sid, &id)) {
+ DEBUG(3, ("Delete mapping %s <-> GID %d from memcache\n",
+ sid_string_dbg(psid), *(int*)id.data));
+ memcache_delete(NULL, SID_GID_CACHE, sid);
+ memcache_delete(NULL, GID_SID_CACHE, id);
+ } else if (memcache_lookup(NULL, SID_UID_CACHE, sid, &id)) {
+ DEBUG(3, ("Delete mapping %s <-> UID %d from memcache\n",
+ sid_string_dbg(psid), *(int*)id.data));
+ memcache_delete(NULL, SID_UID_CACHE, sid);
+ memcache_delete(NULL, UID_SID_CACHE, id);
+ } else {
+ DEBUG(3, ("SID %s is not memcached!\n", sid_string_dbg(psid)));
+ return false;
+ }
+ return true;
+}
+
+void flush_gid_cache(void)
+{
+ DEBUG(3, ("Flush GID <-> SID memcache\n"));
+ memcache_flush(NULL, SID_GID_CACHE);
+ memcache_flush(NULL, GID_SID_CACHE);
+}
+
+void flush_uid_cache(void)
+{
+ DEBUG(3, ("Flush UID <-> SID memcache\n"));
+ memcache_flush(NULL, SID_UID_CACHE);
+ memcache_flush(NULL, UID_SID_CACHE);
+}
diff --git a/source3/smbd/msg_idmap.c b/source3/smbd/msg_idmap.c
new file mode 100644
index 0000000..9e2424d
--- /dev/null
+++ b/source3/smbd/msg_idmap.c
@@ -0,0 +1,205 @@
+/*
+ * 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/>.
+ */
+
+/**
+ * @brief Notify smbd about idmap changes
+ * @file msg_idmap.c
+ * @author Gregor Beck <gb at sernet.de>
+ * @date Feb 2011
+ *
+ */
+
+#include "includes.h"
+#include "memcache.h"
+#include "globals.h"
+#include "../libcli/security/dom_sid.h"
+#include "../librpc/gen_ndr/messaging.h"
+#include "../librpc/gen_ndr/ndr_security.h"
+#include "idmap_cache.h"
+
+struct id {
+ union {
+ uid_t uid;
+ gid_t gid;
+ struct dom_sid sid;
+ };
+ enum {UID, GID, SID} type;
+};
+
+static bool parse_id(const char* str, struct id* id)
+{
+ struct dom_sid sid;
+ unsigned long ul;
+ char c, trash;
+
+ if (sscanf(str, "%cID %lu%c", &c, &ul, &trash) == 2) {
+ switch(c) {
+ case 'G':
+ id->gid = ul;
+ id->type = GID;
+ return true;
+ case 'U':
+ id->uid = ul;
+ id->type = UID;
+ return true;
+ default:
+ break;
+ }
+ } else if (string_to_sid(&sid, str)) {
+ id->sid = sid;
+ id->type = SID;
+ return true;
+ }
+ return false;
+}
+
+static bool uid_in_use(const struct user_struct* user, uid_t uid)
+{
+ while (user) {
+ if (user->session_info && (user->session_info->utok.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 unix_user_token utok = user->session_info->utok;
+ 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)
+{
+ uid_t uid;
+ gid_t gid;
+ if (sid_to_gid(psid, &gid)) {
+ return gid_in_use(user, gid);
+ } else if (sid_to_uid(psid, &uid)) {
+ return uid_in_use(user, uid);
+ }
+ return false;
+}
+
+
+static bool id_in_use(const struct user_struct* user, const struct id* id)
+{
+ switch(id->type) {
+ case UID:
+ return uid_in_use(user, id->uid);
+ case GID:
+ return gid_in_use(user, id->gid);
+ case SID:
+ return sid_in_use(user, &id->sid);
+ default:
+ break;
+ }
+ return false;
+}
+
+static void delete_from_cache(const struct id* id)
+{
+ switch(id->type) {
+ case UID:
+ delete_uid_cache(id->uid);
+ idmap_cache_del_uid(id->uid);
+ break;
+ case GID:
+ delete_gid_cache(id->gid);
+ idmap_cache_del_gid(id->gid);
+ break;
+ case SID:
+ delete_sid_cache(&id->sid);
+ idmap_cache_del_sid(&id->sid);
+ break;
+ 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)
+{
+ const char* msg = data ? (const char*)data->data : NULL;
+
+ DEBUG(0, ("Foo: idmap flush cache message(0x%.2x): %s\n", msg_type, msg ? msg : "<NULL>"));
+
+ if ((msg == NULL) || (msg[0] == '\0')) {
+ flush_gid_cache();
+ flush_uid_cache();
+ } else if (strncmp(msg, "GID", 3)) {
+ flush_gid_cache();
+ } else if (strncmp(msg, "UID", 3)) {
+ flush_uid_cache();
+ } else {
+ DEBUG(0, ("Invalid argument: %s\n", msg));
+ }
+}
+
+
+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)
+{
+ const char* msg = (data && data->data) ? (const char*)data->data : "<NULL>";
+ bool do_kill = (msg_type == MSG_IDMAP_KILL);
+ struct user_struct* validated_users = smbd_server_conn->smb1.sessions.validated_users;
+ struct id id;
+
+ DEBUG(0, ("Foo: idmap delete message(0x%.2x): %s\n", msg_type, msg));
+
+ if (!parse_id(msg, &id)) {
+ DEBUG(0, ("Invalid ?ID: %s\n", msg));
+ return;
+ }
+
+ if( do_kill && id_in_use(validated_users, &id) ) {
+ exit_server_cleanly(msg);
+ } else {
+ delete_from_cache(&id);
+ }
+}
+
+void msg_idmap_register_msgs(struct messaging_context *ctx)
+{
--
Samba Shared Repository
More information about the samba-cvs
mailing list