ctdb/docs: Include ceph rados namespace support in man page
[samba.git] / source3 / winbindd / nss_info.c
index 734c0096024b663cc6e4ee3817564c09d5d222fb..3b58ca2932414bb446d07ec3e97a0aa55e90419c 100644 (file)
@@ -32,7 +32,7 @@ static struct nss_domain_entry *nss_domain_list = NULL;
 
 static struct nss_function_entry *nss_get_backend(const char *name )
 {
-       struct nss_function_entry *entry = backends;
+       struct nss_function_entry *entry = NULL;
 
        for(entry = backends; entry; entry = entry->next) {
                if ( strequal(entry->name, name) )
@@ -46,7 +46,8 @@ static struct nss_function_entry *nss_get_backend(const char *name )
  Allow a module to register itself as a backend.
 **********************************************************************/
 
- NTSTATUS smb_register_idmap_nss(int version, const char *name, struct nss_info_methods *methods)
+ NTSTATUS smb_register_idmap_nss(int version, const char *name,
+                                const struct nss_info_methods *methods)
 {
        struct nss_function_entry *entry;
 
@@ -65,7 +66,7 @@ static struct nss_function_entry *nss_get_backend(const char *name )
        }
 
        if ( nss_get_backend(name) ) {
-               DEBUG(0,("smb_register_idmap_nss: idmap module %s "
+               DEBUG(5,("smb_register_idmap_nss: idmap module %s "
                         "already registered!\n", name));
                return NT_STATUS_OBJECT_NAME_COLLISION;
        }
@@ -84,11 +85,12 @@ static struct nss_function_entry *nss_get_backend(const char *name )
 /********************************************************************
  *******************************************************************/
 
-static bool parse_nss_parm( const char *config, char **backend, char **domain )
+static bool parse_nss_parm(TALLOC_CTX *mem_ctx,
+                          const char *config,
+                          char **backend,
+                          char **domain)
 {
        char *p;
-       char *q;
-       int len;
 
        *backend = *domain = NULL;
 
@@ -100,27 +102,18 @@ static bool parse_nss_parm( const char *config, char **backend, char **domain )
        /* if no : then the string must be the backend name only */
 
        if ( !p ) {
-               *backend = SMB_STRDUP( config );
+               *backend = talloc_strdup(mem_ctx, config);
                return (*backend != NULL);
        }
 
        /* split the string and return the two parts */
 
        if ( strlen(p+1) > 0 ) {
-               *domain = SMB_STRDUP( p+1 );
+               *domain = talloc_strdup(mem_ctx, p + 1);
        }
 
-       len = PTR_DIFF(p,config)+1;
-       if ( (q = SMB_MALLOC_ARRAY( char, len )) == NULL ) {
-               SAFE_FREE( *backend );
-               return False;
-       }
-
-       StrnCpy( q, config, len-1);
-       q[len-1] = '\0';
-       *backend = q;
-
-       return True;
+       *backend = talloc_strndup(mem_ctx, config, PTR_DIFF(p, config));
+       return (*backend != NULL);
 }
 
 static NTSTATUS nss_domain_list_add_domain(const char *domain,
@@ -128,7 +121,7 @@ static NTSTATUS nss_domain_list_add_domain(const char *domain,
 {
        struct nss_domain_entry *nss_domain;
 
-       nss_domain = TALLOC_ZERO_P(nss_domain_list, struct nss_domain_entry);
+       nss_domain = talloc_zero(nss_domain_list, struct nss_domain_entry);
        if (!nss_domain) {
                DEBUG(0, ("nss_domain_list_add_domain: talloc() failure!\n"));
                return NT_STATUS_NO_MEMORY;
@@ -164,32 +157,39 @@ static NTSTATUS nss_domain_list_add_domain(const char *domain,
  to initialize the state on a per domain basis.
  *******************************************************************/
 
- NTSTATUS nss_init( const char **nss_list )
+static NTSTATUS nss_init(const char **nss_list)
 {
        NTSTATUS status;
-       static NTSTATUS nss_initialized = NT_STATUS_UNSUCCESSFUL;
+       static bool nss_initialized = false;
        int i;
-       char *backend, *domain;
+       char *backend = NULL, *domain = NULL;
        struct nss_function_entry *nss_backend;
+       TALLOC_CTX *frame;
 
        /* check for previous successful initializations */
 
-       if ( NT_STATUS_IS_OK(nss_initialized) )
+       if (nss_initialized) {
                return NT_STATUS_OK;
+       }
+
+       frame = talloc_stackframe();
 
-       /* The "template" backend should alqays be registered as it
+       /* The "template" backend should always be registered as it
           is a static module */
 
-       if ( (nss_backend = nss_get_backend( "template" )) == NULL ) {
-               static_init_nss_info;
+       nss_backend = nss_get_backend("template");
+       if (nss_backend == NULL) {
+               static_init_nss_info(NULL);
        }
 
        /* Create the list of nss_domains (loading any shared plugins
           as necessary) */
 
        for ( i=0; nss_list && nss_list[i]; i++ ) {
+               bool ok;
 
-               if ( !parse_nss_parm(nss_list[i], &backend, &domain) ) {
+               ok = parse_nss_parm(frame, nss_list[i], &backend, &domain);
+               if (!ok) {
                        DEBUG(0,("nss_init: failed to parse \"%s\"!\n",
                                 nss_list[i]));
                        continue;
@@ -200,21 +200,36 @@ static NTSTATUS nss_domain_list_add_domain(const char *domain,
 
                /* validate the backend */
 
-               if ( (nss_backend = nss_get_backend( backend )) == NULL ) {
-                       /* attempt to register the backend */
-                       status = smb_probe_module( "nss_info", backend );
+               nss_backend = nss_get_backend(backend);
+               if (nss_backend == NULL) {
+                       /*
+                        * This is a freaking hack. We don't have proper
+                        * modules for nss_info backends. Right now we have
+                        * our standard nss_info backends in the ad backend.
+                        */
+                       status = smb_probe_module("idmap", "ad");
                        if ( !NT_STATUS_IS_OK(status) ) {
                                continue;
                        }
+               }
 
-                       /* try again */
-                       if ( (nss_backend = nss_get_backend( backend )) == NULL ) {
-                               DEBUG(0,("nss_init: unregistered backend %s!.  Skipping\n",
-                                        backend));
+               nss_backend = nss_get_backend(backend);
+               if (nss_backend == NULL) {
+                       /* attempt to register the backend */
+                       status = smb_probe_module( "nss_info", backend );
+                       if ( !NT_STATUS_IS_OK(status) ) {
                                continue;
                        }
                }
 
+               /* try again */
+               nss_backend = nss_get_backend(backend);
+               if (nss_backend == NULL) {
+                       DEBUG(0, ("nss_init: unregistered backend %s!. "
+                                 "Skipping\n", backend));
+                       continue;
+               }
+
                /*
                 * The first config item of the list without an explicit domain
                 * is treated as the default nss info backend.
@@ -232,20 +247,22 @@ static NTSTATUS nss_domain_list_add_domain(const char *domain,
 
                /* cleanup */
 
-               SAFE_FREE( backend );
-               SAFE_FREE( domain );
+               TALLOC_FREE(domain);
+               TALLOC_FREE(backend);
        }
 
+
        if ( !nss_domain_list ) {
                DEBUG(3,("nss_init: no nss backends configured.  "
                         "Defaulting to \"template\".\n"));
 
 
-               /* we shouild default to use template here */
+               /* we should default to use template here */
        }
 
-       nss_initialized = NT_STATUS_OK;
+       nss_initialized = true;
 
+       TALLOC_FREE(frame);
        return NT_STATUS_OK;
 }
 
@@ -259,8 +276,8 @@ static struct nss_domain_entry *find_nss_domain( const char *domain )
 
        status = nss_init( lp_winbind_nss_info() );
        if ( !NT_STATUS_IS_OK(status) ) {
-               DEBUG(4,("nss_get_info: Failed to init nss_info API (%s)!\n",
-                        nt_errstr(status)));
+               DEBUG(4,("find_nss_domain: Failed to init nss_info API "
+                        "(%s)!\n", nt_errstr(status)));
                return NULL;
        }
 
@@ -296,33 +313,6 @@ static struct nss_domain_entry *find_nss_domain( const char *domain )
        return p;
 }
 
-/********************************************************************
- *******************************************************************/
-
- NTSTATUS nss_get_info( const char *domain, const DOM_SID *user_sid,
-                      TALLOC_CTX *ctx,
-                      ADS_STRUCT *ads, LDAPMessage *msg,
-                      char **homedir, char **shell, char **gecos,
-                      gid_t *p_gid)
-{
-       struct nss_domain_entry *p;
-       struct nss_info_methods *m;
-
-       DEBUG(10, ("nss_get_info called for sid [%s] in domain '%s'\n",
-                  sid_string_dbg(user_sid), domain?domain:"NULL"));
-
-       if ( (p = find_nss_domain( domain )) == NULL ) {
-               DEBUG(4,("nss_get_info: Failed to find nss domain pointer for %s\n",
-                        domain ));
-               return NT_STATUS_NOT_FOUND;
-       }
-
-       m = p->backend->methods;
-
-       return m->get_nss_info( p, user_sid, ctx, ads, msg,
-                               homedir, shell, gecos, p_gid );
-}
-
 /********************************************************************
  *******************************************************************/
 
@@ -330,7 +320,7 @@ static struct nss_domain_entry *find_nss_domain( const char *domain )
                            const char *name, char **alias )
 {
        struct nss_domain_entry *p;
-       struct nss_info_methods *m;
+       const struct nss_info_methods *m;
 
        if ( (p = find_nss_domain( domain )) == NULL ) {
                DEBUG(4,("nss_map_to_alias: Failed to find nss domain pointer for %s\n",
@@ -351,7 +341,7 @@ static struct nss_domain_entry *find_nss_domain( const char *domain )
                              const char *alias, char **name )
 {
        struct nss_domain_entry *p;
-       struct nss_info_methods *m;
+       const struct nss_info_methods *m;
 
        if ( (p = find_nss_domain( domain )) == NULL ) {
                DEBUG(4,("nss_map_from_alias: Failed to find nss domain pointer for %s\n",