From 3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Dec 1999 13:27:58 +0000 Subject: first pass at updating head branch to be to be the same as the SAMBA_2_0 branch (This used to be commit 453a822a76780063dff23526c35408866d0c0154) --- source3/web/cgi.c | 21 +---- source3/web/diagnose.c | 2 +- source3/web/startstop.c | 4 +- source3/web/statuspage.c | 72 +++++++++------- source3/web/swat.c | 209 +++++++++++++++++++++++++++++++---------------- 5 files changed, 188 insertions(+), 120 deletions(-) (limited to 'source3/web') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 305c173a5d..62a5e71e05 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -333,7 +333,7 @@ handle a http authentication line static BOOL cgi_handle_authorization(char *line) { char *p, *user, *user_pass; - const struct passwd *pass = NULL; + struct passwd *pass = NULL; BOOL ret = False; if (strncasecmp(line,"Basic ", 6)) { @@ -386,20 +386,7 @@ static BOOL cgi_handle_authorization(char *line) * We have not authenticated as root, * become the user *permanently*. */ - if(!become_user_permanently(pass->pw_uid, pass->pw_gid)) { - /* - * Always give the same error so a cracker - * cannot tell why we fail. - */ - cgi_setup_error("401 Bad Authorization", "", - "username/password must be supplied"); - return False; - } - - /* - * On exit from here we are the authenticated - * user - no way back. - */ + become_user_permanently(pass->pw_uid, pass->pw_gid); } /* Save the users name */ @@ -571,9 +558,9 @@ void cgi_setup(char *rootdir, int auth_required) *p = 0; } - string_sub(url, "/swat/", ""); + string_sub(url, "/swat/", "", 0); - if (strstr(url,"..")==0 && file_exist(url, NULL)) { + if (url[0] != '/' && strstr(url,"..")==0 && file_exist(url, NULL)) { cgi_download(url); } diff --git a/source3/web/diagnose.c b/source3/web/diagnose.c index 054de2a631..f29e380b93 100644 --- a/source3/web/diagnose.c +++ b/source3/web/diagnose.c @@ -32,7 +32,7 @@ BOOL nmbd_running(void) struct in_addr *ip_list; if ((fd = open_socket_in(SOCK_DGRAM, 0, 3, - interpret_addr("127.0.0.1"))) != -1) { + interpret_addr("127.0.0.1"), True)) != -1) { if ((ip_list = name_query(fd, "__SAMBA__", 0, True, True, loopback_ip, &count,0)) != NULL) { diff --git a/source3/web/startstop.c b/source3/web/startstop.c index 6a15e7a46f..9eeac96cc0 100644 --- a/source3/web/startstop.c +++ b/source3/web/startstop.c @@ -37,7 +37,7 @@ void start_smbd(void) return; } - slprintf(binfile, sizeof(pstring) - 1, "%s/smbd", BINDIR); + slprintf(binfile, sizeof(pstring) - 1, "%s/smbd", SBINDIR); become_daemon(); @@ -58,7 +58,7 @@ void start_nmbd(void) return; } - slprintf(binfile, sizeof(pstring) - 1, "%s/nmbd", BINDIR); + slprintf(binfile, sizeof(pstring) - 1, "%s/nmbd", SBINDIR); become_daemon(); diff --git a/source3/web/statuspage.c b/source3/web/statuspage.c index faf1dcb20d..304a122e23 100644 --- a/source3/web/statuspage.c +++ b/source3/web/statuspage.c @@ -26,13 +26,13 @@ static char *tstring(time_t t) { static pstring buf; pstrcpy(buf, asctime(LocalTime(&t))); - all_string_sub(buf," "," "); + all_string_sub(buf," "," ",sizeof(buf)); return buf; } static void print_share_mode(share_mode_entry *e, char *fname) { - printf("%d",e->pid); + printf("%d",(int)e->pid); printf(""); switch ((e->share_mode>>4)&0xF) { case DENY_NONE: printf("DENY_NONE"); break; @@ -60,12 +60,14 @@ static void print_share_mode(share_mode_entry *e, char *fname) printf("EXCLUSIVE "); else if (e->op_type & BATCH_OPLOCK) printf("BATCH "); + else if (e->op_type & LEVEL_II_OPLOCK) + printf("LEVEL_II "); else printf("NONE "); printf(""); printf("%s%s\n", - fname,tstring(e->time.tv_sec)); + dos_to_unix(fname,False),tstring(e->time.tv_sec)); } @@ -131,7 +133,7 @@ void status_page(void) if (crec.magic == 0x280267 && crec.cnum == -1 && process_exists(crec.pid)) { char buf[30]; - slprintf(buf,sizeof(buf)-1,"kill_%d", crec.pid); + slprintf(buf,sizeof(buf)-1,"kill_%d", (int)crec.pid); if (cgi_variable(buf)) { kill_pid(crec.pid); } @@ -159,10 +161,10 @@ void status_page(void) f = sys_fopen(fname,"r"); if (!f) { - printf("Couldn't open status file %s\n",fname); + /* open failure either means no connections have been + made or status=no */ if (!lp_status(-1)) printf("You need to have status=yes in your smb config file\n"); - return; } @@ -171,60 +173,74 @@ void status_page(void) printf("version:%s",VERSION); fflush(stdout); - if (smbd_running()) { - printf("smbd:running\n"); - } else { - printf("smbd:not running>\n"); + printf("smbd:%srunning\n",smbd_running()?"":"not "); + if (geteuid() == 0) { + if (smbd_running()) { + printf("\n"); + } else { + printf("\n"); + } + printf("\n"); } + printf("\n"); fflush(stdout); - if (nmbd_running()) { - printf("nmbd:running\n"); - } else { - printf("nmbd:not running\n"); + printf("nmbd:%srunning\n",nmbd_running()?"":"not "); + if (geteuid() == 0) { + if (nmbd_running()) { + printf("\n"); + } else { + printf("\n"); + } + printf("\n"); } + printf("\n"); printf("\n"); fflush(stdout); - - if (geteuid() != 0) - printf("NOTE: You are not logged in as root and won't be able to start/stop the server

\n"); - printf("

Active Connections

\n"); printf("\n"); - printf("\n"); + printf("\n"); + if (geteuid() == 0) { + printf("\n"); + } + printf("\n"); - while (!feof(f)) { + while (f && !feof(f)) { if (fread(&crec,sizeof(crec),1,f) != 1) break; if (crec.magic == 0x280267 && crec.cnum == -1 && process_exists(crec.pid)) { - printf("\n", - crec.pid, + printf("\n", + (int)crec.pid, crec.machine,crec.addr, - tstring(crec.start), - crec.pid); + tstring(crec.start)); + if (geteuid() == 0) { + printf("\n", + (int)crec.pid); + } + printf("\n"); } } printf("
PIDClientIP addressDateKill
PIDClientIP addressDateKill
%d%s%s%s
%d%s%s%s

\n"); - fseek(f, 0, SEEK_SET); + if (f) fseek(f, 0, SEEK_SET); printf("

Active Shares

\n"); printf("\n"); printf("\n\n"); - while (!feof(f)) { + while (f && !feof(f)) { if (fread(&crec,sizeof(crec),1,f) != 1) break; if (crec.cnum == -1) continue; if (crec.magic == 0x280267 && process_exists(crec.pid)) { printf("\n", crec.name,uidtoname(crec.uid), - gidtoname(crec.gid),crec.pid, + gidtoname(crec.gid),(int)crec.pid, crec.machine, tstring(crec.start)); } @@ -241,7 +257,7 @@ void status_page(void) locking_end(); printf("
ShareUserGroupPIDClientDate
%s%s%s%d%s%s
\n"); - fclose(f); + if (f) fclose(f); printf("\n"); diff --git a/source3/web/swat.c b/source3/web/swat.c index ce7801ba5c..48c3ae07e2 100644 --- a/source3/web/swat.c +++ b/source3/web/swat.c @@ -31,6 +31,8 @@ static pstring servicesf = CONFIGFILE; static BOOL demo_mode = False; static BOOL have_write_access = False; +static BOOL have_read_access = False; +static int iNumNonAutoPrintServices = 0; /* * Password Management Globals @@ -215,9 +217,10 @@ static void show_parameter(int snum, struct parm_struct *parm) break; case P_OCTAL: - printf("", make_parm_name(parm->label), *(int *)ptr); - printf("", - make_parm_name(parm->label),(int)(parm->def.ivalue)); + printf("", make_parm_name(parm->label), octal_string(*(int *)ptr)); + printf("", + make_parm_name(parm->label), + octal_string((int)(parm->def.ivalue))); break; case P_ENUM: @@ -252,10 +255,18 @@ static void show_parameters(int snum, int allparameters, int advanced, int print continue; } if (parm->flags & FLAG_HIDE) continue; + if (snum >= 0) { + if (printers & !(parm->flags & FLAG_PRINT)) continue; + if (!printers & !(parm->flags & FLAG_SHARE)) continue; + } if (!advanced) { - if (!printers && !(parm->flags & FLAG_BASIC)) { + if (!(parm->flags & FLAG_BASIC)) { void *ptr = parm->ptr; + if (parm->class == P_LOCAL && snum >= 0) { + ptr = lp_local_ptr(snum, ptr); + } + switch (parm->type) { case P_CHAR: if (*(char *)ptr == (char)(parm->def.cvalue)) continue; @@ -299,6 +310,15 @@ static void show_parameters(int snum, int allparameters, int advanced, int print } } +/**************************************************************************** + load the smb.conf file into loadparm. +****************************************************************************/ +static BOOL load_config(BOOL save_def) +{ + lp_resetnumservices(); + return lp_load(servicesf,False,save_def,False); +} + /**************************************************************************** write a config file ****************************************************************************/ @@ -306,15 +326,15 @@ static void write_config(FILE *f, BOOL show_defaults) { fprintf(f, "# Samba config file created using SWAT\n"); fprintf(f, "# from %s (%s)\n", cgi_remote_host(), cgi_remote_addr()); - fprintf(f, "# Date: %s\n\n", timestring()); + fprintf(f, "# Date: %s\n\n", timestring(False)); - lp_dump(f, show_defaults); + lp_dump(f, show_defaults, iNumNonAutoPrintServices); } /**************************************************************************** save and reoad the smb.conf config file ****************************************************************************/ -static int save_reload(void) +static int save_reload(int snum) { FILE *f; @@ -325,14 +345,18 @@ static int save_reload(void) } write_config(f, False); + if (snum) + lp_dump_one(f, False, snum); fclose(f); lp_killunused(NULL); - if (!lp_load(servicesf,False,False,False)) { + if (!load_config(False)) { printf("Can't reload %s\n", servicesf); return 0; } + iNumNonAutoPrintServices = lp_numservices(); + load_printers(); return 1; } @@ -379,14 +403,6 @@ static void commit_parameters(int snum) } } -/**************************************************************************** - load the smb.conf file into loadparm. -****************************************************************************/ -static BOOL load_config(void) -{ - return lp_load(servicesf,False,True,False); -} - /**************************************************************************** spit out the html for a link with an image ****************************************************************************/ @@ -402,13 +418,22 @@ static void image_link(char *name,char *hlink, char *src) ****************************************************************************/ static void show_main_buttons(void) { - image_link("Home", "", "images/home.gif"); + char *p; + + if ((p = cgi_user_name()) && strcmp(p, "root")) { + printf("Logged in as %s

\n", p); + } - image_link("Globals", "globals", "images/globals.gif"); - image_link("Shares", "shares", "images/shares.gif"); - image_link("Printers", "printers", "images/printers.gif"); - image_link("Status", "status", "images/status.gif"); - image_link("View Config", "viewconfig","images/viewconfig.gif"); + image_link("Home", "", "images/home.gif"); + if (have_write_access) { + image_link("Globals", "globals", "images/globals.gif"); + image_link("Shares", "shares", "images/shares.gif"); + image_link("Printers", "printers", "images/printers.gif"); + } + if (have_read_access) { + image_link("Status", "status", "images/status.gif"); + image_link("View Config", "viewconfig","images/viewconfig.gif"); + } image_link("Password Management", "passwd", "images/passwd.gif"); printf("


\n"); @@ -462,7 +487,7 @@ static void globals_page(void) if (cgi_variable("Commit")) { commit_parameters(GLOBALS_SNUM); - save_reload(); + save_reload(0); } printf("
\n"); @@ -511,26 +536,29 @@ static void shares_page(void) if (cgi_variable("Commit") && snum >= 0) { commit_parameters(snum); - save_reload(); + save_reload(0); } if (cgi_variable("Delete") && snum >= 0) { lp_remove_service(snum); - save_reload(); + save_reload(0); share = NULL; snum = -1; } if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) { + load_config(False); lp_copy_service(GLOBALS_SNUM, share); - save_reload(); + iNumNonAutoPrintServices = lp_numservices(); + save_reload(0); snum = lp_servicenumber(share); } printf("\n"); printf("\n"); - printf("\n"); + printf("\n"); + printf("\n"); printf("

"); - - printf("

\n"); - printf("\n"); + printf("\n"); + if (have_write_access) { + printf("\n"); + } + printf("\n"); + printf("
"); + printf(""); + if (have_write_access) { + printf("\n"); + printf("\n"); + printf("\n"); + } printf("
"); @@ -554,7 +590,7 @@ static void shares_page(void) printf("\n"); } - printf("\n"); + printf("\n"); if (advanced == 0) { printf("\n"); } else { @@ -584,8 +620,6 @@ static BOOL change_password(const char *remote_machine, char *user_name, BOOL add_user, BOOL enable_user, BOOL disable_user) { BOOL ret = False; - uint16 acb_info = 0; - uint16 acb_mask = 0; pstring err_str; pstring msg_str; @@ -602,28 +636,14 @@ static BOOL change_password(const char *remote_machine, char *user_name, return ret; } - if (!pwdb_initialise(False)) - { + if(!initialize_password_db()) { printf("Can't setup password database vectors.\n

"); return False; } - if (enable_user) - { - acb_mask |= ACB_DISABLED; - acb_info &= ~ACB_DISABLED; - } - - if (disable_user) - { - acb_mask |= ACB_DISABLED; - acb_info |= ACB_DISABLED; - } - - ret = local_password_change(user_name, add_user, - acb_info, acb_mask, - new_passwd, err_str, sizeof(err_str), - msg_str, sizeof(msg_str)); + ret = local_password_change(user_name, False, add_user, enable_user, + disable_user, False, new_passwd, err_str, sizeof(err_str), + msg_str, sizeof(msg_str)); if(*msg_str) printf("%s\n

", msg_str); @@ -787,7 +807,7 @@ static void passwd_page(void) printf(" Re-type New Password : \n"); printf("\n",NEW2_PSWD); printf(" Remote Machine : \n"); - printf("\n",RHOST); + printf("\n",RHOST); printf(""); @@ -826,26 +846,37 @@ static void printers_page(void) printf("

Printer Parameters

\n"); + printf("

Important Note:

\n"); + printf("Printer names marked with [*] in the Choose Printer drop-down box "); + printf("are autoloaded printers from "); + printf("Printcap Name.\n"); + printf("Attempting to delete these printers from SWAT will have no effect.\n"); + if (cgi_variable("Advanced") && !cgi_variable("Basic")) advanced = 1; if (cgi_variable("Commit") && snum >= 0) { commit_parameters(snum); - save_reload(); + if (snum >= iNumNonAutoPrintServices) + save_reload(snum); + else + save_reload(0); } if (cgi_variable("Delete") && snum >= 0) { lp_remove_service(snum); - save_reload(); + save_reload(0); share = NULL; snum = -1; } if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) { + load_config(False); lp_copy_service(GLOBALS_SNUM, share); + iNumNonAutoPrintServices = lp_numservices(); snum = lp_servicenumber(share); lp_do_parameter(snum, "print ok", "Yes"); - save_reload(); + save_reload(0); snum = lp_servicenumber(share); } @@ -859,23 +890,36 @@ static void printers_page(void) for (i=0;i= iNumNonAutoPrintServices) + printf("