sync 3.0 branch with HEAD
authorJelmer Vernooij <jelmer@samba.org>
Sat, 17 Aug 2002 14:34:48 +0000 (14:34 +0000)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 17 Aug 2002 14:34:48 +0000 (14:34 +0000)
(This used to be commit d53d77cc8e21dfbfd376d529661ef299e14e31a0)

source3/web/diagnose.c
source3/web/neg_lang.c
source3/web/startstop.c
source3/web/statuspage.c
source3/web/swat.c

index e822474aab4187c59c6c7fcea50d9949c6c0c210..396499bcb9e9905dcce2fceb45e6c21a5783054f 100644 (file)
 #include "includes.h"
 #include "../web/swat_proto.h"
 
+#ifdef WITH_WINBIND
+
+NSS_STATUS winbindd_request(int req_type,
+                       struct winbindd_request *request,
+                       struct winbindd_response *response);
+
+/* check to see if winbind is running by pinging it */
+
+BOOL winbindd_running(void)
+{
+
+       if (winbindd_request(WINBINDD_PING, NULL, NULL))
+               return False;
+
+       return True;
+}      
+#endif
 
 /* check to see if nmbd is running on localhost by looking for a __SAMBA__
    response */
index 88bc5498e92374bef689a5f99d9776df278668e0..da974f78a4a0a542bd9a0502179d4683a5e53611 100644 (file)
@@ -48,20 +48,70 @@ int web_open(const char *fname, int flags, mode_t mode)
 }
 
 
+struct pri_list {
+       float pri;
+       char *string;
+};
+
+static int qsort_cmp_list(const void *x, const void *y) {
+       struct pri_list *a = (struct pri_list *)x;
+       struct pri_list *b = (struct pri_list *)y;
+       if (a->pri > b->pri) return -1;
+       if (a->pri == b->pri) return 0;
+       return 1;
+}
+
 /*
   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;
+       struct pri_list *pl;
+       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++;
        }
-       
+       pl = (struct pri_list *)malloc(sizeof(struct pri_list) * 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;
+                       sscanf(pri_code, "%f", &(pl[i].pri));
+               } else {
+                       pl[i].pri = 1;
+               }
+               pl[i].string = strdup(lang_list[i]);
+       }
+       str_list_free(&lang_list);
+
+       qsort(pl, lang_num, sizeof(struct pri_list), &qsort_cmp_list);
+
        /* it's not an error to not initialise - we just fall back to 
           the default */
+
+       for (i = 0; i < lang_num; i++) {
+               if (lang_tdb_init(pl[i].string)) break;
+       }
+
+       for (i = 0; i < lang_num; i++) {
+               SAFE_FREE(pl[i].string);
+       }
+       SAFE_FREE(pl);
+
+       return;
 }
index 893784dd55e175030bfbf1a0ecf33b5fb06fa443..e10dff411806cca65136ce30916ebc164eb7e16b 100644 (file)
@@ -67,6 +67,27 @@ void start_nmbd(void)
        exit(0);
 }
 
+/** Startup winbindd from web interface. */
+void start_winbindd(void)
+{
+       pstring binfile;
+
+       if (geteuid() != 0) return;
+
+       if (fork()) {
+               sleep(SLEEP_TIME);
+               return;
+       }
+
+       slprintf(binfile, sizeof(pstring) - 1, "%s/winbindd", dyn_SBINDIR);
+
+       become_daemon();
+
+       execl(binfile, binfile, NULL);
+
+       exit(0);
+}
+
 
 /* stop smbd */
 void stop_smbd(void)
@@ -91,7 +112,19 @@ void stop_nmbd(void)
 
        kill(pid, SIGTERM);
 }
+#ifdef WITH_WINBIND
+/* stop winbindd */
+void stop_winbindd(void)
+{
+       pid_t pid = pidfile_pid("winbindd");
 
+       if (geteuid() != 0) return;
+
+       if (pid <= 0) return;
+
+       kill(pid, SIGTERM);
+}
+#endif
 /* kill a specified process */
 void kill_pid(pid_t pid)
 {
index 792e077a616781786e5f08c4096aec799b544d23..3b597d44c04f970e3df56d7cbdd517b601fc2e02 100644 (file)
@@ -248,6 +248,20 @@ void status_page(void)
                stop_nmbd();
        }
 
+#ifdef WITH_WINBIND
+       if (cgi_variable("winbindd_restart")) {
+               stop_winbindd();
+               start_winbindd();
+       }
+
+       if (cgi_variable("winbindd_start")) {
+               start_winbindd();
+       }
+
+       if (cgi_variable("winbindd_stop")) {
+               stop_winbindd();
+       }
+#endif
        if (cgi_variable("autorefresh")) {
                autorefresh = 1;
        } else if (cgi_variable("norefresh")) {
@@ -320,6 +334,20 @@ void status_page(void)
        }
        d_printf("</tr>\n");
 
+#ifdef WITH_WINBIND
+       fflush(stdout);
+       d_printf("<tr><td>%s</td><td>%s</td>\n", _("winbindd:"), winbindd_running()?_("running"):_("not running"));
+       if (geteuid() == 0) {
+           if (winbindd_running()) {
+               d_printf("<td><input type=submit name=\"winbindd_stop\" value=\"%s\"></td>\n", _("Stop winbindd"));
+           } else {
+               d_printf("<td><input type=submit name=\"winbindd_start\" value=\"%s\"></td>\n", _("Start winbindd"));
+           }
+           d_printf("<td><input type=submit name=\"winbindd_restart\" value=\"%s\"></td>\n", _("Restart winbindd"));
+       }
+       d_printf("</tr>\n");
+#endif
+
        d_printf("</table>\n");
        fflush(stdout);
 
index 7be46790dbe98a83aab9194ee7e87a27f3845489..80d3232d2bffedb6912b8f05047b507d790bb708 100644 (file)
@@ -79,15 +79,15 @@ static char *fix_backslash(char *str)
        return newstring;
 }
 
-static char *stripspace(char *str)
+static char *stripspaceupper(char *str)
 {
-static char newstring[1024];
-char *p = newstring;
+       static char newstring[1024];
+       char *p = newstring;
 
-        while (*str) {
-                if (*str != ' ') *p++ = *str;
-                ++str;
-        }
+       while (*str) {
+               if (*str != ' ') *p++ = toupper(*str);
+               ++str;
+       }
        *p = '\0';
        return newstring;
 }
@@ -200,7 +200,7 @@ static void show_parameter(int snum, struct parm_struct *parm)
                ptr = lp_local_ptr(snum, ptr);
        }
 
-       printf("<tr><td>%s</td><td>", get_parm_translated(stripspace(parm->label), _("Help"), parm->label));
+       printf("<tr><td>%s</td><td>", get_parm_translated(stripspaceupper(parm->label), _("Help"), parm->label));
        switch (parm->type) {
        case P_CHAR:
                d_printf("<input type=text size=2 name=\"parm_%s\" value=\"%c\">",