r21070: * Add the new boolean 'winbind normalize names' option as discussed
authorGerald Carter <jerry@samba.org>
Wed, 31 Jan 2007 05:38:36 +0000 (05:38 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:17:32 +0000 (12:17 -0500)
  on the samba-technical ml.  The replacement character is hardcoded
  as a '_' for now.

source/nsswitch/winbindd_group.c
source/nsswitch/winbindd_rpc.c
source/nsswitch/winbindd_user.c
source/nsswitch/winbindd_util.c
source/param/loadparm.c

index e5cdc404a0d3f070c021bc7925f64519abbd8251..9d8b41b4bff56785f0d2730e1b15dc038ba72d6c 100644 (file)
@@ -462,6 +462,7 @@ void winbindd_getgrnam(struct winbindd_cli_state *state)
        gid_t gid;
        union unid_t id;
        NTSTATUS status;
+       char replace_char[2] = { 0x0, 0x0 };
        
        /* Ensure null termination */
        state->request.data.groupname[sizeof(state->request.data.groupname)-1]='\0';
@@ -502,6 +503,8 @@ void winbindd_getgrnam(struct winbindd_cli_state *state)
        }
 
        /* Get rid and name type from name */
+
+       ws_name_replace( name_group, '_' );
         
        if (!winbindd_lookup_sid_by_name(state->mem_ctx, domain, domain->name,
                                         name_group, &group_sid, &name_type)) {
index 08fe129db0e3f8b05e0ee38f9f5445ec7caa8894..6e6add20098518fa4929059c20083a4be3217ef1 100644 (file)
@@ -246,7 +246,7 @@ NTSTATUS msrpc_name_to_sid(struct winbindd_domain *domain,
        NTSTATUS result;
        DOM_SID *sids = NULL;
        enum lsa_SidType *types = NULL;
-       const char *full_name;
+       char *full_name;
        struct rpc_pipe_client *cli;
        POLICY_HND lsa_policy;
 
@@ -262,6 +262,8 @@ NTSTATUS msrpc_name_to_sid(struct winbindd_domain *domain,
                return NT_STATUS_NO_MEMORY;
        }
 
+       ws_name_return( full_name, '_' );       
+
        DEBUG(3,("name_to_sid [rpc] %s for domain %s\n", full_name?full_name:"", domain_name ));
 
        result = cm_connect_lsa(domain, mem_ctx, &cli, &lsa_policy);
@@ -314,6 +316,9 @@ NTSTATUS msrpc_sid_to_name(struct winbindd_domain *domain,
        *type = (enum lsa_SidType)types[0];
        *domain_name = domains[0];
        *name = names[0];
+
+       ws_name_replace( *name, '_' );  
+               
        DEBUG(5,("Mapped sid to [%s]\\[%s]\n", domains[0], *name));
        return NT_STATUS_OK;
 }
@@ -333,6 +338,7 @@ NTSTATUS msrpc_rids_to_names(struct winbindd_domain *domain,
        POLICY_HND lsa_policy;
        DOM_SID *sids;
        size_t i;
+       char **ret_names;
 
        DEBUG(3, ("rids_to_names [rpc] for domain %s\n", domain->name ));
 
@@ -360,10 +366,11 @@ NTSTATUS msrpc_rids_to_names(struct winbindd_domain *domain,
                return result;
        }
 
+       ret_names = *names;
        for (i=0; i<num_rids; i++) {
                if ((*types)[i] != SID_NAME_UNKNOWN) {
+                       ws_name_replace( ret_names[i], '_' );
                        *domain_name = domains[i];
-                       break;
                }
        }
 
index 76cf9d44bdf0c37ce05de6f399308d711b7743f7..e386efedb301886efd8254cb3591b2bfaf810bd5 100644 (file)
@@ -241,6 +241,9 @@ static void getpwsid_queryuser_recv(void *private_data, BOOL success,
        fstrcpy( username, acct_name );
        strlower_m( username );
        s->username = talloc_strdup(s->state->mem_ctx, username);
+
+       ws_name_replace( s->username, '_' );
+        
        s->fullname = talloc_strdup(s->state->mem_ctx, full_name);
        s->homedir = talloc_strdup(s->state->mem_ctx, homedir);
        s->shell = talloc_strdup(s->state->mem_ctx, shell);
index 7a3a7bdf287f97ea00417a22f2d40dfc65771bae..85d5f3443a480102e1c124212f636c5ecbbb0706 100644 (file)
@@ -1073,3 +1073,37 @@ NTSTATUS lookup_usergroups_cached(struct winbindd_domain *domain,
 
        return status;
 }
+
+/*********************************************************************
+ We use this to remove spaces from user and group names
+********************************************************************/
+
+void ws_name_replace( char *name, char replace )
+{
+       char replace_char[2] = { 0x0, 0x0 };
+    
+       if ( !lp_winbind_normalize_names() || (replace == '\0') ) 
+               return;
+
+       replace_char[0] = replace;      
+       all_string_sub( name, " ", replace_char, 0 );
+
+       return; 
+}
+
+/*********************************************************************
+ We use this to do the inverse of ws_name_replace()
+********************************************************************/
+
+void ws_name_return( char *name, char replace )
+{
+       char replace_char[2] = { 0x0, 0x0 };
+    
+       if ( !lp_winbind_normalize_names() || (replace == '\0') ) 
+               return;
+       
+       replace_char[0] = replace;      
+       all_string_sub( name, replace_char, " ", 0 );
+
+       return; 
+}
index e1cce4b963fc0eb65a939e41edd6b43cccbedac8..8634c48b31b4d94b1a375865ef82d5b4e128b444 100644 (file)
@@ -180,6 +180,7 @@ typedef struct {
        BOOL bWinbindNestedGroups;
        BOOL bWinbindRefreshTickets;
        BOOL bWinbindOfflineLogon;
+       BOOL bWinbindNormalizeNames;
        char **szIdmapDomains;
        char **szIdmapBackend; /* deprecated */
        char *szIdmapAllocBackend;
@@ -1288,6 +1289,7 @@ static struct parm_struct parm_table[] = {
        {"winbind nss info", P_LIST, P_GLOBAL, &Globals.szWinbindNssInfo, NULL, NULL, FLAG_ADVANCED}, 
        {"winbind refresh tickets", P_BOOL, P_GLOBAL, &Globals.bWinbindRefreshTickets, NULL, NULL, FLAG_ADVANCED}, 
        {"winbind offline logon", P_BOOL, P_GLOBAL, &Globals.bWinbindOfflineLogon, NULL, NULL, FLAG_ADVANCED},
+       {"winbind normalize names", P_BOOL, P_GLOBAL, &Globals.bWinbindNormalizeNames, NULL, NULL, FLAG_ADVANCED},
 
        {NULL,  P_BOOL,  P_NONE,  NULL,  NULL,  NULL,  0}
 };
@@ -1622,6 +1624,7 @@ static void init_globals(BOOL first_time_only)
        string_set(&Globals.szTemplateShell, "/bin/false");
        string_set(&Globals.szTemplateHomedir, "/home/%D/%U");
        string_set(&Globals.szWinbindSeparator, "\\");
+
        string_set(&Globals.szCupsServer, "");
        string_set(&Globals.szIPrintServer, "");
 
@@ -1854,6 +1857,7 @@ FN_GLOBAL_BOOL(lp_winbind_trusted_domains_only, &Globals.bWinbindTrustedDomainsO
 FN_GLOBAL_BOOL(lp_winbind_nested_groups, &Globals.bWinbindNestedGroups)
 FN_GLOBAL_BOOL(lp_winbind_refresh_tickets, &Globals.bWinbindRefreshTickets)
 FN_GLOBAL_BOOL(lp_winbind_offline_logon, &Globals.bWinbindOfflineLogon)
+FN_GLOBAL_BOOL(lp_winbind_normalize_names, &Globals.bWinbindNormalizeNames)
 
 FN_GLOBAL_LIST(lp_idmap_domains, &Globals.szIdmapDomains)
 FN_GLOBAL_LIST(lp_idmap_backend, &Globals.szIdmapBackend) /* deprecated */