s3:loadparm: rename free_parameter() to free_one_parameter_by_snum()
[kai/samba.git] / source3 / param / loadparm.c
index d91d34d29bfab55e42e7bbd488346cee699e7ea1..580136446ba68a4a7e3225ec4fa8f38689233a6e 100644 (file)
@@ -425,6 +425,7 @@ struct service {
        bool bHideUnReadable;
        bool bHideUnWriteableFiles;
        bool bBrowseable;
+       bool bAccessBasedShareEnum;
        bool bAvailable;
        bool bRead_only;
        bool bNo_set_dir;
@@ -568,6 +569,7 @@ static struct service sDefault = {
        False,                  /* bHideUnReadable */
        False,                  /* bHideUnWriteableFiles */
        True,                   /* bBrowseable */
+       False,                  /* bAccessBasedShareEnum */
        True,                   /* bAvailable */
        True,                   /* bRead_only */
        True,                   /* bNo_set_dir */
@@ -669,6 +671,8 @@ static void set_server_role(void);
 static void set_default_server_announce_type(void);
 static void set_allowed_client_auth(void);
 
+static void *lp_local_ptr(struct service *service, void *ptr);
+
 static const struct enum_list enum_protocol[] = {
        {PROTOCOL_NT1, "NT1"},
        {PROTOCOL_LANMAN2, "LANMAN2"},
@@ -3303,6 +3307,15 @@ static struct parm_struct parm_table[] = {
                .enum_list      = NULL,
                .flags          = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT,
        },
+       {
+               .label          = "access based share enum",
+               .type           = P_BOOL,
+               .p_class        = P_LOCAL,
+               .ptr            = &sDefault.bAccessBasedShareEnum,
+               .special        = NULL,
+               .enum_list      = NULL,
+               .flags          = FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE
+       },
        {
                .label          = "browsable",
                .type           = P_BOOL,
@@ -4572,10 +4585,12 @@ static void init_printer_values(struct service *pService)
        }
 }
 
+
 /**
- * Free the allocated data for one parameter for a given share.
+ * Free the allocated data for one parameter for a given share
+ * specified by an snum.
  */
-static void free_parameter(int snum, struct parm_struct parm)
+static void free_one_parameter_by_snum(int snum, struct parm_struct parm)
 {
        void *parm_ptr;
 
@@ -4588,7 +4603,7 @@ static void free_parameter(int snum, struct parm_struct parm)
        } else if (parm.p_class != P_LOCAL) {
                return;
        } else {
-               parm_ptr = lp_local_ptr(snum, parm.ptr);
+               parm_ptr = lp_local_ptr_by_snum(snum, parm.ptr);
        }
 
        if ((parm.type == P_STRING) ||
@@ -4608,7 +4623,7 @@ static void free_parameters(int snum)
        uint32_t i;
 
        for (i=0; parm_table[i].label; i++) {
-               free_parameter(snum, parm_table[i]);
+               free_one_parameter_by_snum(snum, parm_table[i]);
        }
 }
 
@@ -4899,7 +4914,7 @@ static void init_globals(bool first_time_only)
        Globals.bWinbindTrustedDomainsOnly = False;
        Globals.bWinbindNestedGroups = True;
        Globals.winbind_expand_groups = 1;
-       Globals.szWinbindNssInfo = str_list_make(NULL, "template", NULL);
+       Globals.szWinbindNssInfo = str_list_make_v3(talloc_autofree_context(), "template", NULL);
        Globals.bWinbindRefreshTickets = False;
        Globals.bWinbindOfflineLogon = False;
 
@@ -5063,7 +5078,6 @@ FN_GLOBAL_STRING(lp_remote_announce, &Globals.szRemoteAnnounce)
 FN_GLOBAL_STRING(lp_remote_browse_sync, &Globals.szRemoteBrowseSync)
 FN_GLOBAL_LIST(lp_wins_server_list, &Globals.szWINSservers)
 FN_GLOBAL_LIST(lp_interfaces, &Globals.szInterfaces)
-FN_GLOBAL_STRING(lp_socket_address, &Globals.szSocketAddress)
 FN_GLOBAL_STRING(lp_nis_home_map_name, &Globals.szNISHomeMapName)
 static FN_GLOBAL_STRING(lp_announce_version, &Globals.szAnnounceVersion)
 FN_GLOBAL_LIST(lp_netbios_aliases, &Globals.szNetbiosAliases)
@@ -5332,6 +5346,7 @@ FN_LOCAL_BOOL(lp_hide_special_files, bHideSpecialFiles)
 FN_LOCAL_BOOL(lp_hideunreadable, bHideUnReadable)
 FN_LOCAL_BOOL(lp_hideunwriteable_files, bHideUnWriteableFiles)
 FN_LOCAL_BOOL(lp_browseable, bBrowseable)
+FN_LOCAL_BOOL(lp_access_based_share_enum, bAccessBasedShareEnum)
 FN_LOCAL_BOOL(lp_readonly, bRead_only)
 FN_LOCAL_BOOL(lp_no_set_dir, bNo_set_dir)
 FN_LOCAL_BOOL(lp_guest_ok, bGuest_ok)
@@ -5418,7 +5433,6 @@ FN_GLOBAL_INTEGER(lp_client_ldap_sasl_wrapping, &Globals.client_ldap_sasl_wrappi
 
 static int map_parameter(const char *pszParmName);
 static int map_parameter_canonical(const char *pszParmName, bool *inverse);
-static bool set_boolean(bool *pb, const char *pszParmValue);
 static const char *get_boolean(bool bool_value);
 static int getservicebyname(const char *pszServiceName,
                            struct service *pserviceDest);
@@ -5532,7 +5546,7 @@ static bool lp_bool(const char *s)
                return False;
        }
        
-       if (!set_boolean(&ret,s)) {
+       if (!set_boolean(s, &ret)) {
                DEBUG(0,("lp_bool(%s): value is not boolean!\n",s));
                return False;
        }
@@ -5616,7 +5630,7 @@ const char **lp_parm_string_list(int snum, const char *type, const char *option,
                return (const char **)def;
                
        if (data->list==NULL) {
-               data->list = str_list_make(NULL, data->value, NULL);
+               data->list = str_list_make_v3(talloc_autofree_context(), data->value, NULL);
        }
 
        return (const char **)data->list;
@@ -5927,6 +5941,7 @@ bool lp_add_home(const char *pszHomename, int iDefaultService,
        /* set the browseable flag from the global default */
 
        ServicePtrs[i]->bBrowseable = sDefault.bBrowseable;
+       ServicePtrs[i]->bAccessBasedShareEnum = sDefault.bAccessBasedShareEnum;
 
        ServicePtrs[i]->autoloaded = True;
 
@@ -6314,49 +6329,13 @@ void show_parameter_list(void)
        }
 }
 
-/***************************************************************************
- Set a boolean variable from the text value stored in the passed string.
- Returns True in success, False if the passed string does not correctly 
- represent a boolean.
-***************************************************************************/
-
-static bool set_boolean(bool *pb, const char *pszParmValue)
-{
-       bool bRetval;
-       bool value;
-
-       bRetval = True;
-       value = False;
-       if (strwicmp(pszParmValue, "yes") == 0 ||
-           strwicmp(pszParmValue, "true") == 0 ||
-           strwicmp(pszParmValue, "1") == 0)
-               value = True;
-       else if (strwicmp(pszParmValue, "no") == 0 ||
-                   strwicmp(pszParmValue, "False") == 0 ||
-                   strwicmp(pszParmValue, "0") == 0)
-               value = False;
-       else {
-               DEBUG(2,
-                     ("ERROR: Badly formed boolean in configuration file: \"%s\".\n",
-                      pszParmValue));
-               bRetval = False;
-       }
-
-       if ((pb != NULL) && (bRetval != False)) {
-               *pb = value;
-       }
-
-       return (bRetval);
-}
-
-
 /***************************************************************************
  Check if a given string correctly represents a boolean value.
 ***************************************************************************/
 
 bool lp_string_is_valid_boolean(const char *parm_value)
 {
-       return set_boolean(NULL, parm_value);
+       return set_boolean(parm_value, NULL);
 }
 
 /***************************************************************************
@@ -6381,7 +6360,7 @@ bool lp_invert_boolean(const char *str, const char **inverse_str)
 {
        bool val;
 
-       if (!set_boolean(&val, str)) {
+       if (!set_boolean(str, &val)) {
                return False;
        }
 
@@ -6399,7 +6378,7 @@ bool lp_canonicalize_boolean(const char *str, const char**canon_str)
 {
        bool val;
 
-       if (!set_boolean(&val, str)) {
+       if (!set_boolean(str, &val)) {
                return False;
        }
 
@@ -6606,7 +6585,7 @@ static struct smbconf_ctx *lp_smbconf_ctx(void)
                werr = smbconf_init(NULL, &conf_ctx, "registry:");
                if (!W_ERROR_IS_OK(werr)) {
                        DEBUG(1, ("error initializing registry configuration: "
-                                 "%s\n", dos_errstr(werr)));
+                                 "%s\n", win_errstr(werr)));
                        conf_ctx = NULL;
                }
        }
@@ -6896,7 +6875,7 @@ static bool handle_netbios_scope(int snum, const char *pszParmValue, char **ptr)
 static bool handle_netbios_aliases(int snum, const char *pszParmValue, char **ptr)
 {
        TALLOC_FREE(Globals.szNetbiosAliases);
-       Globals.szNetbiosAliases = str_list_make(NULL, pszParmValue, NULL);
+       Globals.szNetbiosAliases = str_list_make_v3(talloc_autofree_context(), pszParmValue, NULL);
        return set_netbios_aliases((const char **)Globals.szNetbiosAliases);
 }
 
@@ -7191,14 +7170,24 @@ static void init_copymap(struct service *pservice)
                        bitmap_set(pservice->copymap, i);
 }
 
+/***************************************************************************
+ Return the local pointer to a parameter given a service struct and the
+ pointer into the default structure.
+***************************************************************************/
+
+static void *lp_local_ptr(struct service *service, void *ptr)
+{
+       return (void *)(((char *)service) + PTR_DIFF(ptr, &sDefault));
+}
+
 /***************************************************************************
  Return the local pointer to a parameter given the service number and the 
  pointer into the default structure.
 ***************************************************************************/
 
-void *lp_local_ptr(int snum, void *ptr)
+void *lp_local_ptr_by_snum(int snum, void *ptr)
 {
-       return (void *)(((char *)ServicePtrs[snum]) + PTR_DIFF(ptr, &sDefault));
+       return lp_local_ptr(ServicePtrs[snum], ptr);
 }
 
 /***************************************************************************
@@ -7250,7 +7239,7 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                               pszParmName));
                        return (True);
                }
-               parm_ptr = lp_local_ptr(snum, def_ptr);
+               parm_ptr = lp_local_ptr_by_snum(snum, def_ptr);
        }
 
        if (snum >= 0) {
@@ -7298,8 +7287,8 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
 
                case P_LIST:
                        TALLOC_FREE(*((char ***)parm_ptr));
-                       *(char ***)parm_ptr = str_list_make(
-                               NULL, pszParmValue, NULL);
+                       *(char ***)parm_ptr = str_list_make_v3(
+                               talloc_autofree_context(), pszParmValue, NULL);
                        break;
 
                case P_STRING:
@@ -9505,3 +9494,18 @@ int lp_min_receive_file_size(void)
        }
        return MIN(Globals.iminreceivefile, BUFFER_SIZE);
 }
+
+/*******************************************************************
+ If socket address is an empty character string, it is necessary to 
+ define it as "0.0.0.0". 
+********************************************************************/
+
+const char *lp_socket_address(void)
+{
+       char *sock_addr = Globals.szSocketAddress;
+       
+       if (sock_addr[0] == '\0'){
+               string_set(&Globals.szSocketAddress, "0.0.0.0");
+       }
+       return  Globals.szSocketAddress;
+}