s3: safe_string: do not include string_wrappers.h
[bbaumbach/samba-autobuild/.git] / source3 / utils / net_groupmap.c
index 8c6aa2e5c0ac1a5d639a11193055a29afcae9ccf..68765a21fc89755755ce7a6c86f848594bdccdd7 100644 (file)
@@ -2,7 +2,7 @@
  *  Unix SMB/CIFS implementation.
  *  RPC Pipe client / server routines
  *  Copyright (C) Andrew Tridgell              1992-2000,
- *  Copyright (C) Jean François Micouleau      1998-2001.
+ *  Copyright (C) Jean François Micouleau      1998-2001.
  *  Copyright (C) Gerald Carter                2003,
  *  Copyright (C) Volker Lendecke              2004
  *
@@ -26,6 +26,7 @@
 #include "utils/net.h"
 #include "../libcli/security/security.h"
 #include "passdb.h"
+#include "lib/util/string_wrappers.h"
 
 /*********************************************************
  Figure out if the input was an NT group or a SID string.
@@ -68,12 +69,16 @@ static bool get_sid_from_input(struct dom_sid *sid, char *input)
 
 static void print_map_entry (const GROUP_MAP *map, bool long_list)
 {
+       struct dom_sid_buf buf;
+
        if (!long_list)
                d_printf("%s (%s) -> %s\n", map->nt_name,
-                        sid_string_tos(&map->sid), gidtoname(map->gid));
+                        dom_sid_str_buf(&map->sid, &buf),
+                        gidtoname(map->gid));
        else {
                d_printf("%s\n", map->nt_name);
-               d_printf(_("\tSID       : %s\n"), sid_string_tos(&map->sid));
+               d_printf(_("\tSID       : %s\n"),
+                        dom_sid_str_buf(&map->sid, &buf));
                d_printf(_("\tUnix gid  : %u\n"), (unsigned int)map->gid);
                d_printf(_("\tUnix group: %s\n"), gidtoname(map->gid));
                d_printf(_("\tGroup type: %s\n"),
@@ -195,7 +200,7 @@ static int net_groupmap_add(struct net_context *c, int argc, const char **argv)
        fstring type = "";
        fstring ntcomment = "";
        enum lsa_SidType sid_type = SID_NAME_DOM_GRP;
-       uint32 rid = 0;
+       uint32_t rid = 0;
        gid_t gid;
        int i;
        GROUP_MAP *map;
@@ -222,7 +227,7 @@ static int net_groupmap_add(struct net_context *c, int argc, const char **argv)
                        if ( rid < DOMAIN_RID_ADMINS ) {
                                d_fprintf(stderr,
                                          _("RID must be greater than %d\n"),
-                                         (uint32)DOMAIN_RID_ADMINS-1);
+                                         (uint32_t)DOMAIN_RID_ADMINS-1);
                                return -1;
                        }
                }
@@ -303,8 +308,9 @@ static int net_groupmap_add(struct net_context *c, int argc, const char **argv)
        /* Default is domain group. */
        map->sid_name_use = SID_NAME_DOM_GRP;
        if (pdb_getgrgid(map, gid)) {
+               struct dom_sid_buf buf;
                d_printf(_("Unix group %s already mapped to SID %s\n"),
-                        unixgrp, sid_string_tos(&map->sid));
+                        unixgrp, dom_sid_str_buf(&map->sid, &buf));
                TALLOC_FREE(map);
                return -1;
        }
@@ -654,7 +660,7 @@ static int net_groupmap_set(struct net_context *c, int argc, const char **argv)
 
                if (c->opt_rid == 0) {
                        if ( pdb_capabilities() & PDB_CAP_STORE_RIDS ) {
-                               if ( !pdb_new_rid((uint32*)&c->opt_rid) ) {
+                               if ( !pdb_new_rid((uint32_t *)&c->opt_rid) ) {
                                        d_fprintf( stderr,
                                            _("Could not allocate new RID\n"));
                                        TALLOC_FREE(map);
@@ -764,10 +770,13 @@ static int net_groupmap_cleanup(struct net_context *c, int argc, const char **ar
                        printf(_("Group %s is not mapped\n"),
                                maps[i]->nt_name);
 
-               if (!sid_check_is_in_our_sam(&maps[i]->sid)) {
+               if (!sid_check_is_in_our_sam(&maps[i]->sid) &&
+                   !sid_check_is_in_builtin(&maps[i]->sid))
+               {
+                       struct dom_sid_buf buf;
                        printf(_("Deleting mapping for NT Group %s, sid %s\n"),
                                maps[i]->nt_name,
-                               sid_string_tos(&maps[i]->sid));
+                               dom_sid_str_buf(&maps[i]->sid, &buf));
                        pdb_delete_group_mapping_entry(maps[i]->sid);
                }
        }
@@ -848,7 +857,8 @@ static int net_groupmap_listmem(struct net_context *c, int argc, const char **ar
        }
 
        for (i = 0; i < num; i++) {
-               printf("%s\n", sid_string_tos(&(members[i])));
+               struct dom_sid_buf buf;
+               printf("%s\n", dom_sid_str_buf(&(members[i]), &buf));
        }
 
        TALLOC_FREE(members);
@@ -860,8 +870,9 @@ static bool print_alias_memberships(TALLOC_CTX *mem_ctx,
                                    const struct dom_sid *domain_sid,
                                    const struct dom_sid *member)
 {
-       uint32 *alias_rids;
+       uint32_t *alias_rids;
        size_t i, num_alias_rids;
+       struct dom_sid_buf buf;
 
        alias_rids = NULL;
        num_alias_rids = 0;
@@ -870,14 +881,14 @@ static bool print_alias_memberships(TALLOC_CTX *mem_ctx,
                                     mem_ctx, domain_sid, member, 1,
                                     &alias_rids, &num_alias_rids))) {
                d_fprintf(stderr, _("Could not list memberships for sid %s\n"),
-                        sid_string_tos(member));
+                         dom_sid_str_buf(member, &buf));
                return false;
        }
 
        for (i = 0; i < num_alias_rids; i++) {
                struct dom_sid alias;
                sid_compose(&alias, domain_sid, alias_rids[i]);
-               printf("%s\n", sid_string_tos(&alias));
+               printf("%s\n", dom_sid_str_buf(&alias, &buf));
        }
 
        return true;