From 668a9af94eebd7cc875a1f0c7d9fbcb135fb5c61 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 21 Jun 2003 08:35:30 +0000 Subject: This removes the StrCaseCmp() stuff from 'net idmap' and 'net groupmap'. The correct way to implement this stuff is via a function table, as exampled in all the other parts of 'net'. This also moves the idmap code into a new file. Volker, is this your code? You might want to put your name on it. Andrew Bartlett (This used to be commit 477f2d9e390bb18d4f08d1cac9c981b73d628c4f) --- source3/utils/net_idmap.c | 156 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 source3/utils/net_idmap.c (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c new file mode 100644 index 0000000000..0fea4311ec --- /dev/null +++ b/source3/utils/net_idmap.c @@ -0,0 +1,156 @@ +/* + Samba Unix/Linux SMB client library + Distributed SMB/CIFS Server Management Utility + Copyright (C) 2003 Andrew Bartlett (abartlet@samba.org) + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include "includes.h" +#include "../utils/net.h" + + +/*********************************************************** + Helper function for net_idmap_dump. Dump one entry. + **********************************************************/ +static int net_idmap_dump_one_entry(TDB_CONTEXT *tdb, + TDB_DATA key, + TDB_DATA data, + void *unused) +{ + if (strcmp(key.dptr, "USER HWM") == 0) { + printf("USER HWM %d\n", IVAL(data.dptr,0)); + return 0; + } + + if (strcmp(key.dptr, "GROUP HWM") == 0) { + printf("GROUP HWM %d\n", IVAL(data.dptr,0)); + return 0; + } + + if (strncmp(key.dptr, "S-", 2) != 0) + return 0; + + printf("%s %s\n", data.dptr, key.dptr); + return 0; +} + +/*********************************************************** + Dump the current idmap + **********************************************************/ +static int net_idmap_dump(int argc, const char **argv) +{ + TDB_CONTEXT *idmap_tdb; + + if ( argc != 1 ) + return net_help_idmap( argc, argv ); + + idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDONLY, 0); + + if (idmap_tdb == NULL) { + d_printf("Could not open idmap: %s\n", argv[0]); + return -1; + } + + tdb_traverse(idmap_tdb, net_idmap_dump_one_entry, NULL); + + tdb_close(idmap_tdb); + + return 0; +} + +/*********************************************************** + Write entries from stdin to current local idmap + **********************************************************/ +static int net_idmap_restore(int argc, const char **argv) +{ + if (!idmap_init()) { + d_printf("Could not init idmap\n"); + return -1; + } + + while (!feof(stdin)) { + fstring line, sid_string; + int len; + unid_t id; + int type = ID_EMPTY; + DOM_SID sid; + + if (fgets(line, sizeof(line)-1, stdin) == NULL) + break; + + len = strlen(line); + + if ( (len > 0) && (line[len-1] == '\n') ) + line[len-1] = '\0'; + + if (sscanf(line, "GID %d %s", &id.gid, sid_string) == 2) { + type = ID_GROUPID; + } + + if (sscanf(line, "UID %d %s", &id.uid, sid_string) == 2) { + type = ID_USERID; + } + + if (type == ID_EMPTY) { + d_printf("ignoring invalid line [%s]\n", line); + continue; + } + + if (!string_to_sid(&sid, sid_string)) { + d_printf("ignoring invalid sid [%s]\n", sid_string); + continue; + } + + if (!NT_STATUS_IS_OK(idmap_set_mapping(&sid, id, type))) { + d_printf("Could not set mapping of %s %d to sid %s\n", + (type == ID_GROUPID) ? "GID" : "UID", + (type == ID_GROUPID) ? id.gid : id.uid, + sid_string_static(&sid)); + continue; + } + + } + + idmap_close(); + return 0; +} + +int net_help_idmap(int argc, const char **argv) +{ + d_printf("net idmap dump filename"\ + "\n Dump current id mapping\n"); + + d_printf("net idmap restore"\ + "\n Restore entries from stdin to current local idmap\n"); + + return -1; +} + +/*********************************************************** + Look at the current idmap + **********************************************************/ +int net_idmap(int argc, const char **argv) +{ + struct functable func[] = { + {"dump", net_idmap_dump}, + {"restore", net_idmap_restore}, + {"help", net_help_idmap}, + {NULL, NULL} + }; + + return net_run_function(argc, argv, func, net_help_idmap); +} + + -- cgit From 0e983b32fd309de24b923a5c4928635c6c03e89f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 27 Jun 2003 20:55:48 +0000 Subject: Some const correctness. Stop tdb being used as a remote backend. If an idmap backend is specified cause smbd to ask winbindd (use winbindd if you want a consistant remote backend solution). Should work well enough for next beta now... Jeremy. (This used to be commit 8f830c509af5976d988a30f0b0aee4ec61dd97a3) --- source3/utils/net_idmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 0fea4311ec..689d4ff813 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -75,7 +75,7 @@ static int net_idmap_dump(int argc, const char **argv) **********************************************************/ static int net_idmap_restore(int argc, const char **argv) { - if (!idmap_init()) { + if (!idmap_init(lp_idmap_backend())) { d_printf("Could not init idmap\n"); return -1; } -- cgit From 80c1f1d865b13a63c7a60876b63458119566e044 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 22 Jul 2003 04:31:20 +0000 Subject: Fixup a bunch of printf-style functions and debugs to use unsigned long when displaying pid_t, uid_t and gid_t values. This removes a whole lot of warnings on some of the 64-bit build farm machines as well as help us out when 64-bit uid/gid/pid values come along. (This used to be commit f93528ba007c8800a850678f35f499fb7360fb9a) --- source3/utils/net_idmap.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 689d4ff813..b7eb8e4c49 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -95,10 +95,14 @@ static int net_idmap_restore(int argc, const char **argv) if ( (len > 0) && (line[len-1] == '\n') ) line[len-1] = '\0'; + /* Yuck - this is broken for sizeof(gid_t) != sizeof(int) */ + if (sscanf(line, "GID %d %s", &id.gid, sid_string) == 2) { type = ID_GROUPID; } + /* Yuck - this is broken for sizeof(uid_t) != sizeof(int) */ + if (sscanf(line, "UID %d %s", &id.uid, sid_string) == 2) { type = ID_USERID; } -- cgit From c9bc4b27b71f6baaa9dde1722061f3d59d8554bc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 22 Jul 2003 06:52:39 +0000 Subject: Another round of uid/gid/pid format string changes I missed the first time. (This used to be commit 6616485dbad74dab7506609c6bfd183fc9c1f93c) --- source3/utils/net_idmap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index b7eb8e4c49..b035d8d2f1 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -118,9 +118,10 @@ static int net_idmap_restore(int argc, const char **argv) } if (!NT_STATUS_IS_OK(idmap_set_mapping(&sid, id, type))) { - d_printf("Could not set mapping of %s %d to sid %s\n", + d_printf("Could not set mapping of %s %lu to sid %s\n", (type == ID_GROUPID) ? "GID" : "UID", - (type == ID_GROUPID) ? id.gid : id.uid, + (type == ID_GROUPID) ? (unsigned long)id.gid: + (unsigned long)id.uid, sid_string_static(&sid)); continue; } -- cgit From 2afb1b60d77edb53ddf803680ed0aa8799169130 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 24 Feb 2004 15:45:10 +0000 Subject: 'net idmap restore' is too useful to be left broken :-) Set the HWM values correctly after having manipulated the tdb. Volker (This used to be commit b1eba2188b1be183f37219a722903adc14b91369) --- source3/utils/net_idmap.c | 106 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index b035d8d2f1..61ef919b84 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -70,6 +70,109 @@ static int net_idmap_dump(int argc, const char **argv) return 0; } +/*********************************************************** + Fix up the HWMs after a idmap restore. + **********************************************************/ + +struct hwms { + BOOL ok; + int user_hwm; + int group_hwm; +}; + +static int net_idmap_find_max_id(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA data, + void *handle) +{ + struct hwms *hwms = (struct hwms *)handle; + int *idptr = NULL; + int id; + + if (strncmp(key.dptr, "S-", 2) != 0) + return 0; + + if (sscanf(data.dptr, "GID %d", &id) == 1) { + idptr = &hwms->group_hwm; + } + + if (sscanf(data.dptr, "UID %d", &id) == 1) { + idptr = &hwms->user_hwm; + } + + if (idptr == NULL) { + d_printf("Illegal idmap entry: [%s]->[%s]\n", + key.dptr, data.dptr); + hwms->ok = False; + return -1; + } + + if (*idptr <= id) + *idptr = id+1; + + return 0; +} + +static NTSTATUS net_idmap_fixup_hwm(void) +{ + NTSTATUS result = NT_STATUS_UNSUCCESSFUL; + TDB_CONTEXT *idmap_tdb; + char *tdbfile = NULL; + int dummy; + + struct hwms hwms; + struct hwms highest; + + if (!lp_idmap_uid(&hwms.user_hwm, &highest.user_hwm) || + !lp_idmap_gid(&hwms.group_hwm, &highest.group_hwm)) { + d_printf("idmap range missing\n"); + return NT_STATUS_UNSUCCESSFUL; + } + + tdbfile = strdup(lock_path("winbindd_idmap.tdb")); + if (!tdbfile) { + DEBUG(0, ("idmap_init: out of memory!\n")); + return NT_STATUS_NO_MEMORY; + } + + idmap_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR, 0); + + if (idmap_tdb == NULL) { + d_printf("Could not open idmap: %s\n", tdbfile); + return NT_STATUS_NO_SUCH_FILE; + } + + hwms.ok = True; + + tdb_traverse(idmap_tdb, net_idmap_find_max_id, &hwms); + + if (!hwms.ok) { + goto done; + } + + d_printf("USER HWM: %d GROUP HWM: %d\n", + hwms.user_hwm, hwms.group_hwm); + + if (hwms.user_hwm >= highest.user_hwm) { + d_printf("Highest UID out of uid range\n"); + goto done; + } + + if (hwms.group_hwm >= highest.group_hwm) { + d_printf("Highest GID out of gid range\n"); + goto done; + } + + if ((tdb_store_int32(idmap_tdb, "USER HWM", hwms.user_hwm) != 0) || + (tdb_store_int32(idmap_tdb, "GROUP HWM", hwms.group_hwm) != 0)) { + d_printf("Could not store HWMs\n"); + goto done; + } + + result = NT_STATUS_OK; + done: + tdb_close(idmap_tdb); + return result; +} + /*********************************************************** Write entries from stdin to current local idmap **********************************************************/ @@ -129,7 +232,8 @@ static int net_idmap_restore(int argc, const char **argv) } idmap_close(); - return 0; + + return NT_STATUS_IS_OK(net_idmap_fixup_hwm()) ? 0 : -1; } int net_help_idmap(int argc, const char **argv) -- cgit From 6d3e45579ec62e732bf51fe21e935a0e4b2204a7 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 24 Feb 2004 17:28:17 +0000 Subject: Remove unused variable. Volker (This used to be commit eece7ff000a9589d56130e93a6105ad1052e9a14) --- source3/utils/net_idmap.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 61ef919b84..f5b4bf1b4a 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -116,7 +116,6 @@ static NTSTATUS net_idmap_fixup_hwm(void) NTSTATUS result = NT_STATUS_UNSUCCESSFUL; TDB_CONTEXT *idmap_tdb; char *tdbfile = NULL; - int dummy; struct hwms hwms; struct hwms highest; -- cgit From b4cf9e95059071df49b34ff8574e48cb96f42da1 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 7 Oct 2004 04:01:18 +0000 Subject: r2835: Since we always have -I. and -I$(srcdir) in CFLAGS, we can get rid of '..' from all #include preprocessor commands. This fixes bugzilla #1880 where OpenVMS gets confused about the '.' characters. (This used to be commit 7f161702fa4916979602cc0295919b541912acd6) --- source3/utils/net_idmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index f5b4bf1b4a..35892e8b52 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -18,7 +18,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "includes.h" -#include "../utils/net.h" +#include "utils/net.h" /*********************************************************** -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/utils/net_idmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 35892e8b52..b4f4cdb0a8 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -126,7 +126,7 @@ static NTSTATUS net_idmap_fixup_hwm(void) return NT_STATUS_UNSUCCESSFUL; } - tdbfile = strdup(lock_path("winbindd_idmap.tdb")); + tdbfile = SMB_STRDUP(lock_path("winbindd_idmap.tdb")); if (!tdbfile) { DEBUG(0, ("idmap_init: out of memory!\n")); return NT_STATUS_NO_MEMORY; -- cgit From 35657ac39e27d6b8268430015c2750a3c8c1ce1e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 17 Dec 2004 10:20:53 +0000 Subject: r4254: Add an undocumented hack. I had to delete a wrong mapping (a user that had ended up as a gid in winbindd_idmap.tdb) from winbindd_idmap.tdb. Stopping winbind was not an option on that machine.... net idmap delete Thanks, Volker (This used to be commit 27c16733c13bb1c91d356f1c9f5c1f069e24cca2) --- source3/utils/net_idmap.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index b4f4cdb0a8..f7ebd94f34 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -235,6 +235,57 @@ static int net_idmap_restore(int argc, const char **argv) return NT_STATUS_IS_OK(net_idmap_fixup_hwm()) ? 0 : -1; } +/*********************************************************** + Delete a SID mapping from a winbindd_idmap.tdb + **********************************************************/ +static int net_idmap_delete(int argc, const char **argv) +{ + TDB_CONTEXT *idmap_tdb; + TDB_DATA key, data; + fstring sid; + + if (argc != 2) + return net_help_idmap(argc, argv); + + idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDWR, 0); + + if (idmap_tdb == NULL) { + d_printf("Could not open idmap: %s\n", argv[0]); + return -1; + } + + fstrcpy(sid, argv[1]); + + if (strncmp(sid, "S-1-5-", strlen("S-1-5-")) != 0) { + d_printf("Can only delete SIDs, %s is does not start with " + "S-1-5-\n", sid); + return -1; + } + + key.dptr = sid; + key.dsize = strlen(key.dptr)+1; + + data = tdb_fetch(idmap_tdb, key); + + if (data.dptr == NULL) { + d_printf("Could not find sid %s\n", argv[1]); + return -1; + } + + if (tdb_delete(idmap_tdb, key) != 0) { + d_printf("Could not delete key %s\n", argv[1]); + return -1; + } + + if (tdb_delete(idmap_tdb, data) != 0) { + d_printf("Could not delete key %s\n", data.dptr); + return -1; + } + + return 0; +} + + int net_help_idmap(int argc, const char **argv) { d_printf("net idmap dump filename"\ @@ -243,6 +294,8 @@ int net_help_idmap(int argc, const char **argv) d_printf("net idmap restore"\ "\n Restore entries from stdin to current local idmap\n"); + /* Deliberately *not* document net idmap delete */ + return -1; } @@ -254,6 +307,7 @@ int net_idmap(int argc, const char **argv) struct functable func[] = { {"dump", net_idmap_dump}, {"restore", net_idmap_restore}, + {"delete", net_idmap_delete}, {"help", net_help_idmap}, {NULL, NULL} }; -- cgit From 9b1e5a71180f340a1f6327d53e68bb9b661ec894 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 25 Jan 2005 01:19:02 +0000 Subject: r4972: Fix a warning and some debugging-outputs. Guenther (This used to be commit 1eabfa050b661168b42892c2d841c7891e59cf5f) --- source3/utils/net_idmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index f7ebd94f34..7abb31ab3d 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -288,7 +288,7 @@ static int net_idmap_delete(int argc, const char **argv) int net_help_idmap(int argc, const char **argv) { - d_printf("net idmap dump filename"\ + d_printf("net idmap dump "\ "\n Dump current id mapping\n"); d_printf("net idmap restore"\ -- cgit From 8d7c88667190fe286971ac4fffb64ee5bd9eeeb0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 18 Oct 2005 03:24:00 +0000 Subject: r11137: Compile with only 2 warnings (I'm still working on that code) on a gcc4 x86_64 box. Jeremy. (This used to be commit d720867a788c735e56d53d63265255830ec21208) --- source3/utils/net_idmap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 7abb31ab3d..0ee180e13e 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -76,8 +76,8 @@ static int net_idmap_dump(int argc, const char **argv) struct hwms { BOOL ok; - int user_hwm; - int group_hwm; + uid_t user_hwm; + gid_t group_hwm; }; static int net_idmap_find_max_id(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA data, @@ -160,8 +160,8 @@ static NTSTATUS net_idmap_fixup_hwm(void) goto done; } - if ((tdb_store_int32(idmap_tdb, "USER HWM", hwms.user_hwm) != 0) || - (tdb_store_int32(idmap_tdb, "GROUP HWM", hwms.group_hwm) != 0)) { + if ((tdb_store_int32(idmap_tdb, "USER HWM", (int32)hwms.user_hwm) != 0) || + (tdb_store_int32(idmap_tdb, "GROUP HWM", (int32)hwms.group_hwm) != 0)) { d_printf("Could not store HWMs\n"); goto done; } -- cgit From ff00d8e96383dbf6781d550ec1eff54b8737ef94 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 18 Oct 2005 18:02:37 +0000 Subject: r11155: Remove warning in torturous logic. Jeremy. (This used to be commit c7373b39bae6dca8281d45d1ff3f2161465838df) --- source3/utils/net_idmap.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 0ee180e13e..8109bef522 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -84,18 +84,21 @@ static int net_idmap_find_max_id(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA data, void *handle) { struct hwms *hwms = (struct hwms *)handle; - int *idptr = NULL; + void *idptr = NULL; + BOOL isgid = False; int id; if (strncmp(key.dptr, "S-", 2) != 0) return 0; if (sscanf(data.dptr, "GID %d", &id) == 1) { - idptr = &hwms->group_hwm; + idptr = (void *)&hwms->group_hwm; + isgid = True; } if (sscanf(data.dptr, "UID %d", &id) == 1) { - idptr = &hwms->user_hwm; + idptr = (void *)&hwms->user_hwm; + isgid = False; } if (idptr == NULL) { @@ -105,8 +108,15 @@ static int net_idmap_find_max_id(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA data, return -1; } - if (*idptr <= id) - *idptr = id+1; + if (isgid) { + if (hwms->group_hwm <= (gid_t)id) { + hwms->group_hwm = (gid_t)(id+1); + } + } else { + if (hwms->user_hwm <= (uid_t)id) { + hwms->user_hwm = (uid_t)(id+1); + } + } return 0; } -- cgit From c42be9fd38556a1cc2e16c8d763a592beb863806 Mon Sep 17 00:00:00 2001 From: Lars Müller Date: Tue, 17 Jan 2006 21:22:00 +0000 Subject: r12986: Use d_fprintf(stderr, ...) for any error message in net. All 'usage' messages are still printed to stdout. Fix some compiler warnings for system() calls where we didn't used the return code. Add appropriate error messages and return with the error code we got from system() or NT_STATUS_UNSUCCESSFUL. (This used to be commit f650e3bdafc4c6bcd7eb4bcf8b6b885b979919eb) --- source3/utils/net_idmap.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 8109bef522..0b5f68101e 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -59,7 +59,7 @@ static int net_idmap_dump(int argc, const char **argv) idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDONLY, 0); if (idmap_tdb == NULL) { - d_printf("Could not open idmap: %s\n", argv[0]); + d_fprintf(stderr, "Could not open idmap: %s\n", argv[0]); return -1; } @@ -102,7 +102,7 @@ static int net_idmap_find_max_id(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA data, } if (idptr == NULL) { - d_printf("Illegal idmap entry: [%s]->[%s]\n", + d_fprintf(stderr, "Illegal idmap entry: [%s]->[%s]\n", key.dptr, data.dptr); hwms->ok = False; return -1; @@ -132,7 +132,7 @@ static NTSTATUS net_idmap_fixup_hwm(void) if (!lp_idmap_uid(&hwms.user_hwm, &highest.user_hwm) || !lp_idmap_gid(&hwms.group_hwm, &highest.group_hwm)) { - d_printf("idmap range missing\n"); + d_fprintf(stderr, "idmap range missing\n"); return NT_STATUS_UNSUCCESSFUL; } @@ -145,7 +145,7 @@ static NTSTATUS net_idmap_fixup_hwm(void) idmap_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR, 0); if (idmap_tdb == NULL) { - d_printf("Could not open idmap: %s\n", tdbfile); + d_fprintf(stderr, "Could not open idmap: %s\n", tdbfile); return NT_STATUS_NO_SUCH_FILE; } @@ -161,18 +161,18 @@ static NTSTATUS net_idmap_fixup_hwm(void) hwms.user_hwm, hwms.group_hwm); if (hwms.user_hwm >= highest.user_hwm) { - d_printf("Highest UID out of uid range\n"); + d_fprintf(stderr, "Highest UID out of uid range\n"); goto done; } if (hwms.group_hwm >= highest.group_hwm) { - d_printf("Highest GID out of gid range\n"); + d_fprintf(stderr, "Highest GID out of gid range\n"); goto done; } if ((tdb_store_int32(idmap_tdb, "USER HWM", (int32)hwms.user_hwm) != 0) || (tdb_store_int32(idmap_tdb, "GROUP HWM", (int32)hwms.group_hwm) != 0)) { - d_printf("Could not store HWMs\n"); + d_fprintf(stderr, "Could not store HWMs\n"); goto done; } @@ -188,7 +188,7 @@ static NTSTATUS net_idmap_fixup_hwm(void) static int net_idmap_restore(int argc, const char **argv) { if (!idmap_init(lp_idmap_backend())) { - d_printf("Could not init idmap\n"); + d_fprintf(stderr, "Could not init idmap\n"); return -1; } @@ -230,7 +230,7 @@ static int net_idmap_restore(int argc, const char **argv) } if (!NT_STATUS_IS_OK(idmap_set_mapping(&sid, id, type))) { - d_printf("Could not set mapping of %s %lu to sid %s\n", + d_fprintf(stderr, "Could not set mapping of %s %lu to sid %s\n", (type == ID_GROUPID) ? "GID" : "UID", (type == ID_GROUPID) ? (unsigned long)id.gid: (unsigned long)id.uid, @@ -260,14 +260,14 @@ static int net_idmap_delete(int argc, const char **argv) idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDWR, 0); if (idmap_tdb == NULL) { - d_printf("Could not open idmap: %s\n", argv[0]); + d_fprintf(stderr, "Could not open idmap: %s\n", argv[0]); return -1; } fstrcpy(sid, argv[1]); if (strncmp(sid, "S-1-5-", strlen("S-1-5-")) != 0) { - d_printf("Can only delete SIDs, %s is does not start with " + d_fprintf(stderr, "Can only delete SIDs, %s is does not start with " "S-1-5-\n", sid); return -1; } @@ -278,17 +278,17 @@ static int net_idmap_delete(int argc, const char **argv) data = tdb_fetch(idmap_tdb, key); if (data.dptr == NULL) { - d_printf("Could not find sid %s\n", argv[1]); + d_fprintf(stderr, "Could not find sid %s\n", argv[1]); return -1; } if (tdb_delete(idmap_tdb, key) != 0) { - d_printf("Could not delete key %s\n", argv[1]); + d_fprintf(stderr, "Could not delete key %s\n", argv[1]); return -1; } if (tdb_delete(idmap_tdb, data) != 0) { - d_printf("Could not delete key %s\n", data.dptr); + d_fprintf(stderr, "Could not delete key %s\n", data.dptr); return -1; } -- cgit From c2528679d8a5da90c027f21c4970a211c5175da9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 15 Jun 2006 21:46:15 +0000 Subject: r16270: Fix Klocwork #706 - ensure sscanf has correct format specifier. Jeremy. (This used to be commit dc53d35b0a1491da94e231943a81547be4c75631) --- source3/utils/net_idmap.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 0b5f68101e..47e1f93b69 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -193,7 +193,7 @@ static int net_idmap_restore(int argc, const char **argv) } while (!feof(stdin)) { - fstring line, sid_string; + fstring line, sid_string, fmt_string; int len; unid_t id; int type = ID_EMPTY; @@ -208,14 +208,15 @@ static int net_idmap_restore(int argc, const char **argv) line[len-1] = '\0'; /* Yuck - this is broken for sizeof(gid_t) != sizeof(int) */ - - if (sscanf(line, "GID %d %s", &id.gid, sid_string) == 2) { + snprintf(fmt_string, sizeof(fmt_string), "GID %%d %%%us", FSTRING_LEN); + if (sscanf(line, fmt_string, &id.gid, sid_string) == 2) { type = ID_GROUPID; } /* Yuck - this is broken for sizeof(uid_t) != sizeof(int) */ - if (sscanf(line, "UID %d %s", &id.uid, sid_string) == 2) { + snprintf(fmt_string, sizeof(fmt_string), "UID %%d %%%us", FSTRING_LEN); + if (sscanf(line, fmt_string, &id.uid, sid_string) == 2) { type = ID_USERID; } -- cgit From fbdcf2663b56007a438ac4f0d8d82436b1bfe688 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/utils/net_idmap.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 47e1f93b69..87da952247 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -185,6 +185,7 @@ static NTSTATUS net_idmap_fixup_hwm(void) /*********************************************************** Write entries from stdin to current local idmap **********************************************************/ + static int net_idmap_restore(int argc, const char **argv) { if (!idmap_init(lp_idmap_backend())) { @@ -193,10 +194,11 @@ static int net_idmap_restore(int argc, const char **argv) } while (!feof(stdin)) { - fstring line, sid_string, fmt_string; + fstring line, sid_string, fmt_string1, fmt_string2; int len; unid_t id; - int type = ID_EMPTY; + enum idmap_type type; + unsigned long idval; DOM_SID sid; if (fgets(line, sizeof(line)-1, stdin) == NULL) @@ -207,20 +209,16 @@ static int net_idmap_restore(int argc, const char **argv) if ( (len > 0) && (line[len-1] == '\n') ) line[len-1] = '\0'; - /* Yuck - this is broken for sizeof(gid_t) != sizeof(int) */ - snprintf(fmt_string, sizeof(fmt_string), "GID %%d %%%us", FSTRING_LEN); - if (sscanf(line, fmt_string, &id.gid, sid_string) == 2) { - type = ID_GROUPID; - } - - /* Yuck - this is broken for sizeof(uid_t) != sizeof(int) */ + snprintf(fmt_string1, sizeof(fmt_string1), "GID %%ul %%%us", FSTRING_LEN); + snprintf(fmt_string2, sizeof(fmt_string2), "UID %%ul %%%us", FSTRING_LEN); - snprintf(fmt_string, sizeof(fmt_string), "UID %%d %%%us", FSTRING_LEN); - if (sscanf(line, fmt_string, &id.uid, sid_string) == 2) { + if (sscanf(line, fmt_string1, &idval, sid_string) == 2) { + type = ID_GROUPID; + id.gid = (gid_t)idval; + } else if (sscanf(line, fmt_string2, &idval, sid_string) == 2) { type = ID_USERID; - } - - if (type == ID_EMPTY) { + id.uid = (uid_t)idval; + } else { d_printf("ignoring invalid line [%s]\n", line); continue; } -- cgit From 4225f9a4bd5eece4d57820bbabb7b882610aa7cc Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 12 Dec 2006 14:52:13 +0000 Subject: r20116: Start merging in the work done to create the new idmap subsystem. Simo. (This used to be commit 50cd8bffeeed2cac755f75fc3d76fe41c451976b) --- source3/utils/net_idmap.c | 375 ++++++++++++++++++++++------------------------ 1 file changed, 176 insertions(+), 199 deletions(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 87da952247..dd16c4b02d 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -20,166 +20,59 @@ #include "includes.h" #include "utils/net.h" - -/*********************************************************** - Helper function for net_idmap_dump. Dump one entry. - **********************************************************/ -static int net_idmap_dump_one_entry(TDB_CONTEXT *tdb, - TDB_DATA key, - TDB_DATA data, - void *unused) -{ - if (strcmp(key.dptr, "USER HWM") == 0) { - printf("USER HWM %d\n", IVAL(data.dptr,0)); - return 0; - } - - if (strcmp(key.dptr, "GROUP HWM") == 0) { - printf("GROUP HWM %d\n", IVAL(data.dptr,0)); - return 0; - } - - if (strncmp(key.dptr, "S-", 2) != 0) - return 0; - - printf("%s %s\n", data.dptr, key.dptr); - return 0; -} +#define ALLOC_CHECK(mem) do { \ + if (!mem) { \ + d_fprintf(stderr, "Out of memory!\n"); \ + talloc_free(ctx); \ + return -1; \ + } } while(0) /*********************************************************** Dump the current idmap **********************************************************/ static int net_idmap_dump(int argc, const char **argv) { - TDB_CONTEXT *idmap_tdb; - - if ( argc != 1 ) - return net_help_idmap( argc, argv ); - - idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDONLY, 0); - - if (idmap_tdb == NULL) { - d_fprintf(stderr, "Could not open idmap: %s\n", argv[0]); - return -1; - } - - tdb_traverse(idmap_tdb, net_idmap_dump_one_entry, NULL); - - tdb_close(idmap_tdb); - - return 0; -} - -/*********************************************************** - Fix up the HWMs after a idmap restore. - **********************************************************/ - -struct hwms { - BOOL ok; - uid_t user_hwm; - gid_t group_hwm; -}; - -static int net_idmap_find_max_id(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA data, - void *handle) -{ - struct hwms *hwms = (struct hwms *)handle; - void *idptr = NULL; - BOOL isgid = False; - int id; + TALLOC_CTX *ctx; + char *filename; - if (strncmp(key.dptr, "S-", 2) != 0) - return 0; - - if (sscanf(data.dptr, "GID %d", &id) == 1) { - idptr = (void *)&hwms->group_hwm; - isgid = True; - } - - if (sscanf(data.dptr, "UID %d", &id) == 1) { - idptr = (void *)&hwms->user_hwm; - isgid = False; + if (argc != 1) { + return net_help_idmap(argc, argv); } - if (idptr == NULL) { - d_fprintf(stderr, "Illegal idmap entry: [%s]->[%s]\n", - key.dptr, data.dptr); - hwms->ok = False; + if (! winbind_ping()) { + d_fprintf(stderr, "To use net idmap Winbindd must be running.\n"); return -1; } - if (isgid) { - if (hwms->group_hwm <= (gid_t)id) { - hwms->group_hwm = (gid_t)(id+1); + ctx = talloc_new(NULL); + ALLOC_CHECK(ctx); + + filename = talloc_strdup(ctx, argv[0]); + ALLOC_CHECK(filename); + + /* filename must be absolute */ + if (*filename != '/') { + char path[4096]; + + filename = getcwd(path, 4095); + if ( ! filename) { + d_fprintf(stderr, "Failed to obtain full output file path"); + talloc_free(ctx); + return -1; } - } else { - if (hwms->user_hwm <= (uid_t)id) { - hwms->user_hwm = (uid_t)(id+1); - } - } - - return 0; -} -static NTSTATUS net_idmap_fixup_hwm(void) -{ - NTSTATUS result = NT_STATUS_UNSUCCESSFUL; - TDB_CONTEXT *idmap_tdb; - char *tdbfile = NULL; - - struct hwms hwms; - struct hwms highest; - - if (!lp_idmap_uid(&hwms.user_hwm, &highest.user_hwm) || - !lp_idmap_gid(&hwms.group_hwm, &highest.group_hwm)) { - d_fprintf(stderr, "idmap range missing\n"); - return NT_STATUS_UNSUCCESSFUL; - } - - tdbfile = SMB_STRDUP(lock_path("winbindd_idmap.tdb")); - if (!tdbfile) { - DEBUG(0, ("idmap_init: out of memory!\n")); - return NT_STATUS_NO_MEMORY; - } - - idmap_tdb = tdb_open_log(tdbfile, 0, TDB_DEFAULT, O_RDWR, 0); - - if (idmap_tdb == NULL) { - d_fprintf(stderr, "Could not open idmap: %s\n", tdbfile); - return NT_STATUS_NO_SUCH_FILE; - } - - hwms.ok = True; - - tdb_traverse(idmap_tdb, net_idmap_find_max_id, &hwms); - - if (!hwms.ok) { - goto done; + filename = talloc_asprintf(ctx, "%s/%s", path, argv[0]); + ALLOC_CHECK(filename); } - d_printf("USER HWM: %d GROUP HWM: %d\n", - hwms.user_hwm, hwms.group_hwm); - - if (hwms.user_hwm >= highest.user_hwm) { - d_fprintf(stderr, "Highest UID out of uid range\n"); - goto done; - } - - if (hwms.group_hwm >= highest.group_hwm) { - d_fprintf(stderr, "Highest GID out of gid range\n"); - goto done; - } - - if ((tdb_store_int32(idmap_tdb, "USER HWM", (int32)hwms.user_hwm) != 0) || - (tdb_store_int32(idmap_tdb, "GROUP HWM", (int32)hwms.group_hwm) != 0)) { - d_fprintf(stderr, "Could not store HWMs\n"); - goto done; + if ( ! winbind_idmap_dump_maps(ctx, filename)) { + d_fprintf(stderr, "Failed to obtain idmap data from winbindd\n"); + talloc_free(ctx); + return -1; } - result = NT_STATUS_OK; - done: - tdb_close(idmap_tdb); - return result; + talloc_free(ctx); + return 0; } /*********************************************************** @@ -188,20 +81,31 @@ static NTSTATUS net_idmap_fixup_hwm(void) static int net_idmap_restore(int argc, const char **argv) { - if (!idmap_init(lp_idmap_backend())) { - d_fprintf(stderr, "Could not init idmap\n"); + TALLOC_CTX *ctx; + FILE *input; + + if (! winbind_ping()) { + d_fprintf(stderr, "To use net idmap Winbindd must be running.\n"); return -1; } - while (!feof(stdin)) { - fstring line, sid_string, fmt_string1, fmt_string2; + ctx = talloc_new(NULL); + ALLOC_CHECK(ctx); + + if (argc == 1) { + input = fopen(argv[0], "r"); + } else { + input = stdin; + } + + while (!feof(input)) { + char line[128], sid_string[128]; int len; - unid_t id; - enum idmap_type type; - unsigned long idval; DOM_SID sid; + struct id_map map; + unsigned long idval; - if (fgets(line, sizeof(line)-1, stdin) == NULL) + if (fgets(line, 127, input) == NULL) break; len = strlen(line); @@ -209,39 +113,50 @@ static int net_idmap_restore(int argc, const char **argv) if ( (len > 0) && (line[len-1] == '\n') ) line[len-1] = '\0'; - snprintf(fmt_string1, sizeof(fmt_string1), "GID %%ul %%%us", FSTRING_LEN); - snprintf(fmt_string2, sizeof(fmt_string2), "UID %%ul %%%us", FSTRING_LEN); - - if (sscanf(line, fmt_string1, &idval, sid_string) == 2) { - type = ID_GROUPID; - id.gid = (gid_t)idval; - } else if (sscanf(line, fmt_string2, &idval, sid_string) == 2) { - type = ID_USERID; - id.uid = (uid_t)idval; + if (sscanf(line, "GID %lu %128s", &idval, sid_string) == 2) { + map.xid.type = ID_TYPE_GID; + map.xid.id = idval; + } else if (sscanf(line, "UID %lu %128s", &idval, sid_string) == 2) { + map.xid.type = ID_TYPE_UID; + map.xid.id = idval; + } else if (sscanf(line, "USER HWM %lu", &idval) == 1) { + /* set uid hwm */ + if (! winbind_set_uid_hwm(idval)) { + d_fprintf(stderr, "Could not set USER HWM\n"); + } + continue; + } else if (sscanf(line, "GROUP HWM %lu", &idval) == 1) { + /* set gid hwm */ + if (! winbind_set_gid_hwm(idval)) { + d_fprintf(stderr, "Could not set GROUP HWM\n"); + } + continue; } else { - d_printf("ignoring invalid line [%s]\n", line); + d_fprintf(stderr, "ignoring invalid line [%s]\n", line); continue; } if (!string_to_sid(&sid, sid_string)) { - d_printf("ignoring invalid sid [%s]\n", sid_string); + d_fprintf(stderr, "ignoring invalid sid [%s]\n", sid_string); continue; } + map.sid = &sid; - if (!NT_STATUS_IS_OK(idmap_set_mapping(&sid, id, type))) { + if (!winbind_set_mapping(&map)) { d_fprintf(stderr, "Could not set mapping of %s %lu to sid %s\n", - (type == ID_GROUPID) ? "GID" : "UID", - (type == ID_GROUPID) ? (unsigned long)id.gid: - (unsigned long)id.uid, - sid_string_static(&sid)); + (map.xid.type == ID_TYPE_GID) ? "GID" : "UID", + (unsigned long)map.xid.id, sid_string_static(map.sid)); continue; } - + } - idmap_close(); + if (input != stdin) { + fclose(input); + } - return NT_STATUS_IS_OK(net_idmap_fixup_hwm()) ? 0 : -1; + talloc_free(ctx); + return 0; } /*********************************************************** @@ -249,62 +164,122 @@ static int net_idmap_restore(int argc, const char **argv) **********************************************************/ static int net_idmap_delete(int argc, const char **argv) { - TDB_CONTEXT *idmap_tdb; - TDB_DATA key, data; - fstring sid; - - if (argc != 2) - return net_help_idmap(argc, argv); + d_printf("Not Implemented yet\n"); + return -1; +} - idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDWR, 0); +static int net_idmap_set(int argc, const char **argv) +{ + d_printf("Not Implemented yet\n"); + return -1; +} +BOOL idmap_store_secret(const char *backend, bool alloc, + const char *domain, const char *identity, + const char *secret) +{ + char *tmp; + int r; + BOOL ret; - if (idmap_tdb == NULL) { - d_fprintf(stderr, "Could not open idmap: %s\n", argv[0]); - return -1; + if (alloc) { + r = asprintf(&tmp, "IDMAP_ALLOC_%s", backend); + } else { + r = asprintf(&tmp, "IDMAP_%s_%s", backend, domain); } - fstrcpy(sid, argv[1]); + if (r < 0) return false; - if (strncmp(sid, "S-1-5-", strlen("S-1-5-")) != 0) { - d_fprintf(stderr, "Can only delete SIDs, %s is does not start with " - "S-1-5-\n", sid); - return -1; + strupper_m(tmp); /* make sure the key is case insensitive */ + ret = secrets_store_generic(tmp, identity, secret); + + free(tmp); + return ret; +} + + +static int net_idmap_secret(int argc, const char **argv) +{ + TALLOC_CTX *ctx; + const char *secret; + const char *dn; + char *domain; + char *backend; + char *opt = NULL; + BOOL ret; + + if (argc != 2) { + return net_help_idmap(argc, argv); } - key.dptr = sid; - key.dsize = strlen(key.dptr)+1; + secret = argv[1]; - data = tdb_fetch(idmap_tdb, key); + ctx = talloc_new(NULL); + ALLOC_CHECK(ctx); - if (data.dptr == NULL) { - d_fprintf(stderr, "Could not find sid %s\n", argv[1]); - return -1; + if (strcmp(argv[0], "alloc") == 0) { + domain = NULL; + backend = lp_idmap_alloc_backend(); + } else { + domain = talloc_strdup(ctx, argv[0]); + ALLOC_CHECK(domain); + + opt = talloc_asprintf(ctx, "idmap config %s", domain); + ALLOC_CHECK(opt); + + backend = talloc_strdup(ctx, lp_parm_const_string(-1, opt, "backend", "tdb")); + ALLOC_CHECK(backend); } - if (tdb_delete(idmap_tdb, key) != 0) { - d_fprintf(stderr, "Could not delete key %s\n", argv[1]); + if ( ( ! backend) || ( ! strequal(backend, "ldap"))) { + d_fprintf(stderr, "The only currently supported backend is LDAP\n"); + talloc_free(ctx); return -1; } - if (tdb_delete(idmap_tdb, data) != 0) { - d_fprintf(stderr, "Could not delete key %s\n", data.dptr); + if (domain) { + + dn = lp_parm_const_string(-1, opt, "ldap_user_dn", NULL); + if ( ! dn) { + d_fprintf(stderr, "Missing ldap_user_dn option for domain %s\n", domain); + talloc_free(ctx); + return -1; + } + + ret = idmap_store_secret("ldap", false, domain, dn, secret); + } else { + dn = lp_parm_const_string(-1, "idmap alloc config", "ldap_user_dn", NULL); + if ( ! dn) { + d_fprintf(stderr, "Missing ldap_user_dn option for alloc backend\n"); + talloc_free(ctx); + return -1; + } + + ret = idmap_store_secret("ldap", true, NULL, dn, secret); + } + + if ( ! ret) { + d_fprintf(stderr, "Failed to store secret\n"); + talloc_free(ctx); return -1; } + d_printf("Secret stored\n"); return 0; } - int net_help_idmap(int argc, const char **argv) { - d_printf("net idmap dump "\ - "\n Dump current id mapping\n"); + d_printf("net idmap dump \n"\ + " Dump current id mapping\n"); - d_printf("net idmap restore"\ - "\n Restore entries from stdin to current local idmap\n"); + d_printf("net idmap restore\n"\ + " Restore entries from stdin\n"); /* Deliberately *not* document net idmap delete */ + d_printf("net idmap secret |alloc \n"\ + " Set the secret for the specified DOMAIN (or the alloc module)\n"); + return -1; } @@ -316,7 +291,9 @@ int net_idmap(int argc, const char **argv) struct functable func[] = { {"dump", net_idmap_dump}, {"restore", net_idmap_restore}, + {"setmap", net_idmap_set }, {"delete", net_idmap_delete}, + {"secret", net_idmap_secret}, {"help", net_help_idmap}, {NULL, NULL} }; -- cgit From 53637791023ec35f669244d7ea24ceaf6cf30d18 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 26 Jun 2007 19:15:26 +0000 Subject: r23612: Revert 'net idmap dump' to the 3.0.24 behaviour. (This used to be commit 56a32f217a183f956ad1c57a62d61a43646aa391) --- source3/utils/net_idmap.c | 63 ++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 31 deletions(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index dd16c4b02d..d4d2c931b8 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -28,50 +28,51 @@ } } while(0) /*********************************************************** - Dump the current idmap + Helper function for net_idmap_dump. Dump one entry. **********************************************************/ -static int net_idmap_dump(int argc, const char **argv) +static int net_idmap_dump_one_entry(TDB_CONTEXT *tdb, + TDB_DATA key, + TDB_DATA data, + void *unused) { - TALLOC_CTX *ctx; - char *filename; - - if (argc != 1) { - return net_help_idmap(argc, argv); + if (strcmp((char *)key.dptr, "USER HWM") == 0) { + printf("USER HWM %d\n", IVAL(data.dptr,0)); + return 0; } - if (! winbind_ping()) { - d_fprintf(stderr, "To use net idmap Winbindd must be running.\n"); - return -1; + if (strcmp((char *)key.dptr, "GROUP HWM") == 0) { + printf("GROUP HWM %d\n", IVAL(data.dptr,0)); + return 0; } - ctx = talloc_new(NULL); - ALLOC_CHECK(ctx); + if (strncmp((char *)key.dptr, "S-", 2) != 0) + return 0; - filename = talloc_strdup(ctx, argv[0]); - ALLOC_CHECK(filename); + printf("%s %s\n", data.dptr, key.dptr); + return 0; +} - /* filename must be absolute */ - if (*filename != '/') { - char path[4096]; - - filename = getcwd(path, 4095); - if ( ! filename) { - d_fprintf(stderr, "Failed to obtain full output file path"); - talloc_free(ctx); - return -1; - } +/*********************************************************** + Dump the current idmap + **********************************************************/ +static int net_idmap_dump(int argc, const char **argv) +{ + TDB_CONTEXT *idmap_tdb; - filename = talloc_asprintf(ctx, "%s/%s", path, argv[0]); - ALLOC_CHECK(filename); - } + if ( argc != 1 ) + return net_help_idmap( argc, argv ); - if ( ! winbind_idmap_dump_maps(ctx, filename)) { - d_fprintf(stderr, "Failed to obtain idmap data from winbindd\n"); - talloc_free(ctx); + idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDONLY, 0); + + if (idmap_tdb == NULL) { + d_fprintf(stderr, "Could not open idmap: %s\n", argv[0]); return -1; } - talloc_free(ctx); + tdb_traverse(idmap_tdb, net_idmap_dump_one_entry, NULL); + + tdb_close(idmap_tdb); + return 0; } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/utils/net_idmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index d4d2c931b8..1b9db0abac 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -5,7 +5,7 @@ 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 2 of the License, or + 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, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/utils/net_idmap.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 1b9db0abac..679c3d6476 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -14,8 +14,7 @@ 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + along with this program. If not, see . */ #include "includes.h" #include "utils/net.h" -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/utils/net_idmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 679c3d6476..052566fa73 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -173,13 +173,13 @@ static int net_idmap_set(int argc, const char **argv) d_printf("Not Implemented yet\n"); return -1; } -BOOL idmap_store_secret(const char *backend, bool alloc, +bool idmap_store_secret(const char *backend, bool alloc, const char *domain, const char *identity, const char *secret) { char *tmp; int r; - BOOL ret; + bool ret; if (alloc) { r = asprintf(&tmp, "IDMAP_ALLOC_%s", backend); @@ -205,7 +205,7 @@ static int net_idmap_secret(int argc, const char **argv) char *domain; char *backend; char *opt = NULL; - BOOL ret; + bool ret; if (argc != 2) { return net_help_idmap(argc, argv); -- cgit From 7b01537679d4d4f1408634fe63c64c144f9d9519 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 15 Dec 2007 21:53:26 +0100 Subject: Replace sid_string_static with sid_string_tos In utils/ I was a bit lazy... (This used to be commit 60e830b0f4571bd5d9039f2edd199534f2a4c341) --- source3/utils/net_idmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 052566fa73..2a060d2f49 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -145,7 +145,8 @@ static int net_idmap_restore(int argc, const char **argv) if (!winbind_set_mapping(&map)) { d_fprintf(stderr, "Could not set mapping of %s %lu to sid %s\n", (map.xid.type == ID_TYPE_GID) ? "GID" : "UID", - (unsigned long)map.xid.id, sid_string_static(map.sid)); + (unsigned long)map.xid.id, + sid_string_tos(map.sid)); continue; } -- cgit From c82e84862896b9753e63ca5a887639ee6c0137f3 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 17 Mar 2008 13:51:50 +0100 Subject: Add "net idmap aclmapset" This is a merge from 3-0-ctdb that goes along with 1daad835, the option nfs4:sidmap option (This used to be commit f5e26d28be6581149bed0b599c38b82d1a44444e) --- source3/utils/net_idmap.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 2a060d2f49..7ac2a82f6e 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -284,6 +284,70 @@ int net_help_idmap(int argc, const char **argv) return -1; } +static int net_idmap_aclmapset(int argc, const char **argv) +{ + TALLOC_CTX *mem_ctx; + int result = -1; + DOM_SID src_sid, dst_sid; + char *src, *dst; + struct db_context *db; + struct db_record *rec; + NTSTATUS status; + + if (argc != 3) { + d_fprintf(stderr, "usage: net idmap aclmapset " + " \n"); + return -1; + } + + if (!(mem_ctx = talloc_init("net idmap aclmapset"))) { + d_fprintf(stderr, "talloc_init failed\n"); + return -1; + } + + if (!(db = db_open(mem_ctx, argv[0], 0, TDB_DEFAULT, + O_RDWR|O_CREAT, 0600))) { + d_fprintf(stderr, "db_open failed: %s\n", strerror(errno)); + goto fail; + } + + if (!string_to_sid(&src_sid, argv[1])) { + d_fprintf(stderr, "%s is not a valid sid\n", argv[1]); + goto fail; + } + + if (!string_to_sid(&dst_sid, argv[2])) { + d_fprintf(stderr, "%s is not a valid sid\n", argv[2]); + goto fail; + } + + if (!(src = sid_string_talloc(mem_ctx, &src_sid)) + || !(dst = sid_string_talloc(mem_ctx, &dst_sid))) { + d_fprintf(stderr, "talloc_strdup failed\n"); + goto fail; + } + + if (!(rec = db->fetch_locked( + db, mem_ctx, string_term_tdb_data(src)))) { + d_fprintf(stderr, "could not fetch db record\n"); + goto fail; + } + + status = rec->store(rec, string_term_tdb_data(dst), 0); + TALLOC_FREE(rec); + + if (!NT_STATUS_IS_OK(status)) { + d_fprintf(stderr, "could not store record: %s\n", + nt_errstr(status)); + goto fail; + } + + result = 0; +fail: + TALLOC_FREE(mem_ctx); + return result; +} + /*********************************************************** Look at the current idmap **********************************************************/ @@ -295,6 +359,7 @@ int net_idmap(int argc, const char **argv) {"setmap", net_idmap_set }, {"delete", net_idmap_delete}, {"secret", net_idmap_secret}, + {"aclmapset", net_idmap_aclmapset}, {"help", net_help_idmap}, {NULL, NULL} }; -- cgit From dec89a93229b14563b1c768097271169616eeae2 Mon Sep 17 00:00:00 2001 From: Karolin Seeger Date: Tue, 25 Mar 2008 12:00:42 +0100 Subject: Fix usage message for 'net idmap dump'. Karolin (This used to be commit c967b62dd3c924419fa4a72aa2143d6bef959d18) --- source3/utils/net_idmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 7ac2a82f6e..f0c3e56ef3 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -270,7 +270,7 @@ static int net_idmap_secret(int argc, const char **argv) int net_help_idmap(int argc, const char **argv) { - d_printf("net idmap dump \n"\ + d_printf("net idmap dump \n"\ " Dump current id mapping\n"); d_printf("net idmap restore\n"\ -- cgit From 08591d0095b80080d42b7292073ad59c58586155 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 11 Apr 2008 12:00:29 +0200 Subject: net_idmap: use wbcSet[U|G]idMapping() and wbcSet[U|G]idHwm() functions metze (This used to be commit dc9a3f8db0af03b4e8223068857092fcaff404f2) --- source3/utils/net_idmap.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index f0c3e56ef3..b0024895f7 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -101,9 +101,10 @@ static int net_idmap_restore(int argc, const char **argv) while (!feof(input)) { char line[128], sid_string[128]; int len; - DOM_SID sid; - struct id_map map; + struct wbcDomainSid sid; + enum id_type type = ID_TYPE_NOT_SPECIFIED; unsigned long idval; + wbcErr wbc_status; if (fgets(line, 127, input) == NULL) break; @@ -114,21 +115,23 @@ static int net_idmap_restore(int argc, const char **argv) line[len-1] = '\0'; if (sscanf(line, "GID %lu %128s", &idval, sid_string) == 2) { - map.xid.type = ID_TYPE_GID; - map.xid.id = idval; + type = ID_TYPE_GID; } else if (sscanf(line, "UID %lu %128s", &idval, sid_string) == 2) { - map.xid.type = ID_TYPE_UID; - map.xid.id = idval; + type = ID_TYPE_UID; } else if (sscanf(line, "USER HWM %lu", &idval) == 1) { /* set uid hwm */ - if (! winbind_set_uid_hwm(idval)) { - d_fprintf(stderr, "Could not set USER HWM\n"); + wbc_status = wbcSetUidHwm(idval); + if (!WBC_ERROR_IS_OK(wbc_status)) { + d_fprintf(stderr, "Could not set USER HWM: %s\n", + wbcErrorString(wbc_status)); } continue; } else if (sscanf(line, "GROUP HWM %lu", &idval) == 1) { /* set gid hwm */ - if (! winbind_set_gid_hwm(idval)) { - d_fprintf(stderr, "Could not set GROUP HWM\n"); + wbc_status = wbcSetGidHwm(idval); + if (!WBC_ERROR_IS_OK(wbc_status)) { + d_fprintf(stderr, "Could not set GROUP HWM: %s\n", + wbcErrorString(wbc_status)); } continue; } else { @@ -136,20 +139,25 @@ static int net_idmap_restore(int argc, const char **argv) continue; } - if (!string_to_sid(&sid, sid_string)) { - d_fprintf(stderr, "ignoring invalid sid [%s]\n", sid_string); + wbc_status = wbcStringToSid(sid_string, &sid); + if (!WBC_ERROR_IS_OK(wbc_status)) { + d_fprintf(stderr, "ignoring invalid sid [%s]: %s\n", + sid_string, wbcErrorString(wbc_status)); continue; } - map.sid = &sid; - if (!winbind_set_mapping(&map)) { - d_fprintf(stderr, "Could not set mapping of %s %lu to sid %s\n", - (map.xid.type == ID_TYPE_GID) ? "GID" : "UID", - (unsigned long)map.xid.id, - sid_string_tos(map.sid)); + if (type == ID_TYPE_UID) { + wbc_status = wbcSetUidMapping(idval, &sid); + } else { + wbc_status = wbcSetGidMapping(idval, &sid); + } + if (!WBC_ERROR_IS_OK(wbc_status)) { + d_fprintf(stderr, "Could not set mapping of %s %lu to sid %s: %s\n", + (type == ID_TYPE_GID) ? "GID" : "UID", + idval, sid_string, + wbcErrorString(wbc_status)); continue; } - } if (input != stdin) { -- cgit From f5769109447d8da0f09b102d444a816ad97a00dc Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Fri, 9 May 2008 23:22:12 +0200 Subject: net: Remove globals (This used to be commit 1e9319cf88b65a2a8d4f5099a1fe5297e405ed2e) --- source3/utils/net_idmap.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index b0024895f7..74992933ba 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -14,7 +14,8 @@ 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 . */ + along with this program. If not, see . +*/ #include "includes.h" #include "utils/net.h" @@ -54,12 +55,12 @@ static int net_idmap_dump_one_entry(TDB_CONTEXT *tdb, /*********************************************************** Dump the current idmap **********************************************************/ -static int net_idmap_dump(int argc, const char **argv) +static int net_idmap_dump(struct net_context *c, int argc, const char **argv) { TDB_CONTEXT *idmap_tdb; if ( argc != 1 ) - return net_help_idmap( argc, argv ); + return net_help_idmap(c, argc, argv ); idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDONLY, 0); @@ -79,7 +80,7 @@ static int net_idmap_dump(int argc, const char **argv) Write entries from stdin to current local idmap **********************************************************/ -static int net_idmap_restore(int argc, const char **argv) +static int net_idmap_restore(struct net_context *c, int argc, const char **argv) { TALLOC_CTX *ctx; FILE *input; @@ -171,13 +172,13 @@ static int net_idmap_restore(int argc, const char **argv) /*********************************************************** Delete a SID mapping from a winbindd_idmap.tdb **********************************************************/ -static int net_idmap_delete(int argc, const char **argv) +static int net_idmap_delete(struct net_context *c, int argc, const char **argv) { d_printf("Not Implemented yet\n"); return -1; } -static int net_idmap_set(int argc, const char **argv) +static int net_idmap_set(struct net_context *c, int argc, const char **argv) { d_printf("Not Implemented yet\n"); return -1; @@ -206,7 +207,7 @@ bool idmap_store_secret(const char *backend, bool alloc, } -static int net_idmap_secret(int argc, const char **argv) +static int net_idmap_secret(struct net_context *c, int argc, const char **argv) { TALLOC_CTX *ctx; const char *secret; @@ -217,7 +218,7 @@ static int net_idmap_secret(int argc, const char **argv) bool ret; if (argc != 2) { - return net_help_idmap(argc, argv); + return net_help_idmap(c, argc, argv); } secret = argv[1]; @@ -276,7 +277,7 @@ static int net_idmap_secret(int argc, const char **argv) return 0; } -int net_help_idmap(int argc, const char **argv) +int net_help_idmap(struct net_context *c, int argc, const char **argv) { d_printf("net idmap dump \n"\ " Dump current id mapping\n"); @@ -292,7 +293,7 @@ int net_help_idmap(int argc, const char **argv) return -1; } -static int net_idmap_aclmapset(int argc, const char **argv) +static int net_idmap_aclmapset(struct net_context *c, int argc, const char **argv) { TALLOC_CTX *mem_ctx; int result = -1; @@ -359,7 +360,7 @@ fail: /*********************************************************** Look at the current idmap **********************************************************/ -int net_idmap(int argc, const char **argv) +int net_idmap(struct net_context *c, int argc, const char **argv) { struct functable func[] = { {"dump", net_idmap_dump}, @@ -372,7 +373,7 @@ int net_idmap(int argc, const char **argv) {NULL, NULL} }; - return net_run_function(argc, argv, func, net_help_idmap); + return net_run_function(c, argc, argv, func, net_help_idmap); } -- cgit From 4206d9754486d2c1e18217cbcdbaad8f31f5244b Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Thu, 8 May 2008 11:23:38 +0200 Subject: net: more whitespace cleanup (This used to be commit ef0184d580500734fc7af51e1c790b075180a3d0) --- source3/utils/net_idmap.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 74992933ba..f3d0c30a4d 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -1,18 +1,18 @@ -/* - Samba Unix/Linux SMB client library - Distributed SMB/CIFS Server Management Utility +/* + Samba Unix/Linux SMB client library + Distributed SMB/CIFS Server Management Utility Copyright (C) 2003 Andrew Bartlett (abartlet@samba.org) 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 . */ -- cgit From 6468d3671696702e74ef20f11493417a6a8e8ab5 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Mon, 19 May 2008 16:10:07 +0200 Subject: net: Make "net idmap" use functable3 (This used to be commit 9c88b16bebd0917a6a4e8d0e5fcc64c3581ceff5) --- source3/utils/net_idmap.c | 98 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 80 insertions(+), 18 deletions(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index f3d0c30a4d..9fab29c9a5 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -59,8 +59,13 @@ static int net_idmap_dump(struct net_context *c, int argc, const char **argv) { TDB_CONTEXT *idmap_tdb; - if ( argc != 1 ) - return net_help_idmap(c, argc, argv ); + if ( argc != 1 || c->display_usage) { + d_printf("Usage:\n" + "net idmap dump \n" + " Dump current ID mapping.\n" + " inputfile\tTDB file to read mappings from.\n"); + return c->display_usage?0:-1; + } idmap_tdb = tdb_open_log(argv[0], 0, TDB_DEFAULT, O_RDONLY, 0); @@ -85,6 +90,15 @@ static int net_idmap_restore(struct net_context *c, int argc, const char **argv) TALLOC_CTX *ctx; FILE *input; + if (c->display_usage) { + d_printf("Usage:\n" + "net idmap restore [inputfile]\n" + " Restore ID mappings from file\n" + " inputfile\tFile to load ID mappings from. If not " + "given, load data from stdin.\n"); + return 0; + } + if (! winbind_ping()) { d_fprintf(stderr, "To use net idmap Winbindd must be running.\n"); return -1; @@ -217,8 +231,15 @@ static int net_idmap_secret(struct net_context *c, int argc, const char **argv) char *opt = NULL; bool ret; - if (argc != 2) { - return net_help_idmap(c, argc, argv); + if (argc != 2 || c->display_usage) { + d_printf("Usage:\n" + "net idmap secret {|alloc} \n" + " Set the secret for the specified domain " + "(or alloc module)\n" + " DOMAIN\tDomain to set secret for.\n" + " alloc\tSet secret for the alloc module\n" + " secret\tNew secret to set.\n"); + return c->display_usage?0:-1; } secret = argv[1]; @@ -279,15 +300,15 @@ static int net_idmap_secret(struct net_context *c, int argc, const char **argv) int net_help_idmap(struct net_context *c, int argc, const char **argv) { - d_printf("net idmap dump \n"\ + d_printf("net idmap dump \n" " Dump current id mapping\n"); - d_printf("net idmap restore\n"\ + d_printf("net idmap restore\n" " Restore entries from stdin\n"); /* Deliberately *not* document net idmap delete */ - d_printf("net idmap secret |alloc \n"\ + d_printf("net idmap secret |alloc \n" " Set the secret for the specified DOMAIN (or the alloc module)\n"); return -1; @@ -303,7 +324,7 @@ static int net_idmap_aclmapset(struct net_context *c, int argc, const char **arg struct db_record *rec; NTSTATUS status; - if (argc != 3) { + if (argc != 3 || c->display_usage) { d_fprintf(stderr, "usage: net idmap aclmapset " " \n"); return -1; @@ -362,18 +383,59 @@ fail: **********************************************************/ int net_idmap(struct net_context *c, int argc, const char **argv) { - struct functable func[] = { - {"dump", net_idmap_dump}, - {"restore", net_idmap_restore}, - {"setmap", net_idmap_set }, - {"delete", net_idmap_delete}, - {"secret", net_idmap_secret}, - {"aclmapset", net_idmap_aclmapset}, - {"help", net_help_idmap}, - {NULL, NULL} + struct functable3 func[] = { + { + "dump", + net_idmap_dump, + NET_TRANSPORT_LOCAL, + "Dump the current ID mappings", + "net idmap dump\n" + " Dump the current ID mappings" + }, + { + "restore", + net_idmap_restore, + NET_TRANSPORT_LOCAL, + "Restore entries from stdin", + "net idmap restore\n" + " Restore entries from stdin" + }, + { + "setmap", + net_idmap_set, + NET_TRANSPORT_LOCAL, + "Not implemented yet", + "net idmap setmap\n" + " Not implemented yet" + }, + { + "delete", + net_idmap_delete, + NET_TRANSPORT_LOCAL, + "Not implemented yet", + "net idmap delete\n" + " Not implemented yet" + }, + { + "secret", + net_idmap_secret, + NET_TRANSPORT_LOCAL, + "Set secret for specified domain", + "net idmap secret {|alloc} \n" + " Set secret for specified domain or alloc module" + }, + { + "aclmapset", + net_idmap_aclmapset, + NET_TRANSPORT_LOCAL, + "Set acl map", + "net idmap aclmapset\n" + " Set acl map" + }, + {NULL, NULL, 0, NULL, NULL} }; - return net_run_function(c, argc, argv, func, net_help_idmap); + return net_run_function3(c, argc, argv, "net idmap", func); } -- cgit From 255bdb26025a5025bc60637dd924f6ec71c49ee5 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Sat, 7 Jun 2008 02:25:08 +0200 Subject: net: Rename functable3 to functable, get rid of old functables (This used to be commit bb7c5fc4ec77db4073d3beccf12af12910b6bd07) --- source3/utils/net_idmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_idmap.c') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 9fab29c9a5..bd363922f6 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -383,7 +383,7 @@ fail: **********************************************************/ int net_idmap(struct net_context *c, int argc, const char **argv) { - struct functable3 func[] = { + struct functable func[] = { { "dump", net_idmap_dump, @@ -435,7 +435,7 @@ int net_idmap(struct net_context *c, int argc, const char **argv) {NULL, NULL, 0, NULL, NULL} }; - return net_run_function3(c, argc, argv, "net idmap", func); + return net_run_function(c, argc, argv, "net idmap", func); } -- cgit