swat.c
来自「samba-3.0.22.tar.gz 编译smb服务器的源码」· C语言 代码 · 共 1,435 行 · 第 1/3 页
C
1,435 行
printf("<td><input type=text size=30 name=newshare></td></tr>\n"); } printf("</table>"); if (snum >= 0) { if (have_write_access) { printf("<input type=submit name=\"Commit\" value=\"%s\">\n", _("Commit Changes")); } printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n", _("Reset Values")); printf("<p>\n"); } if (snum >= 0) { printf("<table>\n"); show_parameters(snum, 1, parm_filter, 0); printf("</table>\n"); } printf("</FORM>\n");}/*************************************************************change a password either locally or remotely*************************************************************/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; pstring err_str; pstring msg_str; if (demo_mode) { printf("%s\n<p>", _("password change in demo mode rejected")); return False; } if (remote_machine != NULL) { ret = remote_password_change(remote_machine, user_name, old_passwd, new_passwd, err_str, sizeof(err_str)); if(*err_str) printf("%s\n<p>", err_str); return ret; } if(!initialize_password_db(True)) { printf("%s\n<p>", _("Can't setup password database vectors.")); return False; } ret = local_password_change(user_name, local_flags, new_passwd, err_str, sizeof(err_str), msg_str, sizeof(msg_str)); if(*msg_str) printf("%s\n<p>", msg_str); if(*err_str) printf("%s\n<p>", err_str); return ret;}/**************************************************************************** do the stuff required to add or change a password ****************************************************************************/static void chg_passwd(void){ const char *host; BOOL rslt; int local_flags = 0; /* Make sure users name has been specified */ if (strlen(cgi_variable(SWAT_USER)) == 0) { printf("<p>%s\n", _(" Must specify \"User Name\" ")); return; } /* * smbpasswd doesn't require anything but the users name to delete, disable or enable the user, * so if that's what we're doing, skip the rest of the checks */ if (!cgi_variable(DISABLE_USER_FLAG) && !cgi_variable(ENABLE_USER_FLAG) && !cgi_variable(DELETE_USER_FLAG)) { /* * 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))) { 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)) { 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)) { 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) { printf("<p>%s\n", _(" Re-typed password didn't match new password ")); return; } } if (cgi_variable(CHG_R_PASSWD_FLAG)) { host = cgi_variable(RHOST); } else if (am_root()) { host = NULL; } else { host = "127.0.0.1"; } /* * Set up the local flags. */ local_flags |= (cgi_variable(ADD_USER_FLAG) ? LOCAL_ADD_USER : 0); local_flags |= (cgi_variable(ADD_USER_FLAG) ? LOCAL_SET_PASSWORD : 0); local_flags |= (cgi_variable(CHG_S_PASSWD_FLAG) ? LOCAL_SET_PASSWORD : 0); local_flags |= (cgi_variable(DELETE_USER_FLAG) ? LOCAL_DELETE_USER : 0); local_flags |= (cgi_variable(ENABLE_USER_FLAG) ? LOCAL_ENABLE_USER : 0); local_flags |= (cgi_variable(DISABLE_USER_FLAG) ? LOCAL_DISABLE_USER : 0); rslt = change_password(host, cgi_variable(SWAT_USER), cgi_variable(OLD_PSWD), cgi_variable(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("\n"); } else { printf(_(" The passwd for '%s' has NOT been changed."), cgi_variable(SWAT_USER)); printf("\n"); } } return;}/**************************************************************************** display a password editing page ****************************************************************************/static void passwd_page(void){ const char *new_name = cgi_user_name(); /* * After the first time through here be nice. If the user * changed the User box text to another users name, remember it. */ if (cgi_variable(SWAT_USER)) { new_name = cgi_variable(SWAT_USER); } if (!new_name) new_name = ""; printf("<H2>%s</H2>\n", _("Server Password Management")); printf("<FORM name=\"swatform\" method=post>\n"); printf("<table>\n"); /* * Create all the dialog boxes for data collection */ printf("<tr><td> %s : </td>\n", _("User Name")); printf("<td><input type=text size=30 name=%s value=%s></td></tr> \n", SWAT_USER, new_name); if (!am_root()) { printf("<tr><td> %s : </td>\n", _("Old Password")); printf("<td><input type=password size=30 name=%s></td></tr> \n",OLD_PSWD); } printf("<tr><td> %s : </td>\n", _("New Password")); printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD); printf("<tr><td> %s : </td>\n", _("Re-type New Password")); printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD); printf("</table>\n"); /* * Create all the control buttons for requesting action */ printf("<input type=submit name=%s value=\"%s\">\n", CHG_S_PASSWD_FLAG, _("Change Password")); if (demo_mode || am_root()) { printf("<input type=submit name=%s value=\"%s\">\n", ADD_USER_FLAG, _("Add New User")); printf("<input type=submit name=%s value=\"%s\">\n", DELETE_USER_FLAG, _("Delete User")); printf("<input type=submit name=%s value=\"%s\">\n", DISABLE_USER_FLAG, _("Disable User")); printf("<input type=submit name=%s value=\"%s\">\n", ENABLE_USER_FLAG, _("Enable User")); } printf("<p></FORM>\n"); /* * Do some work if change, add, disable or enable was * requested. It could be this is the first time through this * code, so there isn't anything to do. */ if ((cgi_variable(CHG_S_PASSWD_FLAG)) || (cgi_variable(ADD_USER_FLAG)) || (cgi_variable(DELETE_USER_FLAG)) || (cgi_variable(DISABLE_USER_FLAG)) || (cgi_variable(ENABLE_USER_FLAG))) { chg_passwd(); } printf("<H2>%s</H2>\n", _("Client/Server Password Management")); printf("<FORM name=\"swatform\" method=post>\n"); printf("<table>\n"); /* * Create all the dialog boxes for data collection */ printf("<tr><td> %s : </td>\n", _("User Name")); printf("<td><input type=text size=30 name=%s value=%s></td></tr>\n",SWAT_USER, new_name); printf("<tr><td> %s : </td>\n", _("Old Password")); printf("<td><input type=password size=30 name=%s></td></tr>\n",OLD_PSWD); printf("<tr><td> %s : </td>\n", _("New Password")); printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW_PSWD); printf("<tr><td> %s : </td>\n", _("Re-type New Password")); printf("<td><input type=password size=30 name=%s></td></tr>\n",NEW2_PSWD); printf("<tr><td> %s : </td>\n", _("Remote Machine")); printf("<td><input type=text size=30 name=%s></td></tr>\n",RHOST); printf("</table>"); /* * Create all the control buttons for requesting action */ printf("<input type=submit name=%s value=\"%s\">", CHG_R_PASSWD_FLAG, _("Change Password")); printf("<p></FORM>\n"); /* * Do some work if a request has been made to change the * password somewhere other than the server. It could be this * is the first time through this code, so there isn't * anything to do. */ if (cgi_variable(CHG_R_PASSWD_FLAG)) { chg_passwd(); }}/**************************************************************************** display a printers editing page ****************************************************************************/static void printers_page(void){ const char *share = cgi_variable("share"); char *s; int snum=-1; int i; int mode = 0; unsigned int parm_filter = FLAG_BASIC; if (share) snum = lp_servicenumber(share); printf("<H2>%s</H2>\n", _("Printer Parameters")); printf("<H3>%s</H3>\n", _("Important Note:")); printf(_("Printer names marked with [*] in the Choose Printer drop-down box ")); printf(_("are autoloaded printers from ")); printf("<A HREF=\"/swat/help/smb.conf.5.html#printcapname\" target=\"docs\">%s</A>\n", _("Printcap Name")); printf("%s\n", _("Attempting to delete these printers from SWAT will have no effect.")); if (cgi_variable("Commit") && snum >= 0) { commit_parameters(snum); if (snum >= iNumNonAutoPrintServices) save_reload(snum); else save_reload(0); } if (cgi_variable("Delete") && snum >= 0) { lp_remove_service(snum); save_reload(0); share = NULL; snum = -1; } if (cgi_variable("createshare") && (share=cgi_variable("newshare"))) { load_config(False); lp_copy_service(GLOBAL_SECTION_SNUM, share); iNumNonAutoPrintServices = lp_numservices(); snum = lp_servicenumber(share); lp_do_parameter(snum, "print ok", "Yes"); save_reload(0); snum = lp_servicenumber(share); } printf("<FORM name=\"swatform\" method=post>\n"); if ( cgi_variable("ViewMode") ) mode = atoi(cgi_variable("ViewMode")); if ( cgi_variable("BasicMode")) mode = 0; if ( cgi_variable("AdvMode")) mode = 1; ViewModeBoxes( mode ); switch ( mode ) { case 0: parm_filter = FLAG_BASIC; break; case 1: parm_filter = FLAG_ADVANCED; break; } printf("<table>\n"); printf("<tr><td><input type=submit name=\"selectshare\" value=\"%s\"></td>\n", _("Choose Printer")); printf("<td><select name=\"share\">\n"); if (snum < 0 || !lp_print_ok(snum)) printf("<option value=\" \"> \n"); for (i=0;i<lp_numservices();i++) { s = lp_servicename(i); if (s && (*s) && strcmp(s,"IPC$") && lp_print_ok(i)) { if (i >= iNumNonAutoPrintServices) printf("<option %s value=\"%s\">[*]%s\n", (share && strcmp(share,s)==0)?"SELECTED":"", s, s); else printf("<option %s value=\"%s\">%s\n", (share && strcmp(share,s)==0)?"SELECTED":"", s, s); } } printf("</select></td>"); if (have_write_access) { printf("<td><input type=submit name=\"Delete\" value=\"%s\"></td>\n", _("Delete Printer")); } printf("</tr>"); printf("</table>\n"); if (have_write_access) { printf("<table>\n"); printf("<tr><td><input type=submit name=\"createshare\" value=\"%s\"></td>\n", _("Create Printer")); printf("<td><input type=text size=30 name=\"newshare\"></td></tr>\n"); printf("</table>"); } if (snum >= 0) { if (have_write_access) { printf("<input type=submit name=\"Commit\" value=\"%s\">\n", _("Commit Changes")); } printf("<input type=reset name=\"Reset Values\" value=\"%s\">\n", _("Reset Values")); printf("<p>\n"); } if (snum >= 0) { printf("<table>\n"); show_parameters(snum, 1, parm_filter, 1); printf("</table>\n"); } printf("</FORM>\n");}/** * main function for SWAT. **/ int main(int argc, char *argv[]){ 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" }, POPT_COMMON_SAMBA POPT_TABLEEND }; fault_setup(NULL); umask(S_IWGRP | S_IWOTH);#if defined(HAVE_SET_AUTH_PARAMETERS) set_auth_parameters(argc, argv);#endif /* HAVE_SET_AUTH_PARAMETERS */ /* just in case it goes wild ... */ alarm(300); setlinebuf(stdout); /* we don't want any SIGPIPE messages */ BlockSignals(True,SIGPIPE); dbf = x_fopen("/dev/null", O_WRONLY, 0); if (!dbf) dbf = x_stderr; /* we don't want stderr screwing us up */ close(2); open("/dev/null", O_WRONLY); pc = poptGetContext("swat", argc, (const char **) argv, long_options, 0); /* Parse command line options */ while(poptGetNextOpt(pc) != -1) { } poptFreeContext(pc); setup_logging(argv[0],False); load_config(True); load_interfaces(); iNumNonAutoPrintServices = lp_numservices(); load_printers(); cgi_setup(dyn_SWATDIR, !demo_mode); print_header(); cgi_load_variables(); if (!file_exist(dyn_CONFIGFILE, NULL)) { have_read_access = True; have_write_access = True; } else { /* check if the authenticated user has write access - if not then don't show write options */ have_write_access = (access(dyn_CONFIGFILE,W_OK) == 0); /* if the user doesn't have read access to smb.conf then don't let them view it */ have_read_access = (access(dyn_CONFIGFILE,R_OK) == 0); } show_main_buttons(); page = cgi_pathinfo(); /* Root gets full functionality */ if (have_read_access && strcmp(page, "globals")==0) { globals_page(); } else if (have_read_access && strcmp(page,"shares")==0) { shares_page(); } else if (have_read_access && strcmp(page,"printers")==0) { printers_page(); } else if (have_read_access && strcmp(page,"status")==0) { status_page(); } else if (have_read_access && strcmp(page,"viewconfig")==0) { viewconfig_page(); } else if (strcmp(page,"passwd")==0) { passwd_page(); } else if (have_read_access && strcmp(page,"wizard")==0) { wizard_page(); } else if (have_read_access && strcmp(page,"wizard_params")==0) { wizard_params_page(); } else if (have_read_access && strcmp(page,"rewritecfg")==0) { rewritecfg_file(); } else { welcome_page(); } print_footer(); return 0;}/** @} **/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?