GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "web/swat_proto.h"
+#include "libcli/security/security.h"
+#include "locking/proto.h"
+#include "librpc/gen_ndr/open_files.h"
+#include "lib/conn_tdb.h"
+#include "../lib/util/pidfile.h"
+
+#define _(x) lang_msg_rotate(talloc_tos(),x)
#define PIDMAP struct PidMap
{
/* 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);
}
/* 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) {
/* show machine name rather PID on table "Open Files"? */
if (PID_or_Machine) {
for (map = pidmap; map != NULL; map = map->next) {
- if (procid_equal(&pid, &map->pid)) {
+ if (serverid_equal(&pid, &map->pid)) {
if (map->machine == NULL) /* no machine name */
break; /* show 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," "," ",sizeof(buf));
+ char *buf;
+ buf = talloc_strdup(ctx, time_to_asc(t));
+ if (!buf) {
+ return "";
+ }
+ buf = talloc_all_string_sub(ctx,
+ buf,
+ " ",
+ " ");
+ if (!buf) {
+ return "";
+ }
return buf;
}
void *dummy)
{
char *utf8_fname;
+ char *utf8_sharepath;
int deny_mode;
+ size_t converted_size;
if (!is_valid_share_mode_entry(e)) {
return;
printf("NONE ");
printf("</td>");
- push_utf8_allocate(&utf8_fname, fname);
- printf("<td>%s</td><td>%s</td></tr>\n",
- utf8_fname,tstring(e->time.tv_sec));
- SAFE_FREE(utf8_fname);
+ push_utf8_talloc(talloc_tos(), &utf8_fname, fname, &converted_size);
+ push_utf8_talloc(talloc_tos(), &utf8_sharepath, sharepath,
+ &converted_size);
+ printf("<td>%s</td><td>%s</td><td>%s</td></tr>\n",
+ utf8_sharepath,utf8_fname,tstring(talloc_tos(),e->time.tv_sec));
+ TALLOC_FREE(utf8_fname);
}
/* kill off any connections chosen by the user */
-static int traverse_fn1(struct db_record *rec,
- const struct connections_key *key,
+static int traverse_fn1(const struct connections_key *key,
const struct connections_data *crec,
void *private_data)
{
- if (crec->cnum == -1 && process_exists(crec->pid)) {
+ if (crec->cnum == TID_FIELD_INVALID && process_exists(crec->pid)) {
char buf[30];
slprintf(buf,sizeof(buf)-1,"kill_%s", procid_str_static(&crec->pid));
if (cgi_variable(buf)) {
}
/* traversal fn for showing machine connections */
-static int traverse_fn2(struct db_record *rec,
- const struct connections_key *key,
+static int traverse_fn2(const struct connections_key *key,
const struct connections_data *crec,
void *private_data)
{
- if (crec->cnum == -1 || !process_exists(crec->pid) ||
- procid_equal(&crec->pid, &smbd_pid))
+ if (crec->cnum == TID_FIELD_INVALID || !process_exists(crec->pid) ||
+ serverid_equal(&crec->pid, &smbd_pid))
return 0;
addPid2Machine (crec->pid, crec->machine);
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));
}
/* traversal fn for showing share connections */
-static int traverse_fn3(struct db_record *rec,
- const struct connections_key *key,
+static int traverse_fn3(const struct connections_key *key,
const struct connections_data *crec,
void *private_data)
{
- if (crec->cnum == -1 || !process_exists(crec->pid))
+ if (crec->cnum == TID_FIELD_INVALID || !process_exists(crec->pid))
return 0;
printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n",
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;
}
int autorefresh=0;
int refresh_interval=30;
int nr_running=0;
- BOOL waitup = False;
+ bool waitup = False;
+ TALLOC_CTX *ctx = talloc_stackframe();
+ const char form_name[] = "status";
- smbd_pid = pid_to_procid(pidfile_pid("smbd"));
+ smbd_pid = pid_to_procid(pidfile_pid(lp_piddir(), "smbd"));
+
+ if (!verify_xsrf_token(form_name)) {
+ goto output_page;
+ }
if (cgi_variable("smbd_restart") || cgi_variable("all_restart")) {
stop_smbd();
PID_or_Machine = 0;
}
- connections_forall(traverse_fn1, NULL);
-
+ connections_forall_read(traverse_fn1, NULL);
+
initPid2Machine ();
+output_page:
printf("<H2>%s</H2>\n", _("Server Status"));
printf("<FORM method=post>\n");
+ print_xsrf_token(cgi_user_name(), cgi_user_pass(), form_name);
if (!autorefresh) {
printf("<input type=submit value=\"%s\" name=\"autorefresh\">\n", _("Auto Refresh"));
printf("<table>\n");
- printf("<tr><td>%s</td><td>%s</td></tr>", _("version:"), SAMBA_VERSION_STRING);
+ printf("<tr><td>%s</td><td>%s</td></tr>", _("version:"), samba_version_string());
fflush(stdout);
printf("<tr><td>%s</td><td>%s</td>\n", _("smbd:"), smbd_running()?_("running"):_("not running"));
}
printf("</tr>\n");
- connections_forall(traverse_fn2, NULL);
+ connections_forall_read(traverse_fn2, NULL);
printf("</table><p>\n");
printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n\n",
_("Share"), _("User"), _("Group"), _("PID"), _("Client"), _("Date"));
- connections_forall(traverse_fn3, NULL);
+ connections_forall_read(traverse_fn3, NULL);
printf("</table><p>\n");
printf("<h3>%s</h3>\n", _("Open Files"));
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"));
+ printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n",
+ _("PID"), _("UID"), _("Sharing"), _("R/W"), _("Oplock"), _("Share"), _("File"), _("Date"));
- locking_init(1);
+ locking_init_readonly();
share_mode_forall(print_share_mode, NULL);
locking_end();
printf("</table>\n");
refresh_interval*1000);
printf("//-->\n</script>\n");
}
+ TALLOC_FREE(ctx);
}