home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / CONTRIB / HTTPD / HTTPD_SO.TAR / httpd_1.3 / src / httpd.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-07  |  16.0 KB  |  632 lines

  1. /*
  2.  * httpd.h: header for simple (ha! not anymore) http daemon
  3.  */
  4.  
  5.  
  6. /* Define one of these according to your system. */
  7. #if defined(SUNOS4)
  8. #define BSD
  9. #undef NO_KILLPG
  10. #undef NO_SETSID
  11. char *crypt(char *pw, char *salt);
  12.  
  13. #elif defined(SOLARIS2)
  14. #undef BSD
  15. #define NO_KILLPG
  16. #undef NO_SETSID
  17. #define bzero(a,b) memset(a,0,b)
  18. #define getwd(d) getcwd(d,MAX_STRING_LEN)
  19.  
  20. #elif defined(IRIX)
  21. #undef BSD
  22. #undef NO_KILLPG
  23. #undef NO_SETSID
  24.  
  25. #elif defined(HPUX)
  26. #undef BSD
  27. #define NO_KILLPG
  28. #undef NO_SETSID
  29. #ifndef _HPUX_SOURCE
  30. #define _HPUX_SOURCE
  31. #endif
  32. #define getwd(d) getcwd(d,MAX_STRING_LEN)
  33.  
  34. #elif defined(AIX)
  35. #undef BSD
  36. #undef NO_KILLPG
  37. #undef NO_SETSID
  38.  
  39. #elif defined(ULTRIX)
  40. #define BSD
  41. #undef NO_KILLPG
  42. #undef NO_SETSID
  43. #define ULTRIX_BRAIN_DEATH
  44. #define NEED_STRDUP
  45.  
  46. #elif defined(OSF1)
  47. #define BSD
  48. #undef NO_KILLPG
  49. #undef NO_SETSID
  50.  
  51. #elif defined(SEQUENT)
  52. #define BSD
  53. #undef NO_KILLPG
  54. #define NO_SETSID
  55. #define NEED_STRDUP
  56. #define tolower(c) (isupper(c) ? tolower(c) : c)
  57.  
  58. #elif defined(NEXT)
  59. #define BSD
  60. #undef NO_KILLPG
  61. #define NO_SETSID
  62. #define NEED_STRDUP
  63. #undef _POSIX_SOURCE
  64. #ifndef S_ISDIR
  65. #define S_ISDIR(m)      (((m)&(S_IFMT)) == (S_IFDIR))
  66. #endif
  67. #ifndef S_ISREG
  68. #define S_ISREG(m)      (((m)&(S_IFMT)) == (S_IFREG))
  69. #endif
  70. #ifndef S_IXUSR
  71. #define S_IXUSR 00100
  72. #endif
  73. #ifndef S_IXGRP
  74. #define S_IXGRP 00010
  75. #endif
  76. #ifndef S_IXOTH
  77. #define S_IXOTH 00001
  78. #endif
  79. #ifndef S_IRUSR
  80. #define S_IRUSR S_IREAD
  81. #endif
  82. #ifndef S_IWUSR
  83. #define S_IWUSR S_IWRITE
  84. #endif
  85. #define STDIN_FILENO  0
  86. #define STDOUT_FILENO 1
  87. #define STDERR_FILENO 2
  88. #define waitpid(a,b,c) wait4(a,b,c,NULL)
  89. typedef int pid_t;
  90.  
  91. #elif defined(LINUX)
  92. #undef BSD
  93. #undef NO_KILLPG
  94. #undef NO_SETSID
  95. #undef NEED_STRDUP
  96.  
  97. #elif defined(SCO)
  98. #undef BSD
  99. #undef NO_KILLPG
  100. #undef NO_SETSID
  101. #define NEED_INITGROUPS
  102.  
  103. #elif defined(CONVEXOS)
  104. #define BSD
  105. #define NEED_STRDUP
  106. #define getwd(d) getcwd(d,MAX_STRING_LEN)
  107.  
  108. #elif defined(AUX)
  109. #define BSD
  110. #undef NO_KILLPG
  111. #undef NO_SETSID
  112. #define NEED_STRDUP
  113. #define _POSIX_SOURCE
  114.  
  115. #elif defined(SVR4)
  116. #define NO_KILLPG
  117. #undef  NO_SETSID
  118. #undef NEED_STRDUP
  119. #define NEED_STRCASECMP
  120. #define NEED_STRNCASECMP
  121. #define bzero(a,b) memset(a,0,b)
  122.  
  123. #elif defined(__NetBSD__)
  124. #define BSD
  125. #undef NO_KILLPG
  126. #undef NO_SETSID
  127.  
  128. #elif defined(UTS21)
  129. #undef BSD
  130. #undef NO_KILLPG
  131. #define NO_SETSID
  132. #define NEED_WAITPID
  133. #define STDIN_FILENO 0
  134. #define STDOUT_FILENO 1
  135. #define STDERR_FILENO 2
  136. #define strftime(buf,bufsize,fmt,tm)    ascftime(buf,fmt,tm)
  137. #include <sys/types.h>
  138.  
  139. #elif defined(APOLLO)
  140. #define BSD
  141. #undef NO_KILLPG
  142. #undef NO_SETSID
  143.  
  144. /* Unknown system - Edit these to match */
  145. #else
  146. /* BSD is whether your system uses BSD calls or System V calls. */
  147. #define BSD
  148. /* NO_KILLPG is set on systems that don't have killpg */
  149. #undef NO_KILLPG
  150. /* NO_SETSID is set on systems that don't have setsid */
  151. #undef NO_SETSID
  152. /* NEED_STRDUP is set on stupid systems that don't have strdup. */
  153. #undef NEED_STRDUP
  154. #endif
  155.  
  156. /*
  157.  * The particular directory style your system supports. If you have dirent.h
  158.  * in /usr/include (POSIX) or /usr/include/sys (SYSV), #include 
  159.  * that file and define DIR_TYPE to be dirent. Otherwise, if you have 
  160.  * /usr/include/sys/dir.h, define DIR_TYPE to be direct and include that
  161.  * file. If you have neither, I'm confused.
  162.  */
  163.  
  164. #include <sys/types.h>
  165.  
  166. #if !defined(NEXT) && !defined(CONVEXOS)
  167. #include <dirent.h>
  168. #define DIR_TYPE dirent
  169. #else
  170. #include <sys/dir.h>
  171. #define DIR_TYPE direct
  172. #endif
  173.  
  174. /* ----------------------------- config dir ------------------------------ */
  175.  
  176. /* Define this to be the default server home dir. Anything later in this
  177.  * file with a relative pathname will have this added.
  178.  */
  179. #define HTTPD_ROOT "/usr/local/etc/httpd"
  180.  
  181. /* Root of server */
  182. #define DOCUMENT_LOCATION "/usr/local/etc/httpd/htdocs"
  183.  
  184. /* Max. number of aliases */
  185. #define MAX_ALIASES 20
  186.  
  187. /* Max. number of security defines */
  188. #define MAX_SECURITY 50
  189.  
  190. /* Default administrator's address */
  191. #define DEFAULT_ADMIN "[no address given]"
  192.  
  193. /* 
  194.  * --------- You shouldn't have to edit anything below this line ----------
  195.  *
  196.  * Any modifications to any defaults not defined above should be done in the 
  197.  * respective config. file. 
  198.  *
  199.  */
  200.  
  201.  
  202. /* -------------- Port number for server running standalone --------------- */
  203.  
  204. #define DEFAULT_PORT 80
  205.  
  206. /* --------- Default user name and group name running standalone ---------- */
  207. /* --- These may be specified as numbers by placing a # before a number --- */
  208.  
  209. #define DEFAULT_USER "#-1"
  210. #define DEFAULT_GROUP "#-1"
  211.  
  212. /* The name of the log files */
  213. #define DEFAULT_XFERLOG "logs/access_log"
  214. #define DEFAULT_ERRORLOG "logs/error_log"
  215. #define DEFAULT_PIDLOG "logs/httpd.pid"
  216.  
  217. /* Define this to be what your HTML directory content files are called */
  218. #define DEFAULT_INDEX "index.html"
  219.  
  220. /* Define this to 1 if you want fancy indexing, 0 otherwise */
  221. #define DEFAULT_INDEXING 0
  222.  
  223. /* Define this to be what type you'd like returned for files with unknown */
  224. /* suffixes */
  225. #define DEFAULT_TYPE "text/html"
  226.  
  227. /* Define this to be what your per-directory security files are called */
  228. #define DEFAULT_ACCESS_FNAME ".htaccess"
  229.  
  230. /* The name of the server config file */
  231. #define SERVER_CONFIG_FILE "conf/httpd.conf"
  232.  
  233. /* The name of the document config file */
  234. #define RESOURCE_CONFIG_FILE "conf/srm.conf"
  235.  
  236. /* The name of the MIME types file */
  237. #define TYPES_CONFIG_FILE "conf/mime.types"
  238.  
  239. /* The name of the access file */
  240. #define ACCESS_CONFIG_FILE "conf/access.conf"
  241.  
  242. /* Whether we should enable rfc931 identity checking */
  243. #define DEFAULT_RFC931 0
  244. /* The default directory in user's home dir */
  245. #define DEFAULT_USER_DIR "public_html"
  246.  
  247. /* The default path for CGI scripts if none is currently set */
  248. #define DEFAULT_PATH "/bin:/usr/bin:/usr/ucb:/usr/bsd:/usr/local/bin"
  249.  
  250. /* The path to the Bourne shell, for parsed docs */
  251. #define SHELL_PATH "/bin/sh"
  252.  
  253. /* The default string lengths */
  254. #define MAX_STRING_LEN 256
  255. #define HUGE_STRING_LEN 8192
  256.  
  257. /* The timeout for waiting for messages */
  258. #define DEFAULT_TIMEOUT 1200
  259.  
  260. /* The size of the server's internal read-write buffers */
  261. #define IOBUFSIZE 8192
  262.  
  263. /* The number of header lines we will accept from a client */
  264. #define MAX_HEADERS 200
  265.  
  266. /* Hi Roy. */
  267. #define HTTP_TIME_FORMAT "%A, %d-%b-%y %T GMT"
  268.  
  269. /* ------------------------------ error types ------------------------------ */
  270.  
  271. #define SERVER_VERSION "NCSA/1.3"
  272. #define SERVER_PROTOCOL "HTTP/1.0"
  273. #define SERVER_SUPPORT "httpd@ncsa.uiuc.edu"
  274.  
  275. #define DOCUMENT_FOLLOWS 200
  276. #define REDIRECT 302
  277. #define USE_LOCAL_COPY 304
  278. #define BAD_REQUEST 400
  279. #define AUTH_REQUIRED 401
  280. #define FORBIDDEN 403
  281. #define NOT_FOUND 404
  282. #define SERVER_ERROR 500
  283. #define NOT_IMPLEMENTED 501
  284. #define NO_MEMORY 6992
  285.  
  286. #define METHODS 4
  287. #define M_GET 0
  288. #define M_PUT 1
  289. #define M_POST 2
  290. #define M_DELETE 3
  291.  
  292. /* Object types */
  293. #define REDIRECT_URL -1
  294. #define STD_DOCUMENT 0
  295. #define SCRIPT_NCSA 1
  296. #define SCRIPT_CGI 2
  297.  
  298. #define OPT_NONE 0
  299. #define OPT_INDEXES 1
  300. #define OPT_INCLUDES 2
  301. #define OPT_SYM_LINKS 4
  302. #define OPT_EXECCGI 8
  303. #define OPT_UNSET 16
  304. #define OPT_INCNOEXEC 32
  305. #define OPT_SYM_OWNER 64
  306. #define OPT_ALL (OPT_INDEXES|OPT_INCLUDES|OPT_SYM_LINKS|OPT_EXECCGI)
  307.  
  308. #define OR_NONE 0
  309. #define OR_LIMIT 1
  310. #define OR_OPTIONS 2
  311. #define OR_FILEINFO 4
  312. #define OR_AUTHCFG 8
  313. #define OR_INDEXES 16
  314. #define OR_ALL (OR_LIMIT|OR_OPTIONS|OR_FILEINFO|OR_AUTHCFG|OR_INDEXES)
  315.  
  316. #define CGI_MAGIC_TYPE "application/x-httpd-cgi"
  317. #define INCLUDES_MAGIC_TYPE "text/x-server-parsed-html"
  318.  
  319. /* For directory indexing */
  320. #define BY_PATH 0
  321. #define BY_TYPE 1
  322. #define BY_ENCODING 2
  323.  
  324. #define FANCY_INDEXING 1
  325. #define ICONS_ARE_LINKS 2
  326. #define SCAN_HTML_TITLES 4
  327. #define SUPPRESS_LAST_MOD 8
  328. #define SUPPRESS_SIZE 16
  329. #define SUPPRESS_DESC 32
  330.  
  331. #include <stdio.h>
  332. #include <stdlib.h>
  333. #include <string.h>
  334. #include <sys/stat.h>
  335. #include <sys/file.h>
  336. #include <sys/socket.h>
  337. #include <ctype.h>
  338. #include <netinet/in.h>
  339. #include <netdb.h>
  340. #include <sys/ioctl.h>
  341. #include <arpa/inet.h>  /* for inet_ntoa */
  342. #include <time.h>  /* for ctime */
  343. #include <signal.h>
  344. #include <errno.h>
  345. #include <sys/wait.h>
  346. #include <pwd.h>
  347. #include <grp.h>
  348. #include <fcntl.h>
  349.  
  350. #ifndef NEXT
  351. #include <unistd.h>
  352. #endif
  353.  
  354. #ifdef ultrix
  355. #define ULTRIX_BRAIN_DEATH
  356. #endif
  357.  
  358. /* Just in case your linefeed isn't the one the other end is expecting. */
  359. #define LF 10
  360. #define CR 13
  361.  
  362. /* For access control */
  363. #define DENY_THEN_ALLOW 0
  364. #define ALLOW_THEN_DENY 1
  365. #define MUTUAL_FAILURE 2
  366.  
  367. /* Struct shared by access and auth */
  368. typedef struct {
  369.     char *d;
  370.     char opts;
  371.     char override;
  372.  
  373.     int order[METHODS];
  374.  
  375.     int num_allow[METHODS];
  376.     char *allow[METHODS][MAX_SECURITY];
  377.     int num_auth[METHODS];
  378.     char *auth[METHODS][MAX_SECURITY];
  379.  
  380.     char *auth_type;
  381.     char *auth_name;
  382.     char *auth_pwfile;
  383.     char *auth_grpfile;
  384.  
  385.     int num_deny[METHODS];
  386.     char *deny[METHODS][MAX_SECURITY];
  387. } security_data;
  388.  
  389. /* Global, global, who's got the globals? */
  390.  
  391. /* Server config */
  392. extern int standalone;
  393. extern int port;
  394. extern uid_t user_id;
  395. extern gid_t group_id;
  396. extern char server_root[MAX_STRING_LEN];
  397. extern char error_fname[MAX_STRING_LEN];
  398. extern char xfer_fname[MAX_STRING_LEN];
  399. extern char pid_fname[MAX_STRING_LEN];
  400. extern char server_admin[MAX_STRING_LEN];
  401. extern char *server_hostname;
  402. extern char server_confname[MAX_STRING_LEN];
  403. extern char srm_confname[MAX_STRING_LEN];
  404. extern char access_confname[MAX_STRING_LEN];
  405. extern char types_confname[MAX_STRING_LEN];
  406. extern int timeout;
  407. extern int do_rfc931;
  408. #ifdef PEM_AUTH
  409. extern char auth_pem_decrypt[MAX_STRING_LEN];
  410. extern char auth_pem_encrypt[MAX_STRING_LEN];
  411. extern char auth_pem_entity[MAX_STRING_LEN];
  412. extern char auth_pgp_decrypt[MAX_STRING_LEN];
  413. extern char auth_pgp_encrypt[MAX_STRING_LEN];
  414. extern char auth_pgp_entity[MAX_STRING_LEN];
  415. #endif
  416.  
  417. /* Document config */
  418. extern char user_dir[MAX_STRING_LEN];
  419. extern char index_name[MAX_STRING_LEN];
  420. extern char access_name[MAX_STRING_LEN];
  421. extern char document_root[MAX_STRING_LEN];
  422. extern char default_type[MAX_STRING_LEN];
  423. extern char default_icon[MAX_STRING_LEN];
  424. extern char blank_icon[MAX_STRING_LEN];
  425. extern int fancy_indexing;
  426. extern char readme_fname[MAX_STRING_LEN];
  427.  
  428. /* Security config */
  429. extern int num_sec;
  430. extern security_data sec[MAX_SECURITY];
  431.  
  432. /* Auth config */
  433. extern char *auth_type;
  434. extern char *auth_name;
  435. extern char *auth_pwfile;
  436. extern char *auth_grpfile;
  437. extern char user[MAX_STRING_LEN];
  438. #ifdef PEM_AUTH
  439. extern int doing_pem;
  440. #endif
  441.  
  442. /* Request information */
  443. extern int assbackwards;
  444. extern int header_only;
  445. extern char *remote_host;
  446. extern char *remote_ip;
  447. extern char *remote_name;
  448. extern char *remote_logname;
  449. extern int allow;
  450. extern char allow_options;
  451. extern int num_includes;
  452. extern int dirs_in_alias;
  453.  
  454. /* MIME */
  455. extern char auth_line[MAX_STRING_LEN];
  456. extern int content_length;
  457. extern char content_type[MAX_STRING_LEN];
  458. extern char content_encoding[MAX_STRING_LEN];
  459. extern char location[MAX_STRING_LEN];
  460. extern char **in_headers_env;
  461.  
  462. /* http_log */
  463. extern FILE *error_log;
  464. extern int bytes_sent;
  465. extern int status;
  466.  
  467. /* Function prototypes. */
  468.  
  469. /* http_config */
  470. void read_config();
  471. void parse_htaccess(char *dir, char override, FILE *out);
  472. int get_pw(char *user, char *pw, FILE *errors);
  473. int in_group(char *user, char *group);
  474. int init_group(char *grpfile, FILE *out);
  475. void kill_group();
  476.  
  477. /* http_alias */
  478. void reset_aliases();
  479. void dump_aliases();
  480. void add_alias(char *f, char *r, int is_script);
  481. void add_redirect(char *f, char *url);
  482. int translate_name(char *name,FILE *fd);
  483. void unmunge_name(char *name);
  484.  
  485. /* http_request */
  486. void process_request(int in, FILE *out);
  487. void send_fd(FILE *f, FILE *fd, void (*callback)());
  488. void send_fd_timed_out();
  489. int find_script(char *method, char *name, char *args, int in, FILE *out);
  490.  
  491. /* http_get */
  492. void send_file(char *file, FILE *fd, struct stat *fi, 
  493.                char *path_args, char *args);
  494. void process_include(FILE *f, FILE *fd, char *incstring, char *args);
  495. void send_node(char *name, char *args, int in, FILE *fd);
  496. void process_get(int in, FILE *out, char *m, char *url, char *args);
  497.  
  498. /* http_post */
  499. void post_node(char *name, char *args, int in, FILE *out);
  500.  
  501. /* http_put */
  502. void put_node(char *name, char *args, int in, FILE *out);
  503.  
  504. /* http_delete */
  505. void delete_node(char *name, char *args, int in, FILE *out);
  506.  
  507. /* http_script */
  508. void exec_cgi_script(char *method, char *path, char *args, int in, FILE *out);
  509. int cgi_stub(char *method, char *path, char *path_args, char *args,
  510.              char **env, struct stat *finfo, int in, FILE *out);
  511. void exec_get_NCSA(char *path, char *args, int in, FILE *fd);
  512. void exec_post_NCSA(char *path, char *args, int in, FILE *out);
  513. char **add_common_vars(char **env, FILE *out);
  514. void get_path_info(char *path, char *path_args, FILE *out, 
  515.                    struct stat *finfo);
  516.  
  517. /* http_dir */
  518. void index_directory(char *name, FILE *fd);
  519. void add_icon(int type, char *icon, char *to, char *path, FILE *out);
  520. void add_alt(int type, char *alt, char *to, char *path, FILE *out);
  521. void add_desc(int type, char *desc, char *to, char *path, FILE *out);
  522. void add_ignore(char *ext, char *path, FILE *out);
  523. void add_header(char *name, char *path, FILE *out);
  524. void add_readme(char *name, char *path, FILE *out);
  525. void add_opts(char *optstr, char *path, FILE *out);
  526. void add_opts_int(int opts, char *path, FILE *out);
  527. void send_size(size_t size, FILE *fd);
  528.  
  529. void init_indexing();
  530. void kill_indexing();
  531.  
  532. /* http_log */
  533. void record_request(char *cmd_line);
  534. void log_error(char *err);
  535. void log_error_noclose(char *err);
  536. void log_reason(char *reason, char *file);
  537. void die(int type, char *err_string, FILE *fd);
  538. void open_logs();
  539. void close_logs();
  540. void begin_http_header(FILE *fd, char *msg);
  541. void error_log2stderr();
  542. void log_transaction();
  543.  
  544. /* http_mime */
  545. void get_mime_headers(int fd, FILE *out);
  546. void init_header_vars();
  547. void send_http_header(FILE *fd);
  548. void set_content_type(char *fn);
  549. void set_last_modified(time_t t, FILE *out);
  550. void probe_content_type(char *fn);
  551. int scan_script_header(FILE *f, FILE *fd);
  552. void add_type(char *fn, char *t,FILE *out);
  553. void add_encoding(char *fn, char *t,FILE *out);
  554. void set_content_length(int l);
  555. void dump_types();
  556. void init_mime();
  557. void kill_mime();
  558. int is_content_type(char *type);
  559. void dump_default_header(FILE *fd);
  560.  
  561. /* http_access */
  562. void evaluate_access(char *path, struct stat *finfo,int m, int *allow, 
  563.                             char *op, FILE *out);
  564. void kill_security();
  565.  
  566. /* http_auth */
  567. void check_auth(security_data *s, int m, FILE *out);
  568. #ifdef PEM_AUTH
  569. int decrypt_request(int sfd, char *req, FILE **out);
  570. void htexit(int status, FILE *out);
  571. #endif
  572.  
  573. /* http_include */
  574. void send_parsed_file(char *file, FILE *fd, char *path_args, char *args,
  575.                       int noexec);
  576.  
  577. /* util */
  578. void chdir_file(char *file);
  579. void http2cgi(char *w);
  580. int later_than(struct tm *tms, char *i);
  581. int strcmp_match(char *str, char *exp);
  582. int is_matchexp(char *str);
  583. void strsubfirst(int start,char *dest, char *src);
  584. void make_full_path(char *src1,char *src2,char *dst);
  585. int is_directory(char *name);
  586. void getparents(char *name);
  587. void no2slash(char *name);
  588. uid_t uname2id(char *name);
  589. gid_t gname2id(char *name);
  590. int getline(char *s, int n, int f, unsigned int timeout);
  591. int cfg_getline(char *s, int n, FILE *f);
  592. void getword(char *word, char *line, char stop);
  593. void cfg_getword(char *word, char *line);
  594. void get_remote_host(int fd);
  595. char *get_time();
  596. char *gm_timestr_822(time_t t);
  597. char *ht_time(time_t t, char *fmt, int gmt);
  598. struct tm *get_gmtoff(long *tz);
  599. void make_dirstr(char *s, int n, char *d);
  600. int count_dirs(char *path);
  601. void strcpy_dir(char *d, char *s);
  602. void unescape_url(char *url);
  603. void escape_url(char *url);
  604. void escape_shell_cmd(char *cmd);
  605. void plustospace(char *str);
  606. void spacetoplus(char *str);
  607. void str_tolower(char *str);
  608. void uudecode(char *s,unsigned char *d,int dl);
  609. #ifdef NEED_STRDUP
  610. char *strdup (char *str);
  611. #endif
  612. #ifdef NEED_STRCASECMP
  613. int strcasecmp(const char *s1, const char *s2);
  614. #endif
  615. #ifdef NEED_STRNCASECMP
  616. int strncasecmp(const char *s1, const char *s2, int n);
  617. #endif
  618. char *make_env_str(char *n, char *v, FILE *out);
  619. char **new_env(char **env, int to_add, int *pos);
  620. void free_env(char **env);
  621. int ind(char *s, char c);
  622. int rind(char *s, char c);
  623. void construct_url(char *d, char *s);
  624. void get_local_host();
  625. int get_portnum(int sd,FILE *out);
  626. int can_exec(struct stat *finfo);
  627. #ifdef NEED_INITGROUPS
  628. int initgroups(const char *name, gid_t basegid);
  629. #endif
  630. char *get_remote_logname(FILE *fd);
  631. char *rfc931(struct sockaddr_in *rmt_sin,struct sockaddr_in *our_sin);
  632.