HT CGI processing process

xiaoxiao2021-03-06  43

Mainly the process of cgi-bin / www file processing customer request is http: // domain / smagic / boa. . Such CGI corresponds to the httpd.conf of bbsboa.capache under nju09 / down, and the request to execute processible file WWW, and then the request sent by the client browser (shaped like http: / / Your_domain / smgicxxx) Treatment directly through Apache calls.

First, analyze the CGI environment variable Script_URL in bbslib.c, url_parse () function definition: intURL_PARSE () {char * URL, * END, NAME [Strlen], * P, * extraparam; url = getenv ("script_url"); IF (NULL == URL) Return -1; Strcpy (Name, "/"); if (! Strncmp (URL, "SMAGIC, SIZEOF (SMAGIC)) {Snprintf (Name, Strlen,"% s ", URL SIZEOF (SMAGIC)); p = strchr (name, '/'); if (null! = p) {* p = 0; URL = STRCHR (URL 1, '/');} else return -1 ;} extraparam = strchr (name, '_'); if (extraparam) {* extraparam = 0; extraparam ;} else extraparam = ""; extraparam_init (extraparam); loginok = user_init (& currentuser, & u_info, name); if ( Loginok) W_INFO = & (u_info-> wwwinfo; else w_info = & guest; if (! strcmp (url, "/") || nologin) {structure (Needcgi, "bbsindex"); strcpy (rframe, "); STRSNCPY (Name, Getsenv ("http_host"), 70); P = Strchr (Name, '.'); if (p! = null && isaword (domainname, p 1)) {* p = 0; strsncpy (RFrame , Name, 60);} if (RFrame, RFrame)) RFRAME [0] = 0; return 0;} Snprintf (Needcgi, Strlen, "% S" , URL 1); if (null! = (End = strchr (needcgi, '/'))) * end = 0; return 0;} 2, bbsmain.c call URL_PARSE () INTMAIN (int Argc, char * argv []) {struct cgi_applet * a = null; struct rlimit rl; int i; setuid (bbsuid); setuid (bbsuid); setgid (bbsgid); CGI_TIME (null); rl.rlim_cur = 100 * 1024 * 1024; RL.RLIM_MAX = 100 * 1024 * 1024; Strlimit (rlimit_core, & rl); Thispid = getPid (); now_t = time (null); SRAND (now_t * 2 trispid); if (InitbbsInfo); IF

BBSINFO) <0) EXIT (0); if (uhash_uptime () == 0) {EXIT (-1);} wwwcache = get_shm (wwwcache_shmkey, sizeof (struct wwwcache)); if (null == wwwcache) EXIT (0 ); Thisversion = file_time (argv [0]); # iFNDef usebig5 if (thisversion> wwwcache-> www_version) www_version = thisversion; #ENDIF HTML_HEADER (0); if (getEuid ()! = Bbsuid) http_fatal (" Uid error. "); chdir (bbshome); SHM_INIT (& BBSINFO); Signal (SIGTERM, Wantquit); IF (Access (" NOLOGIN ", F_OK) NOLOGIN = 0; Get_att_server (); get_tjpg_server (); while (fcgi_accept ( )> = 0) {#ifdef usebig5 start_outcache (); # Endif cginame = null; incgiloop = 1; if (setjmp (cgi_start) {#ifdef usebig5 end_outcache (); # ENDIF CGI_TIME (a); if (! Incggiloop | | Wwwcache-> www_version> thisversion || RT > 400000) {logtimeused (); exit (2);} incgiloop = 0; Continue;} HTML_HEADER (0); hsprintf (null, null); now_t = time (null); VIA_Proxy = 0; strsncpy (fromhost, getsenv ("remote_addr"), 32); INET_ATON FromHost, & from_addr); for (i = 0; wwwcache-> validproxy [i] && i validproxy [i]) {via_proxy = 1; Break;}} IF (via_proxy || == wwwcache-> accel_addr.s_addr) {char * ptr, * p; int iplen = 255; PTR = getenv ("http_x_forwarded_for"); if (! Ptr) PTR = Getsenv ("Remote_Addr "); P = strrchr (ptr, ','); if (p! = Null) {while (! Isdigit (* p) && * p) p ; if (* p) strncpy (fromhost, p, iPlen);

