Merge branch 'master' of git://git.samba.org/samba
[ira/wip.git] / source3 / web / statuspage.c
index f4f84cd239bfe57d88d015dca6e24aae43316820..e684a075c25228762bdccf994dfdebdca84a32b1 100644 (file)
@@ -20,6 +20,8 @@
 #include "includes.h"
 #include "web/swat_proto.h"
 
+#define _(x) lang_msg_rotate(talloc_tos(),x)
+
 #define PIDMAP         struct PidMap
 
 /* how long to wait for start/stops to take effect */
@@ -41,9 +43,10 @@ static void initPid2Machine (void)
 {
        /* show machine name rather PID on table "Open Files"? */
        if (PID_or_Machine) {
-               PIDMAP *p;
+               PIDMAP *p, *next;
 
-               for (p = pidmap; p != NULL; ) {
+               for (p = pidmap; p != NULL; p = next) {
+                       next = p->next;
                        DLIST_REMOVE(pidmap, p);
                        SAFE_FREE(p->machine);
                        SAFE_FREE(p);
@@ -54,7 +57,7 @@ static void initPid2Machine (void)
 }
 
 /* add new PID <-> Machine name mapping */
-static void addPid2Machine (struct server_id pid, char *machine)
+static void addPid2Machine (struct server_id pid, const char *machine)
 {
        /* show machine name rather PID on table "Open Files"? */
        if (PID_or_Machine) {
@@ -97,11 +100,20 @@ static char *mapPid2Machine (struct server_id pid)
        return pidbuf;
 }
 
-static char *tstring(time_t t)
+static const char *tstring(TALLOC_CTX *ctx, time_t t)
 {
-       static pstring buf;
-       pstrcpy(buf, time_to_asc(t));
-       all_string_sub(buf," ","&nbsp;",sizeof(buf));
+       char *buf;
+       buf = talloc_strdup(ctx, time_to_asc(t));
+       if (!buf) {
+               return "";
+       }
+       buf = talloc_all_string_sub(ctx,
+                       buf,
+                       " ",
+                       "&nbsp;");
+       if (!buf) {
+               return "";
+       }
        return buf;
 }
 
@@ -112,6 +124,7 @@ static void print_share_mode(const struct share_mode_entry *e,
 {
        char           *utf8_fname;
        int deny_mode;
+       size_t converted_size;
 
        if (!is_valid_share_mode_entry(e)) {
                return;
@@ -158,9 +171,9 @@ static void print_share_mode(const struct share_mode_entry *e,
                printf("NONE            ");
        printf("</td>");
 
-       push_utf8_allocate(&utf8_fname, fname);
+       push_utf8_allocate(&utf8_fname, fname, &converted_size);
        printf("<td>%s</td><td>%s</td></tr>\n",
-              utf8_fname,tstring(e->time.tv_sec));
+              utf8_fname,tstring(talloc_tos(),e->time.tv_sec));
        SAFE_FREE(utf8_fname);
 }
 
@@ -197,7 +210,7 @@ static int traverse_fn2(struct db_record *rec,
        printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td>\n",
               procid_str_static(&crec->pid),
               crec->machine, crec->addr,
-              tstring(crec->start));
+              tstring(talloc_tos(),crec->start));
        if (geteuid() == 0) {
                printf("<td><input type=submit value=\"X\" name=\"kill_%s\"></td>\n",
                       procid_str_static(&crec->pid));
@@ -220,7 +233,7 @@ static int traverse_fn3(struct db_record *rec,
               crec->servicename, uidtoname(crec->uid),
               gidtoname(crec->gid),procid_str_static(&crec->pid),
               crec->machine,
-              tstring(crec->start));
+              tstring(talloc_tos(),crec->start));
        return 0;
 }
 
@@ -232,7 +245,8 @@ void status_page(void)
        int autorefresh=0;
        int refresh_interval=30;
        int nr_running=0;
-       BOOL waitup = False;
+       bool waitup = False;
+       TALLOC_CTX *ctx = talloc_stackframe();
 
        smbd_pid = pid_to_procid(pidfile_pid("smbd"));
 
@@ -309,7 +323,7 @@ void status_page(void)
        }
 
        connections_forall(traverse_fn1, NULL);
+
        initPid2Machine ();
 
        printf("<H2>%s</H2>\n", _("Server Status"));
@@ -415,7 +429,7 @@ void status_page(void)
        printf("<table border=1>\n");
        printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n", _("PID"), _("Sharing"), _("R/W"), _("Oplock"), _("File"), _("Date"));
 
-       locking_init(1);
+       locking_init_readonly();
        share_mode_forall(print_share_mode, NULL);
        locking_end();
        printf("</table>\n");
@@ -436,4 +450,5 @@ void status_page(void)
                       refresh_interval*1000);
                printf("//-->\n</script>\n");
        }
+       TALLOC_FREE(ctx);
 }