1. Environment
/Usr/local/Apache/htdocs/(the file to be retrieved is in this directory)
/Usr/local/Apache/temp/(as a transit folder)
/Usr/local/Apache/cgi-bin/
2. Place A. Out generated by GCC search. C in/usr/local/Apache/cgi-bin/, and set the permission to nobody.
.
3. chown-r Nobody. Nobody/usr/local/Apache/temp
4. Add the deletetemp permission to/etc/cron. daily to 555.
Rm-F/usr/local/Apache/temp /*
5. Add a file myupdate permission to/etc/cron. Hourly to 555.
Updatedb-U/usr/local/Apache/htdocs
6. delete a file slocate. cron in/etc/cron. daily.
Appendix (2 in total ):
1. Source Code of index.htm
<HTML>
<Head>
<Title> untitled document </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
</Head>
<Body>
<P> enter your query string </P>
<Form name = "form1" Action = "http: // 129.158.217.223/cgi-bin/a. Out">
<P> </P>
<P>
<Input name = "keyname" value = "" type = text>
</P>
<P>
<Input type = "Submit" value = "query">
</P>
</Form>
<P> </P>
</Body>
</Html>
2. Source Code of search. c
# Include <stdio. h>
# Include <stdlib. h>
# Include <unistd. h>
# Include <sys/types. h>
# Include <fcntl. h>
Int main (INT argc, char * argv ())
{
Int FD;
Int status;
Time_t I;
Char cfilename (64 );
Char ctempname (64 );
Char cbuffer (1024 );
Char * P = cbuffer;
Char ccontent (10240 );
Char * data;
Char keyword (1024 );
Data = getenv ("QUERY_STRING ");
If (Data = NULL)
{
Printf ("Content-Type: text/html ");
Printf ("not found! ");
Exit (1 );
}
Sscanf (data, "keyname = % S &", keyword );
P + = sprintf (P, "locate '% s' | sed-E's # ^/usr/local/Apache/htdocs # http: // 129.158.217.223 # '| sed-E's # ^. * $ # <a href = & >&</A>
# '> ", Keyword );
I = Time (null );
Sprintf (ctempname, "shortd.html", I );
Sprintf (cfilename, "/usr/local/Apache/temp/export d.html", I );
Strcat (cbuffer, cfilename );
Cbuffer (1024-1) = 0;
System (cbuffer );
FD = open (cfilename, o_rdwr );
Status = read (FD, ccontent, sizeof (ccontent)-1 );
Close (FD );
Printf ("Content-Type: text/html ");
Printf ("<meta http-equiv = Refresh content = 0; url =" http: // 129.158.217.223/temp/% s ">", ctempname );
Printf ("waiting .......................");
Printf ("% s", keyword );
Return 0;
}