r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[ira/wip.git] / source3 / web / swat.c
index 43dacb2945e3445e9e4c171175d2360730823f11..25dc9306ea63ce8ff54b2b716a2970753b12e3a0 100644 (file)
@@ -7,7 +7,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -16,8 +16,7 @@
    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/>.
 */
 
 /**
@@ -103,7 +102,7 @@ static char *stripspaceupper(const char *str)
        char *p = newstring;
 
        while (*str) {
-               if (*str != ' ') *p++ = toupper(*str);
+               if (*str != ' ') *p++ = toupper_ascii(*str);
                ++str;
        }
        *p = '\0';
@@ -422,7 +421,7 @@ static void show_parameters(int snum, int allparameters, unsigned int parm_filte
 static BOOL load_config(BOOL save_def)
 {
        lp_resetnumservices();
-       return lp_load(dyn_CONFIGFILE,False,save_def,False);
+       return lp_load(dyn_CONFIGFILE,False,save_def,False,True);
 }
 
 /****************************************************************************
@@ -432,7 +431,7 @@ 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(False));
+       fprintf(f, "# Date: %s\n\n", current_timestring(False));
        
        lp_dump(f, show_defaults, iNumNonAutoPrintServices);
 }
@@ -515,7 +514,7 @@ static void commit_parameters(int snum)
 
        while ((parm = lp_next_parameter(snum, &i, 1))) {
                slprintf(label, sizeof(label)-1, "parm_%s", make_parm_name(parm->label));
-               if ((v = cgi_variable(label))) {
+               if ((v = cgi_variable(label)) != NULL) {
                        if (parm->flags & FLAG_HIDE) continue;
                        commit_parameter(snum, parm, v); 
                }
@@ -580,7 +579,11 @@ static void ViewModeBoxes(int mode)
 ****************************************************************************/
 static void welcome_page(void)
 {
-       include_html("help/welcome.html");
+       if (file_exist("help/welcome.html", NULL)) {
+               include_html("help/welcome.html");
+       } else {
+               include_html("help/welcome-no-samba-doc.html");
+       }
 }
 
 /****************************************************************************
@@ -674,10 +677,10 @@ static void wizard_page(void)
        }
 
        if (cgi_variable("Commit")){
-               SerType = atoi(cgi_variable("ServerType"));
-               winstype = atoi(cgi_variable("WINSType"));
+               SerType = atoi(cgi_variable_nonull("ServerType"));
+               winstype = atoi(cgi_variable_nonull("WINSType"));
                have_home = lp_servicenumber(HOMES_NAME);
-               HomeExpo = atoi(cgi_variable("HomeExpo"));
+               HomeExpo = atoi(cgi_variable_nonull("HomeExpo"));
 
                /* Plain text passwords are too badly broken - use encrypted passwords only */
                lp_do_parameter( GLOBAL_SECTION_SNUM, "encrypt passwords", "Yes");
@@ -710,7 +713,7 @@ static void wizard_page(void)
                                break;
                        case 2:
                                lp_do_parameter( GLOBAL_SECTION_SNUM, "wins support", "No" );
-                               lp_do_parameter( GLOBAL_SECTION_SNUM, "wins server", cgi_variable("WINSAddr"));
+                               lp_do_parameter( GLOBAL_SECTION_SNUM, "wins server", cgi_variable_nonull("WINSAddr"));
                                break;
                }
 
@@ -835,7 +838,7 @@ static void globals_page(void)
        }
 
        if ( cgi_variable("ViewMode") )
-               mode = atoi(cgi_variable("ViewMode"));
+               mode = atoi(cgi_variable_nonull("ViewMode"));
        if ( cgi_variable("BasicMode"))
                mode = 0;
        if ( cgi_variable("AdvMode"))
@@ -911,7 +914,7 @@ static void shares_page(void)
        printf("<table>\n");
 
        if ( cgi_variable("ViewMode") )
-               mode = atoi(cgi_variable("ViewMode"));
+               mode = atoi(cgi_variable_nonull("ViewMode"));
        if ( cgi_variable("BasicMode"))
                mode = 0;
        if ( cgi_variable("AdvMode"))
@@ -982,7 +985,7 @@ static BOOL change_password(const char *remote_machine, const char *user_name,
                            const char *old_passwd, const char *new_passwd, 
                                int local_flags)
 {
-       BOOL ret = False;
+       NTSTATUS ret;
        pstring err_str;
        pstring msg_str;
 
@@ -996,10 +999,10 @@ static BOOL change_password(const char *remote_machine, const char *user_name,
                                                                         new_passwd, err_str, sizeof(err_str));
                if(*err_str)
                        printf("%s\n<p>", err_str);
-               return ret;
+               return NT_STATUS_IS_OK(ret);
        }
 
