svn commit: samba r14580 - branches/SAMBA_3_0/source/utils trunk/source/utils

jerry at samba.org jerry at samba.org
Mon Mar 20 12:14:07 GMT 2006


Author: jerry
Date: 2006-03-20 12:14:07 +0000 (Mon, 20 Mar 2006)
New Revision: 14580

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=14580

Log:
add 'net sam createbuiltingroup' to map BUILTIN local groups to a gid



Modified:
   branches/SAMBA_3_0/source/utils/net_sam.c
   trunk/source/utils/net_sam.c


Changeset:
Modified: branches/SAMBA_3_0/source/utils/net_sam.c
===================================================================
--- branches/SAMBA_3_0/source/utils/net_sam.c	2006-03-20 11:32:08 UTC (rev 14579)
+++ branches/SAMBA_3_0/source/utils/net_sam.c	2006-03-20 12:14:07 UTC (rev 14580)
@@ -455,6 +455,63 @@
 }
 
 /*
+ * Create a local group
+ */
+
+static int net_sam_createbuiltingroup(int argc, const char **argv)
+{
+	NTSTATUS status;
+	uint32 rid;
+	TALLOC_CTX *ctx;
+	enum SID_NAME_USE type;
+	fstring groupname;
+	DOM_SID sid;
+
+	if (argc != 1) {
+		d_fprintf(stderr, "usage: net sam createbuiltingroup <name>\n");
+		return -1;
+	}
+
+	if (!winbind_ping()) {
+		d_fprintf(stderr, "winbind seems not to run. createlocalgroup "
+			  "only works when winbind runs.\n");
+		return -1;
+	}
+
+	if ( (ctx = talloc_init("net_sam_createbuiltingroup")) == NULL ) {
+		d_fprintf( stderr, "Memory allocation error\n");
+		return -1;
+	}
+	
+	/* validate the name and get the group */
+	
+	fstrcpy( groupname, "BUILTIN\\" );
+	fstrcat( groupname, argv[0] );
+	
+	if ( !lookup_name(ctx, groupname, LOOKUP_NAME_ALL, NULL, NULL, &sid, &type)) {
+		d_fprintf(stderr, "%s is not a BUILTIN group\n", argv[0]);
+		return -1;
+	}
+	
+	if ( !sid_peek_rid( &sid, &rid ) ) {
+		d_fprintf(stderr, "Failed to get RID for %s\n", argv[0]);
+		return -1;
+	}
+
+	status = pdb_create_builtin_alias( rid );
+
+	if (!NT_STATUS_IS_OK(status)) {
+		d_fprintf(stderr, "Creating %s failed with %s\n",
+			  argv[0], nt_errstr(status));
+		return -1;
+	}
+
+	d_printf("Created BUILTIN group %s with RID %d\n", argv[0], rid);
+
+	return 0;
+}
+
+/*
  * Add a group member
  */
 
@@ -1140,6 +1197,8 @@
 int net_sam(int argc, const char **argv)
 {
 	struct functable2 func[] = {
+		{ "createbuiltingroup", net_sam_createbuiltingroup,
+		  "Create a new BUILTIN group" },
 		{ "createlocalgroup", net_sam_createlocalgroup,
 		  "Create a new local group" },
 		{ "mapunixgroup", net_sam_mapunixgroup,

Modified: trunk/source/utils/net_sam.c
===================================================================
--- trunk/source/utils/net_sam.c	2006-03-20 11:32:08 UTC (rev 14579)
+++ trunk/source/utils/net_sam.c	2006-03-20 12:14:07 UTC (rev 14580)
@@ -455,6 +455,63 @@
 }
 
 /*
+ * Create a local group
+ */
+
+static int net_sam_createbuiltingroup(int argc, const char **argv)
+{
+	NTSTATUS status;
+	uint32 rid;
+	TALLOC_CTX *ctx;
+	enum SID_NAME_USE type;
+	fstring groupname;
+	DOM_SID sid;
+
+	if (argc != 1) {
+		d_fprintf(stderr, "usage: net sam createbuiltingroup <name>\n");
+		return -1;
+	}
+
+	if (!winbind_ping()) {
+		d_fprintf(stderr, "winbind seems not to run. createlocalgroup "
+			  "only works when winbind runs.\n");
+		return -1;
+	}
+
+	if ( (ctx = talloc_init("net_sam_createbuiltingroup")) == NULL ) {
+		d_fprintf( stderr, "Memory allocation error\n");
+		return -1;
+	}
+	
+	/* validate the name and get the group */
+	
+	fstrcpy( groupname, "BUILTIN\\" );
+	fstrcat( groupname, argv[0] );
+	
+	if ( !lookup_name(ctx, groupname, LOOKUP_NAME_ALL, NULL, NULL, &sid, &type)) {
+		d_fprintf(stderr, "%s is not a BUILTIN group\n", argv[0]);
+		return -1;
+	}
+	
+	if ( !sid_peek_rid( &sid, &rid ) ) {
+		d_fprintf(stderr, "Failed to get RID for %s\n", argv[0]);
+		return -1;
+	}
+
+	status = pdb_create_builtin_alias( rid );
+
+	if (!NT_STATUS_IS_OK(status)) {
+		d_fprintf(stderr, "Creating %s failed with %s\n",
+			  argv[0], nt_errstr(status));
+		return -1;
+	}
+
+	d_printf("Created BUILTIN group %s with RID %d\n", argv[0], rid);
+
+	return 0;
+}
+
+/*
  * Add a group member
  */
 
@@ -1141,6 +1198,8 @@
 int net_sam(int argc, const char **argv)
 {
 	struct functable2 func[] = {
+		{ "createbuiltingroup", net_sam_createbuiltingroup,
+		  "Create a new BUILTIN group" },
 		{ "createlocalgroup", net_sam_createlocalgroup,
 		  "Create a new local group" },
 		{ "mapunixgroup", net_sam_mapunixgroup,



More information about the samba-cvs mailing list