Else Strncpy (fromHost, PTR, IPLEN); Else Strncpy (fromHost, PTR, IPLEN); FromHost [iplen] = 0; inet_aton (fromhost, & from_addr);} if (URL_PARSE ()) http_fatal ("% s is not implemented Function! ", Getsenv (" script_url ")); http_parm_init (); brc_expired (); a = get_cgi_applet (needcgi); if (a! = Null) {cginaMe = A-> Name [0]; // access (Getsenv ("Query_string"), f_ok); wwwcache-> www_visit ; (* (a-> main)) (); # ifdef usebig5 end_outcache (); # Endif CGI_TIME (a); if (! Incggiloop || wwwcache-> www_version > Thisversion) {logtimeused (); exit (4);} incgiLoop = 0; Continue;} http_fatal ("% s does not implement function!", Getsenv ("script_url")); // end_outcache (); incgiLoop = 0 } Logtimeused (); exit (5);} III, MAIN () After calling URL_PARSE (), see the URL_PARSE () 大略 的 大略: First get the value of the environment variable script_url, as Script_url = "/ smagic / boa, then cut off the front part, assign the remaining BOA to Needcgi, then return main (), then call GET_CGI_APPLET () with NeedCGI as the parameter, and check the function name GET_CGI_APPLET from the Applets table according to NeedCGI (Char * Needci) {static ght_hash_table_t * p_table = null; stru CT CGI_Applet * a; if (p_table == null) {INT i; a = applets; p_table = ght_create (250); while (a-> main! = null) {a-> count = 0; A-> utime = 0; A-> STIME = 0; for (i = 0; A-> Name [i]! = Null; i ) GHT_INSERT (p_table, (void *) a, strlen (A-> Name [i]), Void *) A-> Name [i]); A ;}} if (p_table == null) Return Null; return ght_get (p_table, strlen (needcgi), needcgi);} # ElseStruct CGI_Applet * get_cgi_applet (char * needcgi) {Struct cgi_applet * a; int i; a = applets;

While (a-> main! = null) {for (i = 0; A-> Name [i]! = null; i ) IF (! strcmp (needcmp (needcgi, a-> name [i])) Return A; A } Return Null;} # Endif Since URL_PARSE () Written this, http: // Domain / CGI-BIN / WWW naturally doesn't matter .. IV. According to NeedCGi from the Applets table, the function name is checked, the following is available / VAR / WWW / CGI-BIN / Under Executable Internal Functions WWW Call: Struct CGI_Applet Applets [] = {// {BBSUSR_MAIN, {"BBSUSR", NULL}}, {bbsucss_main, {"bbsucss", null} }, {Bbsdefcss_main, {"bbsdefcss", null}}, {bbstop10_main, {"bbstop10", null}}}, {bbsdoc_main, {"bbsdoc", "doc", null}}, {bbscon_main, {"bbscon", "con", null}}, {"bbsbrdadd", "brdd", null}}, {bbsboa_main, {"bbsboa", "boa", null}}, {bbsall_main, {"bbsall", null} }, {Bbsanc_main, {"bbsanc", "anc", null}}, {bbs0an_main, {"bbs0an", "0an", null}}, {bbslogout_main, {"bbslogout", null}}, {bbsLEFT_MAIN, { "BBSLOGIN_MAIN, {" bbslogin ", null}}, {bbsbadlogins_main, {" bbsbadlogins ", null}}, {bbsqry_main, {" bbsqry "," Qry ", null}}, {bbsnot_main , {"Bbsnot", "not", null}}, {bbsfind_main, {"bbsfind", null}}} {bbsfadd_mai n, {"bbsfadd", null}}, {bbsfdel_main, {"bbsfdel", null}}, {bbsfall_main, {"bbsfall", null}}, {bbsfriend_main, {"bbsfriend", null}}, {bbsfoot_main, {"bbsfoot", null}}, {bbsform_main, {"bbsform", null}}, {bbspwd_main, {"bbspwd", null}}, {bbsplan_main, {"bbsplan", null}}, {bbsinfo_main, {" BBSINFO ", NULL}}, {BBSMYBRD_MAIN, {" bbsmybrd ", null}}}, {bbssig_main, {" bbssig "

, Null}}, {"bbspst", "pst", null}}, {bbsgcon_main, {"bbsgcon", "gcon", null}}, {bbsgdoc_main, {"bbsgdoc", "gdoc", NULL }}} {Bbsdel_main, {"bbsdel", "del", null}}, {bbsdelmail_main, {"bbsdelmail", null}}, {bbsmailcon_main, {"bbsmailcon", null}}, {bbsmail_main, {"bbsmail" , "Mail", null}}, {"bbsdelmsg", null}}}}, {bbssnd_main, {"bbssnd", null}}} {bbsnotepad_main, {"bbsnotepad", null}}}, {bbsmsg_main, {" bbsmsg ", NULL}}, {bbssendmsg_main, {" bbssendmsg ", NULL}}, {bbsreg_main, {" bbsreg ", NULL}}, {bbsscanreg_main, {" bbsscanreg ", NULL}}, {bbsmailmsg_main, {" bbsmailmsg " , NULL}}, {bbssndmail_main, { "bbssndmail", NULL}}, {bbsnewmail_main, { "bbsnewmail", NULL}}, {bbspstmail_main, { "bbspstmail", "pstmail", NULL}}, {bbsgetmsg_main, { " "bbsgetmsg", null}}, {"bbschat", null}}, {bbscloak_main, {"bbscloak", null}}, {bbsmdoc_main, {"bbsmdoc", "mdoc", null}}, { Bbsnick_main, {"bbsnick", null}}, {bbstfind_main, {"bbstfind", "tfind", null}}, {bbsadl_main, {"bbsadl", N ULL}}, {BBSTCON_MAIN, {"bbstcon", "tcon", null}}, {bbstdoc_main, {"bbstdoc", "tdoc", null}}, {bbsdoreg_main, {"bbsdoreg", null}}, {bbsmyww_main , {"Bbsmywww", null}}, {bbsccc_main, {"bbsccc", "ccc", null}}, {"bbsufind", null}}, {bbsclear_main, {"bbsclear", "clear ", Null}}, {bbsstat_main, {" bbsstat ", null}}, {bbsedit_main, {" bbsedit "," edit "

, Null}}, {"bbsman", "man", null}}, {bbsparm_main, {"bbsparm", null}}, {bbsfwd_main, {"bbsfwd", "fwd", null}}} bbsmnote_main, { "bbsmnote", NULL}}, {bbsdenyall_main, { "bbsdenyall", NULL}}, {bbsdenydel_main, { "bbsdenydel", NULL}}, {bbsdenyadd_main, { "bbsdenyadd", NULL}}, {bbstopb10_main, {"BBSTOPB10", NULL}}, {bbsbfind_main, {"bbsbfind", "bfind", null}}, {bbsx_main, {"bbsx", null}}, {bbseva_main, {"bbseva", "EVA", NULL }}}, {Bbsvote_main, {"bbsvote", "vote", null}}, {bbsshownav_main, {"bbsshownav", null}}, {bbsbkndoc_main, {"bbsbkndoc", "bkndoc", null}}, {bbsbknsel_main, {"BBSBKNSEL", "BKNSEL", NULL}}, {bbsbkncon_main, {"bbsbkncon", "bkncon", null}}, {bbshome_main, {"bbshome", "home", null}}, {bbsindex_main, {" BBSINDEX ", NULL}}, {" bbssechand ", null}}, // {bbsupload_main, {" bbsupload ", null}}, {bbslform_main, {" bbslform ", null}}, {bbslt_main, {" BBSLT ", NULL}}, {bbsdt_main, {" bbsdt ", null}}, {regReq_main, {" regreq ", null}}, {bbsselstyle_main, {" bbsselstyl e ", null}}, {bbscon1_main, {" bbscon1 "," c1 ", null}}, {bbsattach_main, {" attach ", null}}, {bbskick_main, {" kick ", null}}, {bbsshowfile_main, {"BBSSHOWFILE", "ShowFile", NULL}}, {BBSINCON_MAIN, {"Boards", NULL}}, {bbssetscript_main, {"setscript", null}}} {bbscccmail_main, {"bbscccmail", null}}} BBSFWDMAIL_MAIN, {"bbsfwdmail", null}}, {bbsscanreg_findsurname_main, {"bbsscanreg_findsurname"

转载请注明原文地址:https://www.9cbs.com/read-67123.html

New Post(0)