-       if(!initialize_password_db(True)) {
+       if(!initialize_password_db(True, NULL)) {
                printf("%s\n<p>", _("Can't setup password database vectors."));
                return False;
        }
@@ -1012,7 +1015,7 @@ static BOOL change_password(const char *remote_machine, const char *user_name,
        if(*err_str)
                printf("%s\n<p>", err_str);
 
-       return ret;
+       return NT_STATUS_IS_OK(ret);
 }
 
 /****************************************************************************
@@ -1025,7 +1028,7 @@ static void chg_passwd(void)
        int local_flags = 0;
 
        /* Make sure users name has been specified */
-       if (strlen(cgi_variable(SWAT_USER)) == 0) {
+       if (strlen(cgi_variable_nonull(SWAT_USER)) == 0) {
                printf("<p>%s\n", _(" Must specify \"User Name\" "));
                return;
        }
@@ -1040,27 +1043,27 @@ static void chg_passwd(void)
                 * If current user is not root, make sure old password has been specified 
                 * If REMOTE change, even root must provide old password 
                 */
-               if (((!am_root()) && (strlen( cgi_variable(OLD_PSWD)) <= 0)) ||
-                   ((cgi_variable(CHG_R_PASSWD_FLAG)) &&  (strlen( cgi_variable(OLD_PSWD)) <= 0))) {
+               if (((!am_root()) && (strlen( cgi_variable_nonull(OLD_PSWD)) <= 0)) ||
+                   ((cgi_variable(CHG_R_PASSWD_FLAG)) &&  (strlen( cgi_variable_nonull(OLD_PSWD)) <= 0))) {
                        printf("<p>%s\n", _(" Must specify \"Old Password\" "));
                        return;
                }
 
                /* If changing a users password on a remote hosts we have to know what host */
-               if ((cgi_variable(CHG_R_PASSWD_FLAG)) && (strlen( cgi_variable(RHOST)) <= 0)) {
+               if ((cgi_variable(CHG_R_PASSWD_FLAG)) && (strlen( cgi_variable_nonull(RHOST)) <= 0)) {
                        printf("<p>%s\n", _(" Must specify \"Remote Machine\" "));
                        return;
                }
 
                /* Make sure new passwords have been specified */
-               if ((strlen( cgi_variable(NEW_PSWD)) <= 0) ||
-                   (strlen( cgi_variable(NEW2_PSWD)) <= 0)) {
+               if ((strlen( cgi_variable_nonull(NEW_PSWD)) <= 0) ||
+                   (strlen( cgi_variable_nonull(NEW2_PSWD)) <= 0)) {
                        printf("<p>%s\n", _(" Must specify \"New, and Re-typed Passwords\" "));
                        return;
                }
 
                /* Make sure new passwords was typed correctly twice */
-               if (strcmp(cgi_variable(NEW_PSWD), cgi_variable(NEW2_PSWD)) != 0) {
+               if (strcmp(cgi_variable_nonull(NEW_PSWD), cgi_variable_nonull(NEW2_PSWD)) != 0) {
                        printf("<p>%s\n", _(" Re-typed password didn't match new password "));
                        return;
                }
@@ -1087,17 +1090,17 @@ static void chg_passwd(void)
        
 
        rslt = change_password(host,
-                              cgi_variable(SWAT_USER),
-                              cgi_variable(OLD_PSWD), cgi_variable(NEW_PSWD),
+                              cgi_variable_nonull(SWAT_USER),
+                              cgi_variable_nonull(OLD_PSWD), cgi_variable_nonull(NEW_PSWD),
                                   local_flags);
 
        if(cgi_variable(CHG_S_PASSWD_FLAG)) {
                printf("<p>");
                if (rslt == True) {
-                       printf(_(" The passwd for '%s' has been changed."), cgi_variable(SWAT_USER));
+                       printf(_(" The passwd for '%s' has been changed."), cgi_variable_nonull(SWAT_USER));
                        printf("\n");
                } else {
-                       printf(_(" The passwd for '%s' has NOT been changed."), cgi_variable(SWAT_USER));
+                       printf(_(" The passwd for '%s' has NOT been changed."), cgi_variable_nonull(SWAT_USER));
                        printf("\n");
                }
        }
@@ -1117,7 +1120,7 @@ static void passwd_page(void)
         * changed the User box text to another users name, remember it.
         */
        if (cgi_variable(SWAT_USER)) {
-               new_name = cgi_variable(SWAT_USER);
+               new_name = cgi_variable_nonull(SWAT_USER);
        } 
 
        if (!new_name) new_name = "";
@@ -1261,7 +1264,7 @@ static void printers_page(void)
        printf("<FORM name=\"swatform\" method=post>\n");
 
        if ( cgi_variable("ViewMode") )
-               mode = atoi(cgi_variable("ViewMode"));
+               mode = atoi(cgi_variable_nonull("ViewMode"));
         if ( cgi_variable("BasicMode"))
                 mode = 0;
         if ( cgi_variable("AdvMode"))
@@ -1331,13 +1334,12 @@ static void printers_page(void)
  **/
  int main(int argc, char *argv[])
 {
-       int opt;
        const char *page;
        poptContext pc;
        struct poptOption long_options[] = {
                POPT_AUTOHELP
                { "disable-authentication", 'a', POPT_ARG_VAL, &demo_mode, True, "Disable authentication (demo mode)" },
-        { "password-menu-only", 'P', POPT_ARG_VAL, &passwd_only, True, "Show only change password menu" }, 
+               { "password-menu-only", 'P', POPT_ARG_VAL, &passwd_only, True, "Show only change password menu" }, 
                POPT_COMMON_SAMBA
                POPT_TABLEEND
        };
@@ -1368,12 +1370,15 @@ static void printers_page(void)
 
        /* Parse command line options */
 
-       while((opt = poptGetNextOpt(pc)) != -1) { }
+       while(poptGetNextOpt(pc) != -1) { }
 
        poptFreeContext(pc);
 
+       load_case_tables();
+
        setup_logging(argv[0],False);
        load_config(True);
+       load_interfaces();
        iNumNonAutoPrintServices = lp_numservices();
        load_printers();