Subversion Repositories wimsdev

Rev

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