Extend a comment.
[samba.git] / source3 / param / loadparm.c
index bc5fe5e8f14e311e2d3c07d049d20cb69b814d17..358fabfb2a416e21e8571445ea9eefc0958d0c4a 100644 (file)
@@ -88,8 +88,6 @@ static bool include_registry_globals = False;
 #define USERSHARE_VALID 1
 #define USERSHARE_PENDING_DELETE 2
 
-bool use_getwd_cache = True;
-
 extern int extra_time_offset;
 
 static bool defaults_saved = False;
@@ -215,6 +213,7 @@ typedef struct {
        int pwordlevel;
        int unamelevel;
        int deadtime;
+       bool getwd_cache;
        int maxprotocol;
        int minprotocol;
        int security;
@@ -473,6 +472,7 @@ typedef struct {
        int iAioWriteSize;
        int iMap_readonly;
        int iDirectoryNameCacheSize;
+       int ismb_encrypt;
        param_opt_struct *param_opt;
 
        char dummy[3];          /* for alignment */
@@ -618,6 +618,7 @@ static service sDefault = {
 #else
        100,                    /* iDirectoryNameCacheSize */
 #endif
+       Auto,                   /* ismb_encrypt */
        NULL,                   /* Parametric options */
 
        ""                      /* dummy */
@@ -627,7 +628,7 @@ static service sDefault = {
 static service **ServicePtrs = NULL;
 static int iNumServices = 0;
 static int iServiceIndex = 0;
-static TDB_CONTEXT *ServiceHash;
+static struct db_context *ServiceHash;
 static int *invalid_services = NULL;
 static int num_invalid_services = 0;
 static bool bInGlobalSection = True;
@@ -1028,6 +1029,7 @@ static struct parm_struct parm_table[] = {
        {"use spnego", P_BOOL, P_GLOBAL, &Globals.bUseSpnego, NULL, NULL, FLAG_ADVANCED}, 
        {"client signing", P_ENUM, P_GLOBAL, &Globals.client_signing, NULL, enum_smb_signing_vals, FLAG_ADVANCED}, 
        {"server signing", P_ENUM, P_GLOBAL, &Globals.server_signing, NULL, enum_smb_signing_vals, FLAG_ADVANCED}, 
+       {"smb encrypt", P_ENUM, P_LOCAL, &sDefault.ismb_encrypt, NULL, enum_smb_signing_vals, FLAG_ADVANCED},
        {"client use spnego", P_BOOL, P_GLOBAL, &Globals.bClientUseSpnego, NULL, NULL, FLAG_ADVANCED}, 
        {"client ldap sasl wrapping", P_ENUM, P_GLOBAL, &Globals.client_ldap_sasl_wrapping, NULL, enum_ldap_sasl_wrapping, FLAG_ADVANCED},
        {"enable asu support", P_BOOL, P_GLOBAL, &Globals.bASUSupport, NULL, NULL, FLAG_ADVANCED}, 
@@ -1037,7 +1039,7 @@ static struct parm_struct parm_table[] = {
 
        {"block size", P_INTEGER, P_LOCAL, &sDefault.iBlock_size, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE | FLAG_GLOBAL}, 
        {"deadtime", P_INTEGER, P_GLOBAL, &Globals.deadtime, NULL, NULL, FLAG_ADVANCED}, 
-       {"getwd cache", P_BOOL, P_GLOBAL, &use_getwd_cache, NULL, NULL, FLAG_ADVANCED}, 
+       {"getwd cache", P_BOOL, P_GLOBAL, &Globals.getwd_cache, NULL, NULL, FLAG_ADVANCED},
        {"keepalive", P_INTEGER, P_GLOBAL, &Globals.iKeepalive, NULL, NULL, FLAG_ADVANCED},
        {"change notify", P_BOOL, P_LOCAL, &sDefault.bChangeNotify, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE },
        {"directory name cache size", P_INTEGER, P_LOCAL, &sDefault.iDirectoryNameCacheSize, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE },
@@ -1456,8 +1458,8 @@ static void init_globals(bool first_time_only)
 
        DEBUG(3, ("Initialising global parameters\n"));
 
-       string_set(&Globals.szSMBPasswdFile, dyn_SMB_PASSWD_FILE);
-       string_set(&Globals.szPrivateDir, dyn_PRIVATE_DIR);
+       string_set(&Globals.szSMBPasswdFile, get_dyn_SMB_PASSWD_FILE());
+       string_set(&Globals.szPrivateDir, get_dyn_PRIVATE_DIR());
 
        /* use the new 'hash2' method by default, with a prefix of 1 */
        string_set(&Globals.szManglingMethod, "hash2");
@@ -1491,8 +1493,8 @@ static void init_globals(bool first_time_only)
        string_set(&Globals.szWorkgroup, lp_workgroup());
 
        string_set(&Globals.szPasswdProgram, "");
-       string_set(&Globals.szPidDir, dyn_PIDDIR);
-       string_set(&Globals.szLockDir, dyn_LOCKDIR);
+       string_set(&Globals.szPidDir, get_dyn_PIDDIR());
+       string_set(&Globals.szLockDir, get_dyn_LOCKDIR());
        string_set(&Globals.szSocketAddress, "0.0.0.0");
 
        if (asprintf(&s, "Samba %s", SAMBA_VERSION_STRING) < 0) {
@@ -1535,6 +1537,7 @@ static void init_globals(bool first_time_only)
        Globals.pwordlevel = 0;
        Globals.unamelevel = 0;
        Globals.deadtime = 0;
+       Globals.getwd_cache = true;
        Globals.bLargeReadwrite = True;
        Globals.max_log_size = 5000;
        Globals.max_open_files = MAX_OPEN_FILES;
@@ -1701,7 +1704,7 @@ static void init_globals(bool first_time_only)
        Globals.bASUSupport       = False;
 
        /* User defined shares. */
-       if (asprintf(&s, "%s/usershares", dyn_STATEDIR()) < 0) {
+       if (asprintf(&s, "%s/usershares", get_dyn_STATEDIR()) < 0) {
                smb_panic("init_globals: ENOMEM");
        }
        string_set(&Globals.szUsersharePath, s);
@@ -1729,7 +1732,8 @@ static void init_globals(bool first_time_only)
 
 static char *lp_string(const char *s)
 {
-       char *ret, *tmpstr;
+       char *ret;
+       TALLOC_CTX *ctx = talloc_tos();
 
        /* The follow debug is useful for tracking down memory problems
           especially if you have an inner loop that is calling a lp_*()
@@ -1740,19 +1744,20 @@ static char *lp_string(const char *s)
        DEBUG(10, ("lp_string(%s)\n", s));
 #endif
 
-       tmpstr = alloc_sub_basic(get_current_username(),
-                                current_user_info.domain, s);
-       if (trim_char(tmpstr, '\"', '\"')) {
-               if (strchr(tmpstr,'\"') != NULL) {
-                       SAFE_FREE(tmpstr);
-                       tmpstr = alloc_sub_basic(get_current_username(),
-                                                current_user_info.domain, s);
+       ret = talloc_sub_basic(ctx,
+                       get_current_username(),
+                       current_user_info.domain,
+                       s);
+       if (trim_char(ret, '\"', '\"')) {
+               if (strchr(ret,'\"') != NULL) {
+                       TALLOC_FREE(ret);
+                       ret = talloc_sub_basic(ctx,
+                                       get_current_username(),
+                                       current_user_info.domain,
+                                       s);
                }
        }
-       ret = talloc_strdup(talloc_tos(), tmpstr);
-       SAFE_FREE(tmpstr);
-                       
-       return (ret);
+       return ret;
 }
 
 /*
@@ -2021,6 +2026,7 @@ FN_GLOBAL_INTEGER(lp_maxmux, &Globals.max_mux)
 FN_GLOBAL_INTEGER(lp_passwordlevel, &Globals.pwordlevel)
 FN_GLOBAL_INTEGER(lp_usernamelevel, &Globals.unamelevel)
 FN_GLOBAL_INTEGER(lp_deadtime, &Globals.deadtime)
+FN_GLOBAL_BOOL(lp_getwd_cache, &Globals.getwd_cache)
 FN_GLOBAL_INTEGER(lp_maxprotocol, &Globals.maxprotocol)
 FN_GLOBAL_INTEGER(lp_minprotocol, &Globals.minprotocol)
 FN_GLOBAL_INTEGER(lp_security, &Globals.security)
@@ -2170,6 +2176,7 @@ FN_LOCAL_INTEGER(lp_aio_read_size, iAioReadSize)
 FN_LOCAL_INTEGER(lp_aio_write_size, iAioWriteSize)
 FN_LOCAL_INTEGER(lp_map_readonly, iMap_readonly)
 FN_LOCAL_INTEGER(lp_directory_name_cache_size, iDirectoryNameCacheSize)
+FN_LOCAL_INTEGER(lp_smb_encrypt, ismb_encrypt)
 FN_LOCAL_CHAR(lp_magicchar, magic_char)
 FN_GLOBAL_INTEGER(lp_winbind_cache_time, &Globals.winbind_cache_time)
 FN_GLOBAL_LIST(lp_winbind_nss_info, &Globals.szWinbindNssInfo)
@@ -2512,9 +2519,11 @@ static void free_service_byindex(int idx)
        /* we have to cleanup the hash record */
 
        if (ServicePtrs[idx]->szService) {
-               char *canon_name = canonicalize_servicename( ServicePtrs[idx]->szService );
+               char *canon_name = canonicalize_servicename(
+                       ServicePtrs[idx]->szService );
                
-               tdb_delete_bystring(ServiceHash, canon_name );
+               dbwrap_delete_bystring(ServiceHash, canon_name );
+               TALLOC_FREE(canon_name);
        }
 
        free_service(ServicePtrs[idx]);
@@ -2614,17 +2623,18 @@ static int add_a_service(const service *pservice, const char *name)
 
 static char *canonicalize_servicename(const char *src)
 {
-       static fstring canon; /* is fstring large enough? */
+       char *result;
 
        if ( !src ) {
                DEBUG(0,("canonicalize_servicename: NULL source name!\n"));
                return NULL;
        }
 
-       fstrcpy( canon, src );
-       strlower_m( canon );
+       result = talloc_strdup(talloc_tos(), src);
+       SMB_ASSERT(result != NULL);
 
-       return canon;
+       strlower_m(result);
+       return result;
 }
 
 /***************************************************************************
@@ -2636,9 +2646,8 @@ static bool hash_a_service(const char *name, int idx)
        char *canon_name;
 
        if ( !ServiceHash ) {
-               DEBUG(10,("hash_a_service: creating tdb servicehash\n"));
-               ServiceHash = tdb_open("servicehash", 1031, TDB_INTERNAL, 
-                                        (O_RDWR|O_CREAT), 0600);
+               DEBUG(10,("hash_a_service: creating servicehash\n"));
+               ServiceHash = db_open_rbt(NULL);
                if ( !ServiceHash ) {
                        DEBUG(0,("hash_a_service: open tdb servicehash failed!\n"));
                        return False;
@@ -2648,10 +2657,13 @@ static bool hash_a_service(const char *name, int idx)
        DEBUG(10,("hash_a_service: hashing index %d for service name %s\n",
                idx, name));
 
-       if ( !(canon_name = canonicalize_servicename( name )) )
-               return False;
+       canon_name = canonicalize_servicename( name );
 
-        tdb_store_int32(ServiceHash, canon_name, idx);
+       dbwrap_store_bystring(ServiceHash, canon_name,
+                             make_tdb_data((uint8 *)&idx, sizeof(idx)),
+                             TDB_REPLACE);
+
+       TALLOC_FREE(canon_name);
 
        return True;
 }
@@ -2998,8 +3010,8 @@ static void show_parameter(int parmIndex)
        bool hadSyn;
        bool inverse;
        const char *type[] = { "P_BOOL", "P_BOOLREV", "P_CHAR", "P_INTEGER",
-               "P_OCTAL", "P_LIST", "P_STRING", "P_USTRING", "P_GSTRING",
-               "P_UGSTRING", "P_ENUM", "P_SEP"};
+               "P_OCTAL", "P_LIST", "P_STRING", "P_USTRING",
+               "P_ENUM", "P_SEP"};
        unsigned flags[] = { FLAG_BASIC, FLAG_SHARE, FLAG_PRINT, FLAG_GLOBAL,
                FLAG_WIZARD, FLAG_ADVANCED, FLAG_DEVELOPER, FLAG_DEPRECATED,
                FLAG_HIDE, FLAG_DOS_STRING};
@@ -3175,20 +3187,25 @@ static int getservicebyname(const char *pszServiceName, service * pserviceDest)
 {
        int iService = -1;
        char *canon_name;
+       TDB_DATA data;
 
-       if (ServiceHash != NULL) {
-               if ( !(canon_name = canonicalize_servicename( pszServiceName )) )
-                       return -1;
+       if (ServiceHash == NULL) {
+               return -1;
+       }
 
-               iService = tdb_fetch_int32(ServiceHash, canon_name );
+       canon_name = canonicalize_servicename(pszServiceName);
 
-               if (LP_SNUM_OK(iService)) {
-                       if (pserviceDest != NULL) {
-                               copy_service(pserviceDest, ServicePtrs[iService], NULL);
-                       }
-               } else {
-                       iService = -1;
-               }
+       data = dbwrap_fetch_bystring(ServiceHash, canon_name, canon_name);
+
+       if ((data.dptr != NULL) && (data.dsize == sizeof(iService))) {
+               iService = *(int *)data.dptr;
+       }
+
+       TALLOC_FREE(canon_name);
+
+       if ((iService != -1) && (LP_SNUM_OK(iService))
+           && (pserviceDest != NULL)) {
+               copy_service(pserviceDest, ServicePtrs[iService], NULL);
        }
 
        return (iService);
@@ -3460,7 +3477,7 @@ static bool process_registry_globals(bool (*pfunc)(const char *, const char *))
                if (size && data_p) {
                        err = registry_pull_value(reg_tdb,
                                                  &value,
-                                                 type,
+                                                 (enum winreg_Type)type,
                                                  data_p,
                                                  size,
                                                  size);
@@ -3497,7 +3514,9 @@ done:
 /*
  * this is process_registry_globals as it _should_ be (roughly)
  * using the reg_api functions...
- * 
+ *
+ * We are *not* currently doing it like this due to the large
+ * linker dependecies of the registry code (see above).
  */
 static bool process_registry_globals(bool (*pfunc)(const char *, const char *))
 {
@@ -3617,6 +3636,11 @@ static void add_to_file_list(const char *fname, const char *subfname)
        }
 }
 
+bool lp_include_registry_globals(void)
+{
+       return include_registry_globals;
+}
+
 /*******************************************************************
  Check if a config file has changed date.
 ********************************************************************/
@@ -4169,15 +4193,6 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                        strupper_m(*(char **)parm_ptr);
                        break;
 
-               case P_GSTRING:
-                       pstrcpy((char *)parm_ptr, pszParmValue);
-                       break;
-
-               case P_UGSTRING:
-                       pstrcpy((char *)parm_ptr, pszParmValue);
-                       strupper_m((char *)parm_ptr);
-                       break;
-
                case P_ENUM:
                        lp_set_enum_parm( &parm_table[parmnum], pszParmValue, (int*)parm_ptr );
                        break;
@@ -4238,14 +4253,16 @@ static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
                        fprintf(f, "%c", *(char *)ptr);
                        break;
 
-               case P_OCTAL:
-                       fprintf(f, "%s", octal_string(*(int *)ptr));
+               case P_OCTAL: {
+                       char *o = octal_string(*(int *)ptr);
+                       fprintf(f, "%s", o);
+                       TALLOC_FREE(o);
                        break;
+               }
 
                case P_LIST:
                        if ((char ***)ptr && *(char ***)ptr) {
                                char **list = *(char ***)ptr;
-                               
                                for (; *list; list++) {
                                        /* surround strings with whitespace in double quotes */
                                        if ( strchr_m( *list, ' ' ) )
@@ -4256,13 +4273,6 @@ static void print_parameter(struct parm_struct *p, void *ptr, FILE * f)
                        }
                        break;
 
-               case P_GSTRING:
-               case P_UGSTRING:
-                       if ((char *)ptr) {
-                               fprintf(f, "%s", (char *)ptr);
-                       }
-                       break;
-
                case P_STRING:
                case P_USTRING:
                        if (*(char **)ptr) {
@@ -4292,20 +4302,10 @@ static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
 
                case P_CHAR:
                        return (*((char *)ptr1) == *((char *)ptr2));
-               
+
                case P_LIST:
                        return str_list_compare(*(char ***)ptr1, *(char ***)ptr2);
 
-               case P_GSTRING:
-               case P_UGSTRING:
-               {
-                       char *p1 = (char *)ptr1, *p2 = (char *)ptr2;
-                       if (p1 && !*p1)
-                               p1 = NULL;
-                       if (p2 && !*p2)
-                               p2 = NULL;
-                       return (p1 == p2 || strequal(p1, p2));
-               }
                case P_STRING:
                case P_USTRING:
                {
@@ -4399,10 +4399,6 @@ static bool is_default(int i)
                case P_USTRING:
                        return strequal(parm_table[i].def.svalue,
                                        *(char **)parm_table[i].ptr);
-               case P_GSTRING:
-               case P_UGSTRING:
-                       return strequal(parm_table[i].def.svalue,
-                                       (char *)parm_table[i].ptr);
                case P_BOOL:
                case P_BOOLREV:
                        return parm_table[i].def.bvalue ==
@@ -4712,13 +4708,17 @@ static void lp_add_auto_services(char *str)
        homes = lp_servicenumber(HOMES_NAME);
 
        for (p = strtok(s, LIST_SEP); p; p = strtok(NULL, LIST_SEP)) {
-               char *home = get_user_home_dir(p);
+               char *home;
 
                if (lp_servicenumber(p) >= 0)
                        continue;
 
+               home = get_user_home_dir(talloc_tos(), p);
+
                if (home && homes >= 0)
                        lp_add_home(p, homes, p, home);
+
+               TALLOC_FREE(home);
        }
        SAFE_FREE(s);
 }
@@ -4809,14 +4809,6 @@ static void lp_save_defaults(void)
                                        parm_table[i].def.svalue = NULL;
                                }
                                break;
-                       case P_GSTRING:
-                       case P_UGSTRING:
-                               if (parm_table[i].ptr) {
-                                       parm_table[i].def.svalue = SMB_STRDUP((char *)parm_table[i].ptr);
-                               } else {
-                                       parm_table[i].def.svalue = NULL;
-                               }
-                               break;
                        case P_BOOL:
                        case P_BOOLREV:
                                parm_table[i].def.bvalue =
@@ -5203,9 +5195,18 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i
                return -1;
        }
 
-       /* See if there is already a servicenum for this name. */
-       /* tdb_fetch_int32 returns -1 if not found. */
-       iService = (int)tdb_fetch_int32(ServiceHash, canonicalize_servicename(service_name) );
+       {
+               char *canon_name = canonicalize_servicename(service_name);
+               TDB_DATA data = dbwrap_fetch_bystring(
+                       ServiceHash, canon_name, canon_name);
+
+               iService = -1;
+
+               if ((data.dptr != NULL) && (data.dsize == sizeof(iService))) {
+                       iService = *(int *)data.dptr;
+               }
+               TALLOC_FREE(canon_name);
+       }
 
        if (iService != -1 && ServicePtrs[iService]->usershare_last_mod == lsbuf.st_mtime) {
                /* Nothing changed - Mark valid and return. */
@@ -6151,7 +6152,7 @@ const char *lp_printername(int snum)
 void lp_set_logfile(const char *name)
 {
        string_set(&Globals.szLogFile, name);
-       pstrcpy(debugf, name);
+       debug_set_logfile(name);
 }
 
 /*******************************************************************
@@ -6223,7 +6224,9 @@ bool lp_use_sendfile(int snum)
        if (Protocol < PROTOCOL_NT1) {
                return False;
        }
-       return (_lp_use_sendfile(snum) && (get_remote_arch() != RA_WIN95) && !srv_is_signing_active());
+       return (_lp_use_sendfile(snum) &&
+                       (get_remote_arch() != RA_WIN95) &&
+                       !srv_is_signing_active());
 }
 
 /*******************************************************************