found nasty bug in intl/lang_tdb.c tdb structure was not tested to not be null before...
authorSimo Sorce <idra@samba.org>
Sun, 28 Jul 2002 18:10:39 +0000 (18:10 +0000)
committerSimo Sorce <idra@samba.org>
Sun, 28 Jul 2002 18:10:39 +0000 (18:10 +0000)
this one fixes swat not working with browsers that set more then one language.

along the way implemented language priority in web/neg_lang.c with bubble sort

also changet str_list_make to be able to use a different separator string

Simo.
(This used to be commit 69765e4faa8aaae74c97afc917891fc72d80703d)

source3/auth/auth.c
source3/intl/lang_tdb.c
source3/lib/debug.c
source3/lib/username.c
source3/lib/util_str.c
source3/param/loadparm.c
source3/passdb/pdb_interface.c
source3/smbd/password.c
source3/web/neg_lang.c
source3/wrepld/process.c

index 4f7a5c24a00c6114843ef7de7a1dfe7530042cd0..dca9c6c3c488ed299d3d162f33809c1c150bb3e2 100644 (file)
@@ -395,33 +395,33 @@ NTSTATUS make_auth_context_subsystem(struct auth_context **auth_context)
                {
                case SEC_DOMAIN:
                        DEBUG(5,("Making default auth method list for security=domain\n"));
-                       auth_method_list = str_list_make("guest sam ntdomain");
+                       auth_method_list = str_list_make("guest sam ntdomain", NULL);
                        break;
                case SEC_SERVER:
                        DEBUG(5,("Making default auth method list for security=server\n"));
-                       auth_method_list = str_list_make("guest sam smbserver");
+                       auth_method_list = str_list_make("guest sam smbserver", NULL);
                        break;
                case SEC_USER:
                        if (lp_encrypted_passwords()) { 
                                DEBUG(5,("Making default auth method list for security=user, encrypt passwords = yes\n"));
-                               auth_method_list = str_list_make("guest sam");
+                               auth_method_list = str_list_make("guest sam", NULL);
                        } else {
                                DEBUG(5,("Making default auth method list for security=user, encrypt passwords = no\n"));
-                               auth_method_list = str_list_make("guest unix");
+                               auth_method_list = str_list_make("guest unix", NULL);
                        }
                        break;
                case SEC_SHARE:
                        if (lp_encrypted_passwords()) {
                                DEBUG(5,("Making default auth method list for security=share, encrypt passwords = yes\n"));
-                               auth_method_list = str_list_make("guest sam");
+                               auth_method_list = str_list_make("guest sam", NULL);
                        } else {
                                DEBUG(5,("Making default auth method list for security=share, encrypt passwords = no\n"));
-                               auth_method_list = str_list_make("guest unix");
+                               auth_method_list = str_list_make("guest unix", NULL);
                        }
                        break;
                case SEC_ADS:
                        DEBUG(5,("Making default auth method list for security=ADS\n"));
-                       auth_method_list = str_list_make("guest sam ads ntdomain");
+                       auth_method_list = str_list_make("guest sam ads ntdomain", NULL);
                        break;
                default:
                        DEBUG(5,("Unknown auth method!\n"));
index d5e8bd41bd5b6c280c027a77e79c1384181299b0..a86ea0a3f9a8cad5e0d716a0f7c44c6ed373b355 100644 (file)
@@ -106,8 +106,10 @@ BOOL lang_tdb_init(const char *lang)
 
        if (initialised) {
                /* we are re-initialising, free up any old init */
-               tdb_close(tdb);
-               tdb = NULL;
+               if (tdb) {
+                       tdb_close(tdb);
+                       tdb = NULL;
+               }
                SAFE_FREE(current_lang);
        }
 
index be5f66a562ab637f94fa7c4037f2d8ff7045492d..842d2dac1d62650b431de0ec459397c855c5006c 100644 (file)
@@ -423,7 +423,7 @@ BOOL debug_parse_levels(const char *params_str)
        if (AllowDebugChange == False)
                return True;
 
-       params = str_list_make(params_str);
+       params = str_list_make(params_str, NULL);
 
        if (debug_parse_params(params, DEBUGLEVEL_CLASS,
                               DEBUGLEVEL_CLASS_ISSET))
index 4813c8fd194c20ba5b2df04c25d6aaa5faab4a54..5db7f58b1e254dd42346b33270bc84e9f11ce00c 100644 (file)
@@ -163,7 +163,7 @@ BOOL map_username(char *user)
                        }
                }
 
