Subversion Repositories wimsdev

Rev

Rev 8302 | Rev 8880 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
  2.  *
  3.  *  This program is free software; you can redistribute it and/or modify
  4.  *  it under the terms of the GNU General Public License as published by
  5.  *  the Free Software Foundation; either version 2 of the License, or
  6.  *  (at your option) any later version.
  7.  *
  8.  *  This program is distributed in the hope that it will be useful,
  9.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.  *  GNU General Public License for more details.
  12.  *
  13.  *  You should have received a copy of the GNU General Public License
  14.  *  along with this program; if not, write to the Free Software
  15.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16.  */
  17.  
  18. /* WWW multipurpose server, header definitions */
  19.  
  20. #include "Lib/libwims.h"
  21. #include "config.h"
  22. #include "includes.h"
  23. #include "wimsdef.h"
  24.  
  25. #define evalue strevalue
  26.  
  27. /* limit of query_string. */
  28. #define QUERY_STRING_LIMIT 204799
  29. /* maximal length of deposited file */
  30. #define MAX_DEPOSITLEN (8*1024*1024)
  31. /* maximal number of registered variables */
  32. #define MAX_VAR_NUM 512
  33. /* length limit for public_html/bin executable names */
  34. #define MAX_EXEC_NAME 31
  35. /* max level of nested fors */
  36. #define MAX_FOR_LEVEL 12
  37. /* max nested read; to avoid infinite loop */
  38. #define MAX_READNEST 20
  39. /* number of cached working files */
  40. #define MAX_MCACHE 32
  41. /* max sort items. */
  42. #define MAX_SORT_ITEM 5000
  43. /* max randperm() items. Should be compatible to MAX_LINELEN. */
  44. #define MAX_RANDPERM 2000
  45. /* Number of session random numbers */
  46. #define MAX_SESRANDOM 64
  47. /* Limit of output length. This can be configured. */
  48. #define OUTPUT_LENGTH_LIMIT (1024*1024)
  49. /* limit of items in value lists */
  50. #define MAX_VALUE_LIST 2048
  51. /* We fix a limit for the number of goto's (or for jumps) executed,
  52.  * in order to avoid infinite loop or DOS attack.
  53.  */
  54. #define GOTO_LIMIT 500000
  55. /* maximal nesting level of substitutions. */
  56. #define SUBST_LIMIT 16
  57. /* Limit for instex, insplot, insPLOT. */
  58. #define INS_LIMIT 500
  59. /* file to hold last output */
  60. #define lastout "last.html"
  61. /* Access policy configuration file */
  62. #define ACCESS_CONF "../log/wims.conf.access"
  63. /* Should not be changed */
  64. #define SESSION_BASE "sessions"
  65. #define S2_BASE "s2"
  66.  
  67. /* Prefix char for exec functions */
  68. #define exec_prefix_char '!'
  69. /* Prefix char for calc functions */
  70. #define calc_prefix_char '!'
  71. /* Prefix char for goto labels */
  72. #define label_prefix_char ':'
  73. /* Prefix for tags in data files */
  74. #define tag_prefix_char ':'
  75. /* Prefix char for comment lines */
  76. #define comment_prefix_char '#'
  77. /* prefix to user variable names */
  78. #define var_prefix "w_"
  79. /* (user) prefix for mathematical fonts */
  80. #define mathfont_prefix "m_"
  81. /* prefix for internal variables */
  82. #define wims_prefix "wims_"
  83. #define wpflen strlen(wims_prefix)
  84. /* name of variable definition file */
  85. #define default_var_def "var.def"
  86. /* Not configured */
  87. #define error_data_string "wims_error_data"
  88. /* Name of files containing error messages. */
  89. #define user_error_msg_file "msg/user_error.phtml"
  90. #define module_error_msg_file "msg/module_error.msg"
  91. /* directory containing log files */
  92. #define log_dir "../log"
  93. #define class_base "../log/classes"
  94. /* What should indicate that a file name given by the user
  95.  * would allow him to go upstairs in the directory tree?
  96.  * We shouldn't use "../", otherwise the user may just specify
  97.  * ".." as name and go upstairs one step.
  98.  */
  99. #define parent_dir_string ".."
  100. /* This one is stronger. */
  101. #define PARENT_DIR_STRING "/../"
  102. /* kernel daemon socket file. Should match that of wimslogd. */
  103. #define ksockfile "../tmp/log/.wimslogd"
  104. /* this directory should not exist. Do not change the definition! */
  105. #define sysmask_trigger_dir "sysmask/stat/trigger"
  106.  
  107. typedef struct {
  108.     int lineno; /* line number */
  109. /*    long fpt; */ /* position in the file */
  110.     char varname[MAX_NAMELEN+1];
  111.     double varval, varend, step;
  112.     char *list_pt, *bufpt;
  113.     int from; /* from ... to ... if 0, list if 1 */
  114. } FOR_STACK;
  115.  
  116. typedef struct {
  117.     char *address;
  118.     short int execcode, varcode;
  119.     int isstart; /* bit 0: start line; bit 1: exec; bit 2: label. bit 3: hard comment. bit 4: soft comment */
  120.     unsigned int llen;
  121. } LINE_STRUCT;
  122.  
  123. typedef struct {
  124.     char name[MAX_FNAME+1];
  125.     int  l;
  126.     int linepointer;
  127. /* nocache bits: 0. !nocache; 1. hard nocache; 2. isfromcache; 3. isbase; */
  128.     short int for_idx, nocache;
  129.     int linecnt;
  130.     char *textbuf;
  131.     LINE_STRUCT *lines;
  132.     FOR_STACK *for_stack;
  133. } WORKING_FILE;
  134.  
  135. /* from auth.c */
  136. extern char loadavg[64];
  137. void check_load(int th);
  138. void auth(void);
  139. void checkrafale(void);
  140. void access_check(int isclass);
  141.  
  142. /* from calc.c */
  143. void calc_tolower(char *p);
  144. void calc_toupper(char *p);
  145. void calc_lookup(char *p);
  146. void calc_randitem(char *p);
  147. void calc_mexec(char *p);
  148. void _calc_exec(char *p, char *arg0, char *arg1, int n);
  149. void calc_detag(char *p);
  150. typedef struct  MYFUNCTION {
  151.     char *name;
  152.     int tag;
  153.     void (*routine) (char *p);
  154. } MYFUNCTION;
  155.  
  156. extern MYFUNCTION calc_routine[];
  157. extern int CALC_FN_NO;
  158.  
  159. void calc_append(char *p);
  160. void calc_charof(char *p);
  161. void calc_checkhost(char *p);
  162. void calc_columnof(char *p);
  163. void calc_daemon(char *p);
  164. void calc_date(char *p);
  165. void calc_debug(char *p);
  166. void calc_declosing(char *p);
  167. void calc_defof(char *p);
  168. void calc_embraced(char *p);
  169. void calc_evalsubst(char *p);
  170. void calc_exec(char *p);
  171. void calc_hex(char *p);
  172. void calc_imgrename(char *p);
  173. void calc_itemof(char *p);
  174. void calc_leveldata(char *p);
  175. void calc_lineof(char *p);
  176. void calc_listfile(char *p);
  177. void calc_listintersect(char *p);
  178. void calc_listunion(char *p);
  179. void calc_listuniq(char *p);
  180. void calc_mailurl(char *p);
  181. void calc_makelist(char *p);
  182. void calc_mathsubst(char *p);
  183. void calc_module(char *p);
  184. void calc_nonempty(char *p);
  185. void calc_pos(char *p);
  186. void calc_product(char *p);
  187. void calc_recordof(char *p);
  188. void calc_recursion(char *p);
  189. void calc_reinput(char *p);
  190. void calc_replace(char *p);
  191. void calc_rowof(char *p);
  192. void calc_rows2lines(char *p);
  193. void calc_select(char *p);
  194. void calc_solve(char *p);
  195. void calc_sort(char *p);
  196. void calc_sum(char *p);
  197. void calc_translate(char *p);
  198. void calc_trim(char *p);
  199. void calc_wordof(char *p);
  200. void calc_values(char *p);
  201.  
  202. /* from config.c */
  203. void setsesdir(char *p);
  204. extern int threshold2, threshold1, rafalvl, modlog;
  205. extern char session_dir[MAX_FNAME+1], s2_dir[MAX_FNAME+1];
  206. extern char temp_log[MAX_FNAME+1]; /* temp log file name */
  207. extern char *cgi_name;
  208. extern int idle_time, idle_time2, idle_time3, OLD_LOG_FILES, GEN_LOG_LIMIT, MODULE_LOG_LIMIT;
  209. extern int backup_hour, site_accounting, examlog_limit;
  210. extern int ANIM_LIMIT;
  211. extern char *header_menu, *insplot_processor;
  212. extern char *home_referer, *home_referer_user, *header_menu_supervisor,
  213.    *header_menu_user, *home_referer_supervisor, *title_page, *html_file;
  214. extern char *aliased_cgi, *insdraw_processor, *mail_opt;
  215. extern int mathalign_base ;
  216. unsigned long create_job_ident(void);
  217. void module_index(void);
  218. extern char *module_about_file, *main_var_proc_file, *var_init_file, *special_font;
  219. extern char var_def_file[256], *var_def_buf;
  220. void define_html_header(void);
  221. extern char *usecookie, *bgcolor;
  222. extern int spec_font;
  223. extern char *config_file; /* Main configure file, this name cannot be configured! */
  224. extern char *intro_file; /* Introduction page name */
  225. extern char *ref_file; /* Reference page */
  226. typedef struct CONFIG_DATA { char *name; int is_integer; void  *address; } CONFIG_DATA;
  227. extern CONFIG_DATA main_config[];
  228. extern int MAIN_CONFIG_NO;
  229. extern char *modindex[];
  230. extern int MODINDEX_NO;
  231. void main_configure(void);
  232. void set_rlimits(void);
  233. void module_configure(void);
  234. void set_job_ident(void);
  235.  
  236. /* from compare.c */
  237. int compare(char *p, int numeric, int lvl);
  238.  
  239. /* from evalue.c */
  240. double evalue(char *p);
  241. char *substit(char *p);
  242. enum {for_in, for_from};
  243. struct forstruct {
  244.     char var[MAX_NAMELEN+1];
  245.     int type;
  246.     double list[MAX_VALUE_LIST];
  247.     char *pos[MAX_VALUE_LIST];
  248.     double from, to, step;
  249. } forstruct;
  250. int cutfor(char *p, char *bufp);
  251. void float2str(double d, char *p);
  252.  
  253. /* from exam.c */
  254. void calc_examdep(char *p);
  255. double currexamscore(int sh);
  256. void check_exam(void);
  257.  
  258. /* from exec.c */
  259. void exec_main(char *p);
  260. void exec_set(char *name);
  261. extern MYFUNCTION exec_routine[];
  262. extern int EXEC_FN_NO;
  263. extern struct distr_cmd { char *name; int (*routine) (char *p, char *list[], int max);
  264.   } distr_cmd[];
  265. extern int distr_cmd_no;
  266. void exec_tail(char *p);
  267. void exec_read(char *p);
  268.  
  269. /* from files.c */
  270. void secure_exec(void);
  271. void fileappend(char *p);
  272. void filewrite(char *p);
  273.  
  274. /* from html.c */
  275. void exec_formbar(char *p);
  276. void exec_formbar(char *p);
  277. void exec_formcheckbox(char *p);
  278. void exec_formradio(char *p);
  279. void exec_formselect(char *p);
  280.  
  281. /* from insmmath.c */
  282. void insmath(char *p);
  283. int instex_ready(char *p, char *n);
  284. char *instex_check_static(char *p);
  285. void calc_instexst(char *p);
  286.  
  287. /* from lines.c */
  288. void accessfile(char *content, char *type, char *s,...);
  289. int checkhostt(char bf2[]);
  290. extern int untrust;
  291. void module_error(char msg[]);
  292. int trusted_module(void);
  293. int checkhost(char *hlist);
  294. void _getdef(char buf[], char *name, char value[]);
  295. void getdef(char *fname, char *name, char value[]);
  296. void _daemoncmd(char *p);
  297. int datafile_check(char *name);
  298. extern int is_class_module;
  299. int find_module_file(char *fname, char buf[], int mode);
  300. int call_ssh(char *s,...);
  301. int _http2env(char outs[], char ins[]);
  302. void slashsubst(char *p);
  303. void internal_error(char msg[]);
  304. char *readfile(char *fname, char buf[], long int buflen); /* mathfonts.c */
  305. int call_sh(char *s,...);
  306. unsigned int datafile_recordnum(char *p);
  307. char *datafile_fnd_record(char *p, int n, char bf[]);
  308. int execredirected(char *cmdf, char *inf, char *outf, char *errf, char *arg[]);
  309. char *mkfname(char buf[], char *s,...);
  310. extern char *trusted_modules;
  311. enum{is_file, is_dir, is_exec, is_fifo, is_socket, is_unknown};
  312. extern struct mxtab {
  313.     char cmd[MAX_EXEC_NAME+1];
  314.     unsigned int fd1, fd2;
  315.     int pipe_stdin[2], pipe_stdout[2], pipe_stderr[2];
  316. } mxtab[MAX_MULTIEXEC];
  317. int ftest(char *fname);
  318. int multiexec(char *cmd, char **abuf);
  319. int wgetline(char buf[], size_t buflen, WORKING_FILE *f);
  320. int open_working_file(WORKING_FILE *f, char *fname);
  321. void close_working_file(WORKING_FILE *f, int cache);
  322. void read_tmp_file(char *p, const char *fname);
  323. void initalarm(void);
  324. extern int var_noexport; /* do not export variable */
  325. enum {mode_default, mode_popup, mode_raw} NAME_MODES;
  326. extern char *manager_site;
  327. void flushoutput(void);
  328. extern char pidbuf[32];
  329. extern char lastdatafile[MAX_FNAME+1];
  330. extern char lastftest[MAX_FNAME+1];
  331. int kerneld(char *p, int bufsize);
  332. void _setdef(char buf[], char *name, char *value);
  333. void output0(char buf[]);
  334. void nph_header(int code);
  335. void delete_pid(void);
  336. void setdef(char *fname, char *name);
  337. void instex_flush(void);
  338. char *DEFAULT_INS_FORMAT;
  339. void tex_nospace(char *p);
  340. int get_cached_file(char *name);
  341. extern off_t ftest_size;
  342. void putlastout(void);
  343. void bad_ident(void);
  344. void create_pid(void);
  345. extern struct sockaddr_un sun;
  346. extern char *lastdata;
  347. extern char *outptr;
  348. extern char outbuf[8192];
  349. extern int http2env(char outs[], char ins[]);
  350.  
  351. /* from log.c */
  352. void user_log(char *p);
  353. void write_logs(void);
  354. void mail_log(char *p);
  355. void flushlog(void);
  356. void post_log(void);
  357. void checklogd(void);
  358.  
  359. /* from mathfonts.c */
  360. void fix_tex_size(void);
  361. extern int current_tex_size, texbasesize;
  362. void _output_(char *s);
  363. void output(char *s,...);
  364. char *mathfont(char *fontname);
  365. extern int usertexsize;
  366.  
  367. /* from mathml.c */
  368. int mathml(char *p, int option);
  369.  
  370. /* from matrix.c */
  371. void rawmatrix(char *p);
  372.  
  373. /* from pedia.c */
  374. void pedia(char *p);
  375.  
  376. /* from rawmath.c */
  377. void htmlmath(char *p);
  378. void mathmlmath(char *p);
  379. void tohttpquery(char *p);
  380. void rawmath(char *p);
  381. void texmath(char *p);
  382. extern int rawmath_easy;
  383. extern struct mathname { char *name; int style; char *replace; } mathname[];
  384. extern int mathname_no;
  385.  
  386. /* from hmname.c */
  387. extern struct hmname { char *name; char *replace; char *replacem;} hmname[];
  388. extern int hmname_no;
  389.  
  390. /* from score.c */
  391. void calc_getscorelast(char *p);
  392. void calc_getscore(char *p);
  393. void calc_getscoremean(char *p);
  394. void calc_getscoreremain(char *p);
  395. void calc_getscorerequire(char *p);
  396. void calc_getscoreweight(char *p);
  397. void calc_getscorelast(char *p);
  398. void calc_getscoretry(char *p);
  399. void calc_getscorebest(char *p);
  400. void calc_getscorelevel(char *p);
  401. void calc_getscorepercent(char *p);
  402. void calc_getscorestatus(char *p);
  403. void calc_examscore(char *p);
  404. void exam_currscore(int esh);
  405. extern double exam_scoredata[MAX_EXOS];
  406. int exam_depcheck(char *deps, int exam);
  407. int getscorestatus(char *classe, int sheet);
  408. int depcheck(char *sh, int exo, char *deps);
  409. extern char rscore_class[MAX_CLASSLEN+1];
  410. extern char rscore_user[MAX_NAMELEN+1];
  411.  
  412. /* from test.c */
  413. void exec_test(char *p);
  414.  
  415. /* from texmath.c */
  416. void _replace_matrix ( char *p , char *s_mat1, char *s_mat2);
  417. extern struct tmathfn {
  418.   char *name; int expind; char *left, *right; void (*routine) (char *p);
  419. } tmathfn[];
  420. extern int tmathfn_no;
  421. extern struct tmathvar { char *name, *tex; } tmathvar[];
  422. extern int tmathvar_no;
  423.  
  424. /* from var.c */
  425. int force_setvar(char *vname,char *vvalue);
  426. char *getvar(char *name);
  427. int setvar(char *vname, char *vval);
  428. void debug_output(void);
  429. void exportall(void);
  430. void unsetvar(char *vname);
  431. void get_var_privileges(void);
  432. char *_getvar(char *vname);
  433. int varsuite(char *stem, int beg, int end, char *pbuf[], int pbuflen);
  434. void lessrafale(void);
  435. extern char *exportvars[]; /* wims_ variables that should be exported */
  436. extern int exportvarcnt;
  437.  
  438. /* from variables.c */
  439. int var_def_check(char *name);
  440. void var_proc(char *fname,int cache);
  441. void phtml_put(char *fname,int cache);
  442. void phtml_put_base(char *fname,int cache);
  443. void set_module_prefix(void);
  444. extern int ispriority;
  445. extern char *sed_prog, *tr_prog, *tex2gif;
  446. void get_static_session_var(void);
  447. void parse_ro_names(void);
  448. int var_def_name(char *n, int v);
  449. void set_init_parm(void);
  450. int session_exists(char *s);
  451. int set_session_prefix(void);
  452. int check_session(void);
  453. void trap_check(char *s);
  454. void set_protocol(void);
  455. void main_phtml_put(char *mname);
  456. void var_init(void); /* initialisation */
  457. void set_variables(void);
  458. void save_session_vars(void);
  459.  
  460. /* from wims.c */
  461. void user_error(char msg[]);
  462. extern int robot_access, wrapexec, good_httpd, multiexec_index, outputing;
  463. extern int rlimit_cpu, new_session, hostcquota, manageable, cmd_type, exec_is_module;
  464. extern int available_lang_no, WORKFILE_LIMIT, isclassmodule, mode, module_defined;
  465. extern char session_prefix[], s2_prefix[];
  466. extern char lang[16];
  467. extern char *remote_addr;
  468. extern time_t nowtime, limtime, limtimex;
  469. extern char *ro_name[];
  470. extern char *mathalign_sup1, *mathalign_sup2; /* see mathalign_base */
  471. extern char *module_dir;
  472. extern char tmplbuf[MAX_LINELEN+1]; /* for temporary uses not thru subroutines. */
  473. extern char cwdbuf[MAX_FNAME+1]; /* store current working directory */
  474. extern char ins_alt[MAX_LINELEN+1]; /* dynamic insertion alternative text */
  475. extern char *bin_dir; /* directory containing executable scripts and programs. */
  476. extern char *tmp_debug;
  477. extern char *instex_style;
  478. extern char session_prefix[MAX_FNAME+1], s2_prefix[MAX_FNAME+1], module_prefix[MAX_FNAME+1];
  479. extern char multiexec_random[64];
  480. extern char class_dir[MAX_FNAME+1]; /* directory name of this class */
  481. extern char *devel_modules, *robot_session;
  482. extern int manager_https, confset, rlimit_fsize, rlimit_as, rlimit_data, rlimit_stack, rlimit_core;
  483. extern int rlimit_rss, rlimit_nproc, rlimit_nofile, rlimit_memlock;
  484. extern int sesrandomtab[MAX_SESRANDOM]; /* session random values */
  485. extern char job_identifier[32];
  486. extern int print_precision, substnest, getvar_len;
  487. extern char pre_language[4];
  488. enum {
  489.     ro_cmd, ro_empty, ro_lang, ro_module, ro_session, ro_special_parm,
  490.       ro_special_parm2, ro_special_parm3, ro_special_parm4, ro_useropts, ro_wsession, ro_subsession, ro_win, ro_worksheet
  491. } RO_NAMES;
  492. extern char *home_module;
  493. extern char class_dir[MAX_FNAME+1]; /* directory name of this class */
  494. char available_lang[MAX_LANGUAGES][4];
  495.  
  496. enum {
  497.     cmd_intro, cmd_new, cmd_renew, cmd_reply, cmd_config, cmd_hint, cmd_help,
  498.       cmd_resume, cmd_next, cmd_getins, cmd_getframe, cmd_getfile, cmd_close,
  499.       cmd_ref
  500. } COMMANDS;
  501. extern char tmp_dir[MAX_FNAME+1]; /* temporary directory */
  502.  
  503. extern char ref_name[2048], ref_base[2048];
  504.  
  505. struct user_variable {
  506.     char *name;
  507.     char *value;
  508. } user_variable[MAX_VAR_NUM];
  509.  
  510. extern int user_var_no;
  511. /* Destinated to module error messages */
  512. WORKING_FILE m_file,svar_file,mcache[MAX_MCACHE];
  513.  
  514. extern int isexam, direct_datafile;
  515. extern char *unsetvars[], *commands[];
  516. extern char exam_sheetexo[32]; /* sheet data of an exam */
  517. extern char nowstr[32];
  518. extern int CMD_NO;
  519. extern int simuxam, parm_restore, exodepOK, user_error_nolog;
  520. extern char examlogd[MAX_FNAME+1]; /* examlog file name */
  521. char examlogf[MAX_FNAME+1]; /* examlog file name */
  522. char mpboundary[1024];
  523. char *stdinbuf;
  524. extern char **environ;      /* table of environment variables */
  525. extern char cookiegot[256], cookieheader[64];
  526. extern int executed_gotos; /* number of goto's executed. to check with GOTO_LIMIT. */
  527. extern int noout, execnt, direct_exec, ismhelp;
  528. extern int readnest; /* nested read count */;
  529. extern char *default_form_method;
  530. extern int insert_no, lastout_file, instex_cnt;
  531. extern char instex_src[MAX_LINELEN+1], instex_fname[MAX_LINELEN+1];
  532. extern char *instex_processor;
  533. extern int instex_usedynamic, httpd_type, mcachecnt, mfilecnt;
  534. extern char *mathalign_sup1, *mathalign_sup2; /* see mathalign_base */
  535. enum {httpd_apache, httpd_wims};
  536. extern int output_length; /* length of the output. */
  537. extern int backslash_insmath, killpid, is_multiexec, exec_wait, getwimstexsize;
  538. extern char *remote_host;
  539. extern char *var_readable, *var_writable, *var_nr, *var_nw, *var_pfx;
  540. extern int RO_NAME_NO, INTERNAL_NAME_NO;
  541. extern struct internal_name {
  542.     char *name; int stat;
  543. } internal_name[];
  544. extern char var_hacking;
  545. extern long int startmtime2;
  546. extern int setcookie, forceresume, user_lang, form_access, session_serial;
  547. extern char *protocol;
  548. void useropts(void);
  549. extern char cookiegot[256], cookieset[256];
  550. extern struct tm *now, Now; /* time of request */
  551. extern int isdevelmodule, defined_var_total, deplen, wims_sheet, wims_exo;
  552. struct VAR_DEF {
  553.     char *name; short int beg,end;
  554.     char allow, log_num, defined_in_parm, unused_padding;
  555. } var_def[MAX_VAR_NUM];
  556.  
  557.  
  558. #if !HAVE_SETENV
  559. int setenv(const char *name, const char *value, int overwrite);
  560. void unsetenv(const char *name);
  561. #endif
  562.