2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Jean François Micouleau 1998-2001.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 static TDB_CONTEXT
*tdb
; /* used for driver files */
26 #define DATABASE_VERSION_V1 1 /* native byte format. */
27 #define DATABASE_VERSION_V2 2 /* le format. */
29 #define GROUP_PREFIX "UNIXGROUP/"
32 {SE_PRIV_NONE
, "no_privs", "No privilege" }, /* this one MUST be first */
33 {SE_PRIV_ADD_MACHINES
, "SeMachineAccountPrivilege", "Add workstations to the domain" },
34 {SE_PRIV_SEC_PRIV
, "SeSecurityPrivilege", "Manage the audit logs" },
35 {SE_PRIV_TAKE_OWNER
, "SeTakeOwnershipPrivilege", "Take ownership of file" },
36 {SE_PRIV_ADD_USERS
, "SaAddUsers", "Add users to the domain - Samba" },
37 {SE_PRIV_PRINT_OPERATOR
, "SaPrintOp", "Add or remove printers - Samba" },
38 {SE_PRIV_ALL
, "SaAllPrivs", "all privileges" }
42 /****************************************************************************
43 dump the mapping group mapping to a text file
44 ****************************************************************************/
45 char *decode_sid_name_use(fstring group
, enum SID_NAME_USE name_use
)
47 static fstring group_type
;
51 fstrcpy(group_type
,"User");
53 case SID_NAME_DOM_GRP
:
54 fstrcpy(group_type
,"Domain group");
57 fstrcpy(group_type
,"Domain");
60 fstrcpy(group_type
,"Local group");
62 case SID_NAME_WKN_GRP
:
63 fstrcpy(group_type
,"Builtin group");
65 case SID_NAME_DELETED
:
66 fstrcpy(group_type
,"Deleted");
68 case SID_NAME_INVALID
:
69 fstrcpy(group_type
,"Invalid");
71 case SID_NAME_UNKNOWN
:
73 fstrcpy(group_type
,"Unknown type");
77 fstrcpy(group
, group_type
);
81 /****************************************************************************
82 initialise first time the mapping list - called from init_group_mapping()
83 ****************************************************************************/
84 static BOOL
default_group_mapping(void)
93 /* Add the Wellknown groups */
95 add_initial_entry(-1, "S-1-5-32-544", SID_NAME_WKN_GRP
, "Administrators", "");
96 add_initial_entry(-1, "S-1-5-32-545", SID_NAME_WKN_GRP
, "Users", "");
97 add_initial_entry(-1, "S-1-5-32-546", SID_NAME_WKN_GRP
, "Guests", "");
98 add_initial_entry(-1, "S-1-5-32-547", SID_NAME_WKN_GRP
, "Power Users", "");
99 add_initial_entry(-1, "S-1-5-32-548", SID_NAME_WKN_GRP
, "Account Operators", "");
100 add_initial_entry(-1, "S-1-5-32-549", SID_NAME_WKN_GRP
, "System Operators", "");
101 add_initial_entry(-1, "S-1-5-32-550", SID_NAME_WKN_GRP
, "Print Operators", "");
102 add_initial_entry(-1, "S-1-5-32-551", SID_NAME_WKN_GRP
, "Backup Operators", "");
103 add_initial_entry(-1, "S-1-5-32-552", SID_NAME_WKN_GRP
, "Replicators", "");
105 /* Add the defaults domain groups */
107 sid_copy(&sid_admins
, get_global_sam_sid());
108 sid_append_rid(&sid_admins
, DOMAIN_GROUP_RID_ADMINS
);
109 sid_to_string(str_admins
, &sid_admins
);
110 add_initial_entry(-1, str_admins
, SID_NAME_DOM_GRP
, "Domain Admins", "");
112 sid_copy(&sid_users
, get_global_sam_sid());
113 sid_append_rid(&sid_users
, DOMAIN_GROUP_RID_USERS
);
114 sid_to_string(str_users
, &sid_users
);
115 add_initial_entry(-1, str_users
, SID_NAME_DOM_GRP
, "Domain Users", "");
117 sid_copy(&sid_guests
, get_global_sam_sid());
118 sid_append_rid(&sid_guests
, DOMAIN_GROUP_RID_GUESTS
);
119 sid_to_string(str_guests
, &sid_guests
);
120 add_initial_entry(-1, str_guests
, SID_NAME_DOM_GRP
, "Domain Guests", "");
125 /****************************************************************************
126 Open the group mapping tdb.
127 ****************************************************************************/
129 static BOOL
init_group_mapping(void)
131 static pid_t local_pid
;
132 const char *vstring
= "INFO/version";
135 if (tdb
&& local_pid
== sys_getpid())
137 tdb
= tdb_open_log(lock_path("group_mapping.tdb"), 0, TDB_DEFAULT
, O_RDWR
|O_CREAT
, 0600);
139 DEBUG(0,("Failed to open group mapping database\n"));
143 local_pid
= sys_getpid();
145 /* handle a Samba upgrade */
146 tdb_lock_bystring(tdb
, vstring
, 0);
148 /* Cope with byte-reversed older versions of the db. */
149 vers_id
= tdb_fetch_int32(tdb
, vstring
);
150 if ((vers_id
== DATABASE_VERSION_V1
) || (IREV(vers_id
) == DATABASE_VERSION_V1
)) {
151 /* Written on a bigendian machine with old fetch_int code. Save as le. */
152 tdb_store_int32(tdb
, vstring
, DATABASE_VERSION_V2
);
153 vers_id
= DATABASE_VERSION_V2
;
156 if (vers_id
!= DATABASE_VERSION_V2
) {
157 tdb_traverse(tdb
, tdb_traverse_delete_fn
, NULL
);
158 tdb_store_int32(tdb
, vstring
, DATABASE_VERSION_V2
);
161 tdb_unlock_bystring(tdb
, vstring
);
163 /* write a list of default groups */
164 if(!default_group_mapping())
170 /****************************************************************************
171 ****************************************************************************/
172 static BOOL
add_mapping_entry(GROUP_MAP
*map
, int flag
)
176 fstring string_sid
="";
179 if(!init_group_mapping()) {
180 DEBUG(0,("failed to initialize group mapping"));
184 sid_to_string(string_sid
, &map
->sid
);
186 len
= tdb_pack(buf
, sizeof(buf
), "ddff",
187 map
->gid
, map
->sid_name_use
, map
->nt_name
, map
->comment
);
189 if (len
> sizeof(buf
))
192 slprintf(key
, sizeof(key
), "%s%s", GROUP_PREFIX
, string_sid
);
194 kbuf
.dsize
= strlen(key
)+1;
198 if (tdb_store(tdb
, kbuf
, dbuf
, flag
) != 0) return False
;
203 /****************************************************************************
204 initialise first time the mapping list
205 ****************************************************************************/
206 BOOL
add_initial_entry(gid_t gid
, const char *sid
, enum SID_NAME_USE sid_name_use
, const char *nt_name
, const char *comment
)
210 if(!init_group_mapping()) {
211 DEBUG(0,("failed to initialize group mapping"));
216 if (!string_to_sid(&map
.sid
, sid
)) {
217 DEBUG(0, ("string_to_sid failed: %s", sid
));
221 map
.sid_name_use
=sid_name_use
;
222 fstrcpy(map
.nt_name
, nt_name
);
223 fstrcpy(map
.comment
, comment
);
225 return pdb_add_group_mapping_entry(&map
);
228 /****************************************************************************
229 Return the sid and the type of the unix group.
230 ****************************************************************************/
232 static BOOL
get_group_map_from_sid(DOM_SID sid
, GROUP_MAP
*map
)
239 if(!init_group_mapping()) {
240 DEBUG(0,("failed to initialize group mapping"));
244 /* the key is the SID, retrieving is direct */
246 sid_to_string(string_sid
, &sid
);
247 slprintf(key
, sizeof(key
), "%s%s", GROUP_PREFIX
, string_sid
);
250 kbuf
.dsize
= strlen(key
)+1;
252 dbuf
= tdb_fetch(tdb
, kbuf
);
256 ret
= tdb_unpack(dbuf
.dptr
, dbuf
.dsize
, "ddff",
257 &map
->gid
, &map
->sid_name_use
, &map
->nt_name
, &map
->comment
);
259 SAFE_FREE(dbuf
.dptr
);
262 DEBUG(3,("get_group_map_from_sid: tdb_unpack failure\n"));
266 sid_copy(&map
->sid
, &sid
);
271 /****************************************************************************
272 Return the sid and the type of the unix group.
273 ****************************************************************************/
275 static BOOL
get_group_map_from_gid(gid_t gid
, GROUP_MAP
*map
)
277 TDB_DATA kbuf
, dbuf
, newkey
;
281 if(!init_group_mapping()) {
282 DEBUG(0,("failed to initialize group mapping"));
286 /* we need to enumerate the TDB to find the GID */
288 for (kbuf
= tdb_firstkey(tdb
);
290 newkey
= tdb_nextkey(tdb
, kbuf
), safe_free(kbuf
.dptr
), kbuf
=newkey
) {
292 if (strncmp(kbuf
.dptr
, GROUP_PREFIX
, strlen(GROUP_PREFIX
)) != 0) continue;
294 dbuf
= tdb_fetch(tdb
, kbuf
);
298 fstrcpy(string_sid
, kbuf
.dptr
+strlen(GROUP_PREFIX
));
300 string_to_sid(&map
->sid
, string_sid
);
302 ret
= tdb_unpack(dbuf
.dptr
, dbuf
.dsize
, "ddff",
303 &map
->gid
, &map
->sid_name_use
, &map
->nt_name
, &map
->comment
);
305 SAFE_FREE(dbuf
.dptr
);
308 DEBUG(3,("get_group_map_from_gid: tdb_unpack failure\n"));
313 SAFE_FREE(kbuf
.dptr
);
321 /****************************************************************************
322 Return the sid and the type of the unix group.
323 ****************************************************************************/
325 static BOOL
get_group_map_from_ntname(const char *name
, GROUP_MAP
*map
)
327 TDB_DATA kbuf
, dbuf
, newkey
;
331 if(!init_group_mapping()) {
332 DEBUG(0,("get_group_map_from_ntname:failed to initialize group mapping"));
336 /* we need to enumerate the TDB to find the name */
338 for (kbuf
= tdb_firstkey(tdb
);
340 newkey
= tdb_nextkey(tdb
, kbuf
), safe_free(kbuf
.dptr
), kbuf
=newkey
) {
342 if (strncmp(kbuf
.dptr
, GROUP_PREFIX
, strlen(GROUP_PREFIX
)) != 0) continue;
344 dbuf
= tdb_fetch(tdb
, kbuf
);
348 fstrcpy(string_sid
, kbuf
.dptr
+strlen(GROUP_PREFIX
));
350 string_to_sid(&map
->sid
, string_sid
);
352 ret
= tdb_unpack(dbuf
.dptr
, dbuf
.dsize
, "ddff",
353 &map
->gid
, &map
->sid_name_use
, &map
->nt_name
, &map
->comment
);
355 SAFE_FREE(dbuf
.dptr
);
358 DEBUG(3,("get_group_map_from_ntname: tdb_unpack failure\n"));
362 if (StrCaseCmp(name
, map
->nt_name
)==0) {
363 SAFE_FREE(kbuf
.dptr
);
371 /****************************************************************************
372 Remove a group mapping entry.
373 ****************************************************************************/
375 static BOOL
group_map_remove(DOM_SID sid
)
381 if(!init_group_mapping()) {
382 DEBUG(0,("failed to initialize group mapping"));
386 /* the key is the SID, retrieving is direct */
388 sid_to_string(string_sid
, &sid
);
389 slprintf(key
, sizeof(key
), "%s%s", GROUP_PREFIX
, string_sid
);
392 kbuf
.dsize
= strlen(key
)+1;
394 dbuf
= tdb_fetch(tdb
, kbuf
);
398 SAFE_FREE(dbuf
.dptr
);
400 if(tdb_delete(tdb
, kbuf
) != TDB_SUCCESS
)
406 /****************************************************************************
407 Enumerate the group mapping.
408 ****************************************************************************/
410 static BOOL
enum_group_mapping(enum SID_NAME_USE sid_name_use
, GROUP_MAP
**rmap
,
411 int *num_entries
, BOOL unix_only
)
413 TDB_DATA kbuf
, dbuf
, newkey
;
421 if(!init_group_mapping()) {
422 DEBUG(0,("failed to initialize group mapping"));
429 for (kbuf
= tdb_firstkey(tdb
);
431 newkey
= tdb_nextkey(tdb
, kbuf
), safe_free(kbuf
.dptr
), kbuf
=newkey
) {
433 if (strncmp(kbuf
.dptr
, GROUP_PREFIX
, strlen(GROUP_PREFIX
)) != 0)
436 dbuf
= tdb_fetch(tdb
, kbuf
);
440 fstrcpy(string_sid
, kbuf
.dptr
+strlen(GROUP_PREFIX
));
442 ret
= tdb_unpack(dbuf
.dptr
, dbuf
.dsize
, "ddff",
443 &map
.gid
, &map
.sid_name_use
, &map
.nt_name
, &map
.comment
);
445 SAFE_FREE(dbuf
.dptr
);
448 DEBUG(3,("enum_group_mapping: tdb_unpack failure\n"));
452 /* list only the type or everything if UNKNOWN */
453 if (sid_name_use
!=SID_NAME_UNKNOWN
&& sid_name_use
!=map
.sid_name_use
) {
454 DEBUG(11,("enum_group_mapping: group %s is not of the requested type\n", map
.nt_name
));
458 if (unix_only
==ENUM_ONLY_MAPPED
&& map
.gid
==-1) {
459 DEBUG(11,("enum_group_mapping: group %s is non mapped\n", map
.nt_name
));
463 string_to_sid(&map
.sid
, string_sid
);
465 decode_sid_name_use(group_type
, map
.sid_name_use
);
466 DEBUG(11,("enum_group_mapping: returning group %s of type %s\n", map
.nt_name
,group_type
));
468 mapt
=(GROUP_MAP
*)Realloc((*rmap
), (entries
+1)*sizeof(GROUP_MAP
));
470 DEBUG(0,("enum_group_mapping: Unable to enlarge group map!\n"));
477 mapt
[entries
].gid
= map
.gid
;
478 sid_copy( &mapt
[entries
].sid
, &map
.sid
);
479 mapt
[entries
].sid_name_use
= map
.sid_name_use
;
480 fstrcpy(mapt
[entries
].nt_name
, map
.nt_name
);
481 fstrcpy(mapt
[entries
].comment
, map
.comment
);
487 *num_entries
=entries
;
494 * High level functions
495 * better to use them than the lower ones.
497 * we are checking if the group is in the mapping file
498 * and if the group is an existing unix group
502 /* get a domain group from it's SID */
504 BOOL
get_domain_group_from_sid(DOM_SID sid
, GROUP_MAP
*map
)
509 if(!init_group_mapping()) {
510 DEBUG(0,("failed to initialize group mapping"));
514 DEBUG(10, ("get_domain_group_from_sid\n"));
516 /* if the group is NOT in the database, it CAN NOT be a domain group */
519 ret
= pdb_getgrsid(map
, sid
);
525 DEBUG(10, ("get_domain_group_from_sid: SID found in the TDB\n"));
527 /* if it's not a domain group, continue */
528 if (map
->sid_name_use
!=SID_NAME_DOM_GRP
) {
532 DEBUG(10, ("get_domain_group_from_sid: SID is a domain group\n"));
538 DEBUG(10, ("get_domain_group_from_sid: SID is mapped to gid:%lu\n",(unsigned long)map
->gid
));
540 grp
= getgrgid(map
->gid
);
542 DEBUG(10, ("get_domain_group_from_sid: gid DOESN'T exist in UNIX security\n"));
546 DEBUG(10, ("get_domain_group_from_sid: gid exists in UNIX security\n"));
552 /* get a local (alias) group from it's SID */
554 BOOL
get_local_group_from_sid(DOM_SID
*sid
, GROUP_MAP
*map
)
558 if(!init_group_mapping()) {
559 DEBUG(0,("failed to initialize group mapping"));
563 /* The group is in the mapping table */
565 ret
= pdb_getgrsid(map
, *sid
);
571 if ( (map
->sid_name_use
!= SID_NAME_ALIAS
)
573 || (getgrgid(map
->gid
) == NULL
) )
579 /* local groups only exist in the group mapping DB so this
583 /* the group isn't in the mapping table.
584 * make one based on the unix information */
588 sid_peek_rid(sid
, &alias_rid
);
589 map
->gid
=pdb_group_rid_to_gid(alias_rid
);
591 grp
= getgrgid(map
->gid
);
593 DEBUG(3,("get_local_group_from_sid: No unix group for [%ul]\n", map
->gid
));
597 map
->sid_name_use
=SID_NAME_ALIAS
;
599 fstrcpy(map
->nt_name
, grp
->gr_name
);
600 fstrcpy(map
->comment
, "Local Unix Group");
602 sid_copy(&map
->sid
, sid
);
609 /* get a builtin group from it's SID */
611 BOOL
get_builtin_group_from_sid(DOM_SID
*sid
, GROUP_MAP
*map
)
617 if(!init_group_mapping()) {
618 DEBUG(0,("failed to initialize group mapping"));
623 ret
= pdb_getgrsid(map
, *sid
);
629 if (map
->sid_name_use
!=SID_NAME_WKN_GRP
) {
637 if ( (grp
=getgrgid(map
->gid
)) == NULL
) {
646 /****************************************************************************
647 Returns a GROUP_MAP struct based on the gid.
648 ****************************************************************************/
649 BOOL
get_group_from_gid(gid_t gid
, GROUP_MAP
*map
)
654 if(!init_group_mapping()) {
655 DEBUG(0,("failed to initialize group mapping"));
659 if ( (grp
=getgrgid(gid
)) == NULL
)
663 * make a group map from scratch if doesn't exist.
667 ret
= pdb_getgrgid(map
, gid
);
672 map
->sid_name_use
=SID_NAME_ALIAS
;
674 /* interim solution until we have a last RID allocated */
676 sid_copy(&map
->sid
, get_global_sam_sid());
677 sid_append_rid(&map
->sid
, pdb_gid_to_group_rid(gid
));
679 fstrcpy(map
->nt_name
, grp
->gr_name
);
680 fstrcpy(map
->comment
, "Local Unix Group");
689 /****************************************************************************
690 Get the member users of a group and
691 all the users who have that group as primary.
693 give back an array of SIDS
694 return the grand number of users
697 TODO: sort the list and remove duplicate. JFM.
699 ****************************************************************************/
701 BOOL
get_sid_list_of_group(gid_t gid
, DOM_SID
**sids
, int *num_sids
)
708 struct sys_pwent
*userlist
;
709 struct sys_pwent
*user
;
711 if(!init_group_mapping()) {
712 DEBUG(0,("failed to initialize group mapping"));
719 if ( (grp
=getgrgid(gid
)) == NULL
)
723 DEBUG(10, ("getting members\n"));
725 while (gr
&& (*gr
!= (char)'\0')) {
726 SAM_ACCOUNT
*group_member_acct
= NULL
;
728 s
= Realloc((*sids
), sizeof(**sids
)*(*num_sids
+1));
730 DEBUG(0,("get_uid_list_of_group: unable to enlarge SID list!\n"));
735 if (!NT_STATUS_IS_OK(pdb_init_sam(&group_member_acct
))) {
740 found_user
= pdb_getsampwnam(group_member_acct
, gr
);
744 sid_copy(&(*sids
)[*num_sids
], pdb_get_user_sid(group_member_acct
));
748 pdb_free_sam(&group_member_acct
);
750 gr
= grp
->gr_mem
[++i
];
752 DEBUG(10, ("got [%d] members\n", *num_sids
));
756 user
= userlist
= getpwent_list();
758 while (user
!= NULL
) {
760 SAM_ACCOUNT
*group_member_acct
= NULL
;
763 if (user
->pw_gid
!= gid
) {
768 s
= Realloc((*sids
), sizeof(**sids
)*(*num_sids
+1));
770 DEBUG(0,("get_sid_list_of_group: unable to enlarge "
772 pwent_free(userlist
);
778 if (!NT_STATUS_IS_OK(pdb_init_sam(&group_member_acct
))) {
783 found_user
= pdb_getsampwnam(group_member_acct
, user
->pw_name
);
787 sid_copy(&(*sids
)[*num_sids
],
788 pdb_get_user_sid(group_member_acct
));
791 DEBUG(4,("get_sid_list_of_group: User %s [uid == %lu] "
792 "has no samba account\n",
793 user
->pw_name
, (unsigned long)user
->pw_uid
));
794 if (algorithmic_uid_to_sid(&(*sids
)[*num_sids
],
798 pdb_free_sam(&group_member_acct
);
802 pwent_free(userlist
);
803 DEBUG(10, ("got primary groups, members: [%d]\n", *num_sids
));
809 /****************************************************************************
810 Create a UNIX group on demand.
811 ****************************************************************************/
813 int smb_create_group(char *unix_group
, gid_t
*new_gid
)
821 /* defer to scripts */
823 if ( *lp_addgroup_script() ) {
824 pstrcpy(add_script
, lp_addgroup_script());
825 pstring_sub(add_script
, "%g", unix_group
);
826 ret
= smbrun(add_script
, (new_gid
!=NULL
) ? &fd
: NULL
);
827 DEBUG(3,("smb_create_group: Running the command `%s' gave %d\n",add_script
,ret
));
835 if (read(fd
, output
, sizeof(output
)) > 0) {
836 *new_gid
= (gid_t
)strtoul(output
, NULL
, 10);
845 if ( winbind_create_group( unix_group
, NULL
) ) {
846 DEBUG(3,("smb_create_group: winbindd created the group (%s)\n",
852 struct group
*grp
= getgrnam(unix_group
);
855 *new_gid
= grp
->gr_gid
;
861 /****************************************************************************
862 Delete a UNIX group on demand.
863 ****************************************************************************/
865 int smb_delete_group(char *unix_group
)
870 /* defer to scripts */
872 if ( *lp_delgroup_script() ) {
873 pstrcpy(del_script
, lp_delgroup_script());
874 pstring_sub(del_script
, "%g", unix_group
);
875 ret
= smbrun(del_script
,NULL
);
876 DEBUG(3,("smb_delete_group: Running the command `%s' gave %d\n",del_script
,ret
));
880 if ( winbind_delete_group( unix_group
) ) {
881 DEBUG(3,("smb_delete_group: winbindd deleted the group (%s)\n",
889 /****************************************************************************
890 Set a user's primary UNIX group.
891 ****************************************************************************/
892 int smb_set_primary_group(const char *unix_group
, const char* unix_user
)
897 /* defer to scripts */
899 if ( *lp_setprimarygroup_script() ) {
900 pstrcpy(add_script
, lp_setprimarygroup_script());
901 all_string_sub(add_script
, "%g", unix_group
, sizeof(add_script
));
902 all_string_sub(add_script
, "%u", unix_user
, sizeof(add_script
));
903 ret
= smbrun(add_script
,NULL
);
904 DEBUG(3,("smb_set_primary_group: "
905 "Running the command `%s' gave %d\n",add_script
,ret
));
911 if ( winbind_set_user_primary_group( unix_user
, unix_group
) ) {
912 DEBUG(3,("smb_delete_group: winbindd set the group (%s) as the primary group for user (%s)\n",
913 unix_group
, unix_user
));
920 /****************************************************************************
921 Add a user to a UNIX group.
922 ****************************************************************************/
924 int smb_add_user_group(char *unix_group
, char *unix_user
)
929 /* defer to scripts */
931 if ( *lp_addusertogroup_script() ) {
932 pstrcpy(add_script
, lp_addusertogroup_script());
933 pstring_sub(add_script
, "%g", unix_group
);
934 pstring_sub(add_script
, "%u", unix_user
);
935 ret
= smbrun(add_script
,NULL
);
936 DEBUG(3,("smb_add_user_group: Running the command `%s' gave %d\n",add_script
,ret
));
942 if ( winbind_add_user_to_group( unix_user
, unix_group
) ) {
943 DEBUG(3,("smb_delete_group: winbindd added user (%s) to the group (%s)\n",
944 unix_user
, unix_group
));
951 /****************************************************************************
952 Delete a user from a UNIX group
953 ****************************************************************************/
955 int smb_delete_user_group(const char *unix_group
, const char *unix_user
)
960 /* defer to scripts */
962 if ( *lp_deluserfromgroup_script() ) {
963 pstrcpy(del_script
, lp_deluserfromgroup_script());
964 pstring_sub(del_script
, "%g", unix_group
);
965 pstring_sub(del_script
, "%u", unix_user
);
966 ret
= smbrun(del_script
,NULL
);
967 DEBUG(3,("smb_delete_user_group: Running the command `%s' gave %d\n",del_script
,ret
));
973 if ( winbind_remove_user_from_group( unix_user
, unix_group
) ) {
974 DEBUG(3,("smb_delete_group: winbindd removed user (%s) from the group (%s)\n",
975 unix_user
, unix_group
));
983 NTSTATUS
pdb_default_getgrsid(struct pdb_methods
*methods
, GROUP_MAP
*map
,
986 return get_group_map_from_sid(sid
, map
) ?
987 NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
990 NTSTATUS
pdb_default_getgrgid(struct pdb_methods
*methods
, GROUP_MAP
*map
,
993 return get_group_map_from_gid(gid
, map
) ?
994 NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
997 NTSTATUS
pdb_default_getgrnam(struct pdb_methods
*methods
, GROUP_MAP
*map
,
1000 return get_group_map_from_ntname(name
, map
) ?
1001 NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1004 NTSTATUS
pdb_default_add_group_mapping_entry(struct pdb_methods
*methods
,
1007 return add_mapping_entry(map
, TDB_INSERT
) ?
1008 NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1011 NTSTATUS
pdb_default_update_group_mapping_entry(struct pdb_methods
*methods
,
1014 return add_mapping_entry(map
, TDB_REPLACE
) ?
1015 NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1018 NTSTATUS
pdb_default_delete_group_mapping_entry(struct pdb_methods
*methods
,
1021 return group_map_remove(sid
) ?
1022 NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1025 NTSTATUS
pdb_default_enum_group_mapping(struct pdb_methods
*methods
,
1026 enum SID_NAME_USE sid_name_use
,
1027 GROUP_MAP
**rmap
, int *num_entries
,
1030 return enum_group_mapping(sid_name_use
, rmap
, num_entries
, unix_only
) ?
1031 NT_STATUS_OK
: NT_STATUS_UNSUCCESSFUL
;
1034 /**********************************************************************
1035 no ops for passdb backends that don't implement group mapping
1036 *********************************************************************/
1038 NTSTATUS
pdb_nop_getgrsid(struct pdb_methods
*methods
, GROUP_MAP
*map
,
1041 return NT_STATUS_UNSUCCESSFUL
;
1044 NTSTATUS
pdb_nop_getgrgid(struct pdb_methods
*methods
, GROUP_MAP
*map
,
1047 return NT_STATUS_UNSUCCESSFUL
;
1050 NTSTATUS
pdb_nop_getgrnam(struct pdb_methods
*methods
, GROUP_MAP
*map
,
1053 return NT_STATUS_UNSUCCESSFUL
;
1056 NTSTATUS
pdb_nop_add_group_mapping_entry(struct pdb_methods
*methods
,
1059 return NT_STATUS_UNSUCCESSFUL
;
1062 NTSTATUS
pdb_nop_update_group_mapping_entry(struct pdb_methods
*methods
,
1065 return NT_STATUS_UNSUCCESSFUL
;
1068 NTSTATUS
pdb_nop_delete_group_mapping_entry(struct pdb_methods
*methods
,
1071 return NT_STATUS_UNSUCCESSFUL
;
1074 NTSTATUS
pdb_nop_enum_group_mapping(struct pdb_methods
*methods
,
1075 enum SID_NAME_USE sid_name_use
,
1076 GROUP_MAP
**rmap
, int *num_entries
,
1079 return NT_STATUS_UNSUCCESSFUL
;