-               dosuserlist = str_list_make(dosname);
+               dosuserlist = str_list_make(dosname, NULL);
                if (!dosuserlist) {
                        DEBUG(0,("Unable to build user list\n"));
                        return False;
index 7e974269ece195f958b3f41c5e0293471f0cabe8..9dc80c89dbce7a274da061086131c0426b7cb26e 100644 (file)
@@ -1125,7 +1125,7 @@ some platforms don't have strnlen
 
 #define S_LIST_ABS 16 /* List Allocation Block Size */
 
-char **str_list_make(const char *string)
+char **str_list_make(const char *string, const char *sep)
 {
        char **list, **rlist;
        char *str, *s;
@@ -1139,12 +1139,13 @@ char **str_list_make(const char *string)
                DEBUG(0,("str_list_make: Unable to allocate memory"));
                return NULL;
        }
+       if (!sep) sep = LIST_SEP;
        
        num = lsize = 0;
        list = NULL;
        
        str = s;
-       while (next_token(&str, tok, LIST_SEP, sizeof(tok))) {          
+       while (next_token(&str, tok, sep, sizeof(tok))) {               
                if (num == lsize) {
                        lsize += S_LIST_ABS;
                        rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
index 445663f5474868e49f388a5f49e67fdbbeebebac..64542cd153d9526030ba4b56facba11dc64d94e2 100644 (file)
@@ -1194,7 +1194,7 @@ static void init_globals(void)
 
        string_set(&Globals.szSMBPasswdFile, dyn_SMB_PASSWD_FILE);
        string_set(&Globals.szPrivateDir, dyn_PRIVATE_DIR);
-       Globals.szPassdbBackend = str_list_make("smbpasswd unixsam");
+       Globals.szPassdbBackend = str_list_make("smbpasswd unixsam", NULL);
 
        /* use the new 'hash2' method by default */
        string_set(&Globals.szManglingMethod, "hash2");
@@ -2850,7 +2850,7 @@ BOOL lp_do_parameter(int snum, char *pszParmName, char *pszParmValue)
                        break;
 
                case P_LIST:
-                       *(char ***)parm_ptr = str_list_make(pszParmValue);
+                       *(char ***)parm_ptr = str_list_make(pszParmValue, NULL);
                        break;
 
                case P_STRING:
index 3b0f54b2b3ac037d3126d969fefc30436fe18639..daa3222c5a0f1f5c5f01ec13d582cc5bc8fb176f 100644 (file)
@@ -353,7 +353,7 @@ NTSTATUS make_pdb_context_list(struct pdb_context **context, char **selected)
 NTSTATUS make_pdb_context_string(struct pdb_context **context, const char *selected) 
 {
        NTSTATUS ret;
-       char **newsel = str_list_make(selected);
+       char **newsel = str_list_make(selected, NULL);
        ret = make_pdb_context_list(context, newsel);
        str_list_free(&newsel);
        return ret;
index 391de02dea80ff81abc1ececd107795c2c67fa20..2558ffe16339deb504bf685fb98e92eafc42f62c 100644 (file)
@@ -351,7 +351,7 @@ BOOL user_ok(const char *user,int snum)
        if (valid) str_list_free (&valid);
 
        if (ret && lp_onlyuser(snum)) {
-               char **user_list = str_list_make (lp_username(snum));
+               char **user_list = str_list_make (lp_username(snum), NULL);
                if (user_list && str_list_substitute(user_list, "%S", lp_servicename(snum))) {
                        ret = user_in_list(user, user_list);
                }
index 88bc5498e92374bef689a5f99d9776df278668e0..72dd70fd9834d4c993f6414a873cbef7ee2a8f72 100644 (file)
@@ -52,14 +52,54 @@ int web_open(const char *fname, int flags, mode_t mode)
   choose from a list of languages. The list can be comma or space
   separated
   Keep choosing until we get a hit 
+  Changed to habdle priority -- Simo
 */
-void web_set_lang(const char *lang_list)
+void web_set_lang(const char *lang_string)
 {
-       fstring lang;
-       char *p = (char *)lang_list;
+       char **lang_list, **count;
+       float *pri;
+       int lang_num, i;
+
+       /* build the lang list */
+       lang_list = str_list_make(lang_string, ", \t\r\n");
+       if (!lang_list) return;
        
-       while (next_token(&p, lang, ", \t\r\n", sizeof(lang))) {
-               if (lang_tdb_init(lang)) return;
+       /* sort the list by priority */
+       lang_num = 0;
+       count = lang_list;
+       while (*count && **count) {
+               count++;
+               lang_num++;
+       }
+       pri = (float *)malloc(sizeof(float) * lang_num);
+       for (i = 0; i < lang_num; i++) {
+               char *pri_code;
+               if ((pri_code=strstr(lang_list[i], ";q="))) {
+                       *pri_code = '\0';
+                       pri_code += 3;
+                       pri[i] = strtof(pri_code, NULL);
+               } else {
+                       pri[i] = 1;
+               }
+               if (i != 0) {
+                       int l;
+                       for (l = i; l > 0; l--) {
+                               if (pri[l] > pri[l-1]) {
+                                       char *tempc;
+                                       int tempf;
+                                       tempc = lang_list[l];
+                                       tempf = pri[l];
+                                       lang_list[l] = lang_list[l-1];
+                                       pri[i] = pri[l-1];
+                                       lang_list[l-1] = tempc;
+                                       pri[l-1] = tempf;
+                               }
+                       }
+                }
+       }
+
+       for (i = 0; i < lang_num; i++) {
+               if (lang_tdb_init(lang_list[i])) return;
        }
        
        /* it's not an error to not initialise - we just fall back to 
index 7615b8c78a1372a64736abfcd0f1b7ac231c3be6..56013d2e175fb7d0f182625bf57b6e8bfc7f70b5 100644 (file)
@@ -152,7 +152,7 @@ initialise and fill the in-memory partner table.
 int init_wins_partner_table(void)
 {
        int i=1,j=0,k;
-       char **partner = str_list_make(lp_wins_partners());
+       char **partner = str_list_make(lp_wins_partners(), NULL);
 
        if (partner==NULL) {
                DEBUG(0,("wrepld: no partner list in smb.conf, exiting\n"));