Rev 5505 | Rev 8067 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5505 | Rev 7646 | ||
---|---|---|---|
Line 77... | Line 77... | ||
77 | case 301: cstr="Moved Permanently"; break; |
77 | case 301: cstr="Moved Permanently"; break; |
78 | case 302: cstr="Moved Temporarily"; break; |
78 | case 302: cstr="Moved Temporarily"; break; |
79 | case 420: cstr="WIMS Nested Error"; break; |
79 | case 420: cstr="WIMS Nested Error"; break; |
80 | case 450: cstr="WIMS User Error"; break; |
80 | case 450: cstr="WIMS User Error"; break; |
81 | case 500: cstr="WIMS Internal Error"; break; |
81 | case 500: cstr="WIMS Internal Error"; break; |
82 | case 550: cstr="WIMS Module Error"; break; |
82 | case 550: cstr="WIMS Module Error"; break; |
83 | default: cstr="ERROR"; break; |
83 | default: cstr="ERROR"; break; |
84 | } |
84 | } |
85 | if(httpd_type!=httpd_wims) printf("Status: %d %s\r\n",code,cstr); |
85 | if(httpd_type!=httpd_wims) printf("Status: %d %s\r\n",code,cstr); |
86 | else { |
86 | else { |
87 | char *p, tbuf[256]; |
87 | char *p, tbuf[256]; |
Line 131... | Line 131... | ||
131 | char *p1, *p2; |
131 | char *p1, *p2; |
132 | char buf[MAX_LINELEN+1]; |
132 | char buf[MAX_LINELEN+1]; |
133 | for(p1=buf,p2=p;*p2 && p1-buf<MAX_LINELEN-4;p2++) { |
133 | for(p1=buf,p2=p;*p2 && p1-buf<MAX_LINELEN-4;p2++) { |
134 | if(!isspace(*p2)) {*p1++=*p2;continue;} |
134 | if(!isspace(*p2)) {*p1++=*p2;continue;} |
135 | while(isspace(*p2)) p2++; |
135 | while(isspace(*p2)) p2++; |
136 | if(*(p1-1)=='\\' || |
136 | if(*(p1-1)=='\\' || |
137 | (p1>buf && myisalnum(*(p1-1)) && myisalnum(*p2))) |
137 | (p1>buf && myisalnum(*(p1-1)) && myisalnum(*p2))) |
138 | *p1++=' '; |
138 | *p1++=' '; |
139 | *p1++=*p2; |
139 | *p1++=*p2; |
140 | } |
140 | } |
141 | *p1++=0; memmove(p,buf,p1-buf); |
141 | *p1++=0; memmove(p,buf,p1-buf); |
Line 219... | Line 219... | ||
219 | } |
219 | } |
220 | } |
220 | } |
221 | fd=open(fname,O_RDONLY); if(fd==-1) return NULL; |
221 | fd=open(fname,O_RDONLY); if(fd==-1) return NULL; |
222 | if(buf==NULL) bf=xmalloc(l+8); else {bf=buf;if(l==0) {t=1; l=buflen-1;}} |
222 | if(buf==NULL) bf=xmalloc(l+8); else {bf=buf;if(l==0) {t=1; l=buflen-1;}} |
223 | lc=read(fd,bf,l); close(fd); |
223 | lc=read(fd,bf,l); close(fd); |
224 | if(lc<0 || lc>l || (lc!=l && t==0)) |
224 | if(lc<0 || lc>l || (lc!=l && t==0)) |
225 | {if(buf==NULL) free(bf); else buf[0]=0; return NULL;} |
225 | {if(buf==NULL) free(bf); else buf[0]=0; return NULL;} |
226 | bf[lc]=0; _tolinux(bf); return bf; |
226 | bf[lc]=0; _tolinux(bf); return bf; |
227 | } |
227 | } |
228 | 228 | ||
229 | /* Get a line in a stored working file. |
229 | /* Get a line in a stored working file. |
230 | * Buffer length is always MAX_LINELEN. */ |
230 | * Buffer length is always MAX_LINELEN. */ |
231 | int wgetline(char buf[], size_t buflen, WORKING_FILE *f) |
231 | int wgetline(char buf[], size_t buflen, WORKING_FILE *f) |
232 | { |
232 | { |
233 | int i,j; unsigned int n; |
233 | int i,j; unsigned int n; |
234 | i=f->linepointer; buf[0]=0; |
234 | i=f->linepointer; buf[0]=0; |
Line 362... | Line 362... | ||
362 | error_status=1; |
362 | error_status=1; |
363 | mkfname(erfname,"%s.%s",user_error_msg_file,lang); |
363 | mkfname(erfname,"%s.%s",user_error_msg_file,lang); |
364 | if(ftest(erfname)!=is_file) internal_error("user_error(): error message file not found.\n\ |
364 | if(ftest(erfname)!=is_file) internal_error("user_error(): error message file not found.\n\ |
365 | Bad installation."); |
365 | Bad installation."); |
366 | force_setvar("wims_user_error",msg); |
366 | force_setvar("wims_user_error",msg); |
367 | if(strcmp(msg,"threshold")!=0) user_error_log(msg); |
367 | if(strcmp(msg,"threshold")!=0) user_error_log(msg); |
368 | memmove(module_prefix,".",2); |
368 | memmove(module_prefix,".",2); |
369 | if(lastout_file!=-1 && outputing) { |
369 | if(lastout_file!=-1 && outputing) { |
370 | flushoutput(); close(lastout_file); lastout_file=-1; |
370 | flushoutput(); close(lastout_file); lastout_file=-1; |
371 | } |
371 | } |
372 | nph_header(450); |
372 | nph_header(450); |
373 | phtml_put_base(erfname,0); |
373 | phtml_put_base(erfname,0); |
374 | if(strcmp(msg,"double_click")!=0) delete_pid(); |
374 | if(strcmp(msg,"double_click")!=0) delete_pid(); |
375 | else { |
375 | else { |
376 | cleantmpdir(); flushlog(); |
376 | cleantmpdir(); flushlog(); |
377 | } |
377 | } |
378 | flushoutput(); exit(0); |
378 | flushoutput(); exit(0); |
379 | } |
379 | } |
Line 498... | Line 498... | ||
498 | int trusted_module(void) |
498 | int trusted_module(void) |
499 | { |
499 | { |
500 | char *modname, *w, buf[MAX_LINELEN+1]; |
500 | char *modname, *w, buf[MAX_LINELEN+1]; |
501 | int i,n; |
501 | int i,n; |
502 | static int _trusted=-1; /* avoid repeated computations */ |
502 | static int _trusted=-1; /* avoid repeated computations */ |
503 | 503 | ||
504 | if(untrust&255) return 0; |
504 | if(untrust&255) return 0; |
505 | if(_trusted>=0) return _trusted; |
505 | if(_trusted>=0) return _trusted; |
506 | modname=getvar(ro_name[ro_module]); |
506 | modname=getvar(ro_name[ro_module]); |
507 | if(modname==NULL || *modname==0) return 0; |
507 | if(modname==NULL || *modname==0) return 0; |
508 | if(memcmp(modname,"adm/",strlen("adm/"))==0 || |
508 | if(memcmp(modname,"adm/",strlen("adm/"))==0 || |
509 | memcmp(modname,"classes/",strlen("classes/"))==0 || |
509 | memcmp(modname,"classes/",strlen("classes/"))==0 || |
510 | strcmp(modname,home_module)==0 || |
510 | strcmp(modname,home_module)==0 || |
511 | memcmp(modname,"help/",strlen("help/"))==0) { |
511 | memcmp(modname,"help/",strlen("help/"))==0) { |
512 | tr: |
512 | tr: |
513 | if(memcmp(modname,"classes/",strlen("classes/"))==0) |
513 | if(memcmp(modname,"classes/",strlen("classes/"))==0) |
514 | is_class_module=1; |
514 | is_class_module=1; |
Line 519... | Line 519... | ||
519 | w=fnd_word(trusted_modules,i+1,buf); |
519 | w=fnd_word(trusted_modules,i+1,buf); |
520 | if(strcmp(w,modname)==0) goto tr; |
520 | if(strcmp(w,modname)==0) goto tr; |
521 | } |
521 | } |
522 | return _trusted=0; |
522 | return _trusted=0; |
523 | } |
523 | } |
524 | 524 | ||
525 | /* file should be in the module directory, but |
525 | /* file should be in the module directory, but |
526 | * it may also be somewhere else. |
526 | * it may also be somewhere else. |
527 | * buf[] requires MAX_FNAME+1 length. |
527 | * buf[] requires MAX_FNAME+1 length. |
528 | * Returns 0 if found. */ |
528 | * Returns 0 if found. */ |
529 | int find_module_file(char *fname, char buf[], int mode) |
529 | int find_module_file(char *fname, char buf[], int mode) |
530 | { |
530 | { |
531 | char *p, dtest[32]; |
531 | char *p, dtest[32]; |
532 | 532 | ||
533 | fname=find_word_start(fname); |
533 | fname=find_word_start(fname); |
534 | if(*fname==0) return -1; |
534 | if(*fname==0) return -1; |
535 | /* Name checking: no directory backtracing. */ |
535 | /* Name checking: no directory backtracing. */ |
536 | if(strstr(fname,parent_dir_string)!=NULL) { |
536 | if(strstr(fname,parent_dir_string)!=NULL) { |
537 | setvar(error_data_string,fname); module_error("illegal_fname"); |
537 | setvar(error_data_string,fname); module_error("illegal_fname"); |
Line 550... | Line 550... | ||
550 | mkfname(buf,"%s/%s",tmp_dir,p+1); |
550 | mkfname(buf,"%s/%s",tmp_dir,p+1); |
551 | } |
551 | } |
552 | else { |
552 | else { |
553 | mkfname(buf,"w/%s/%s",module_prefix,p+1); |
553 | mkfname(buf,"w/%s/%s",module_prefix,p+1); |
554 | } |
554 | } |
555 | untrust|=4; |
555 | untrust|=4; |
556 | } |
556 | } |
557 | else { |
557 | else { |
558 | openit: mkfname(buf,"%s/%s",module_prefix,fname); |
558 | openit: mkfname(buf,"%s/%s",module_prefix,fname); |
559 | } |
559 | } |
560 | if(mode) return 0; |
560 | if(mode) return 0; |
Line 562... | Line 562... | ||
562 | if(lastftype==is_exec) { |
562 | if(lastftype==is_exec) { |
563 | isexec: |
563 | isexec: |
564 | setvar("executable",fname); module_error("executable"); |
564 | setvar("executable",fname); module_error("executable"); |
565 | return -1; |
565 | return -1; |
566 | } |
566 | } |
567 | if(strncmp(fname,"adm/",4)==0 && |
567 | if(strncmp(fname,"adm/",4)==0 && |
568 | (!trusted_module() || is_class_module)) return -1; |
568 | (!trusted_module() || is_class_module)) return -1; |
569 | mkfname(buf,"scripts/%s",fname); |
569 | mkfname(buf,"scripts/%s",fname); |
570 | lastopen: |
570 | lastopen: |
571 | if(mode) return 0; |
571 | if(mode) return 0; |
572 | if(ftest(buf)!=is_file) { |
572 | if(ftest(buf)!=is_file) { |
Line 579... | Line 579... | ||
579 | 579 | ||
580 | /* check whether a file is user-submitted */ |
580 | /* check whether a file is user-submitted */ |
581 | /* This is deprecated because of the wimshome/ method. */ |
581 | /* This is deprecated because of the wimshome/ method. */ |
582 | /* int user_file(char *name) { |
582 | /* int user_file(char *name) { |
583 | if(name[0]=='/' || name[0]=='.' || |
583 | if(name[0]=='/' || name[0]=='.' || |
584 | strstr(name,"classes/")!=NULL || |
584 | strstr(name,"classes/")!=NULL || |
585 | strstr(name,"forums/")!=NULL || |
585 | strstr(name,"forums/")!=NULL || |
586 | strstr(name,"sessions/")!=NULL || |
586 | strstr(name,"sessions/")!=NULL || |
587 | strstr(name,"doc/")!=NULL) return 1; else return 0; |
587 | strstr(name,"doc/")!=NULL) return 1; else return 0; |
588 | } */ |
588 | } */ |
589 | 589 | ||
Line 629... | Line 629... | ||
629 | int i, t, ret; |
629 | int i, t, ret; |
630 | 630 | ||
631 | t=untrust; ret=0; |
631 | t=untrust; ret=0; |
632 | if(direct_datafile) mystrncpy(nbuf,p,sizeof(nbuf)); |
632 | if(direct_datafile) mystrncpy(nbuf,p,sizeof(nbuf)); |
633 | else if(datafile_check(p)!=0 || find_module_file(p,nbuf,0)) goto ret; |
633 | else if(datafile_check(p)!=0 || find_module_file(p,nbuf,0)) goto ret; |
634 | readdatafile(nbuf); |
634 | readdatafile(nbuf); |
635 | for(i=nextdatacache, pp=datacache[i]; *pp;) { |
635 | for(i=nextdatacache, pp=datacache[i]; *pp;) { |
636 | pp=_nextdata(pp+1); i++; |
636 | pp=_nextdata(pp+1); i++; |
637 | if(i<DATAFIELD_LIMIT) { |
637 | if(i<DATAFIELD_LIMIT) { |
638 | datacache[i]=pp; nextdatacache=i; |
638 | datacache[i]=pp; nextdatacache=i; |
639 | } |
639 | } |
Line 695... | Line 695... | ||
695 | if(c2>'9' && c2<'A') goto invl; |
695 | if(c2>'9' && c2<'A') goto invl; |
696 | if(c1>'F' || c2>'F') goto invl; |
696 | if(c1>'F' || c2>'F') goto invl; |
697 | if(c1>='A') c1=c1-'A'+'9'+1; |
697 | if(c1>='A') c1=c1-'A'+'9'+1; |
698 | if(c2>='A') c2=c2-'A'+'9'+1; |
698 | if(c2>='A') c2=c2-'A'+'9'+1; |
699 | return (c1-'0')*16+c2-'0'; |
699 | return (c1-'0')*16+c2-'0'; |
700 | } |
700 | } |
701 | 701 | ||
702 | /* Converts back http escaped chars, slight. Does not check buffer length. |
702 | /* Converts back http escaped chars, slight. Does not check buffer length. |
703 | * Returns converted string length. */ |
703 | * Returns converted string length. */ |
704 | int _http2env(char outs[], char ins[]) |
704 | int _http2env(char outs[], char ins[]) |
705 | { |
705 | { |
706 | int j,k,l; |
706 | int j,k,l; |
Line 717... | Line 717... | ||
717 | outs[k]=hex2char(ins[j+1],ins[j+2]); |
717 | outs[k]=hex2char(ins[j+1],ins[j+2]); |
718 | j+=2; continue; |
718 | j+=2; continue; |
719 | } |
719 | } |
720 | outs[k]=ins[j]; |
720 | outs[k]=ins[j]; |
721 | } |
721 | } |
722 | outs[k]=0; |
722 | outs[k]=0; |
723 | return k; |
723 | return k; |
724 | } |
724 | } |
725 | 725 | ||
726 | /* Converts back http escaped chars. Does not check buffer length. |
726 | /* Converts back http escaped chars. Does not check buffer length. |
727 | * Returns converted string length. */ |
727 | * Returns converted string length. */ |
Line 747... | Line 747... | ||
747 | if(ins[j]=='?' || ins[j]=='&') { |
747 | if(ins[j]=='?' || ins[j]=='&') { |
748 | outs[k]=0; continue; |
748 | outs[k]=0; continue; |
749 | } |
749 | } |
750 | outs[k]=ins[j]; |
750 | outs[k]=ins[j]; |
751 | } |
751 | } |
752 | outs[k]=0; |
752 | outs[k]=0; |
753 | return k; |
753 | return k; |
754 | } |
754 | } |
755 | 755 | ||
756 | /* translate a string to http querystring style. |
756 | /* translate a string to http querystring style. |
757 | * '&' is not translated. |
757 | * '&' is not translated. |
Line 842... | Line 842... | ||
842 | void create_pid(void) |
842 | void create_pid(void) |
843 | { |
843 | { |
844 | char buf[MAX_FNAME+1], pbuf[256], obuf[MAX_FNAME+1]; |
844 | char buf[MAX_FNAME+1], pbuf[256], obuf[MAX_FNAME+1]; |
845 | struct stat dst; |
845 | struct stat dst; |
846 | struct utimbuf ub; |
846 | struct utimbuf ub; |
847 | 847 | ||
848 | if(robot_access || *session_prefix==0) return; |
848 | if(robot_access || *session_prefix==0) return; |
849 | if(cmd_type==cmd_getframe) return; |
849 | if(cmd_type==cmd_getframe) return; |
850 | mkfname(buf,"%s/.pid",s2_prefix); |
850 | mkfname(buf,"%s/.pid",s2_prefix); |
851 | /* another process running? */ |
851 | /* another process running? */ |
852 | if(readfile(buf,pbuf,sizeof(pbuf))!=NULL) { |
852 | if(readfile(buf,pbuf,sizeof(pbuf))!=NULL) { |
Line 902... | Line 902... | ||
902 | else { |
902 | else { |
903 | if(inf!=NULL) (void)freopen(inf,"r",stdin); |
903 | if(inf!=NULL) (void)freopen(inf,"r",stdin); |
904 | if(outf!=NULL) (void)freopen(outf,"w",stdout); |
904 | if(outf!=NULL) (void)freopen(outf,"w",stdout); |
905 | if(errf!=NULL) (void)freopen(errf,"w",stderr); |
905 | if(errf!=NULL) (void)freopen(errf,"w",stderr); |
906 | } |
906 | } |
907 | /* This is to patch LinuxPPC uid wrapping |
907 | /* This is to patch LinuxPPC uid wrapping |
908 | * for scripts */ |
908 | * for scripts */ |
909 | t=0; if(strchr(cmdf,'/')) { |
909 | t=0; if(strchr(cmdf,'/')) { |
910 | int tf; |
910 | int tf; |
911 | char tbuf[16]; |
911 | char tbuf[16]; |
912 | tf=open(cmdf,O_RDONLY); (void)read(tf,tbuf,8); close(tf); |
912 | tf=open(cmdf,O_RDONLY); (void)read(tf,tbuf,8); close(tf); |
Line 930... | Line 930... | ||
930 | snprintf(buf+t,sizeof(buf)-t,"\n %s\n",strerror(errno)); |
930 | snprintf(buf+t,sizeof(buf)-t,"\n %s\n",strerror(errno)); |
931 | accessfile(buf,"a","%s/exec.fail",tmp_dir); |
931 | accessfile(buf,"a","%s/exec.fail",tmp_dir); |
932 | exit(127); |
932 | exit(127); |
933 | } |
933 | } |
934 | else { /* parent */ |
934 | else { /* parent */ |
935 | wrapexec=0; status=0; |
935 | wrapexec=0; status=0; |
936 | if(exec_wait && !is_multiexec) { |
936 | if(exec_wait && !is_multiexec) { |
937 | killpid=pid; forkalarm(); |
937 | killpid=pid; forkalarm(); |
938 | waitpid(pid,&status,0); killpid=0; finalalarm(); |
938 | waitpid(pid,&status,0); killpid=0; finalalarm(); |
939 | } |
939 | } |
940 | return WEXITSTATUS(status); |
940 | return WEXITSTATUS(status); |
Line 945... | Line 945... | ||
945 | * Returns 1 if already up, otherwise 0. */ |
945 | * Returns 1 if already up, otherwise 0. */ |
946 | int multiexec(char *cmd, char **abuf) |
946 | int multiexec(char *cmd, char **abuf) |
947 | { |
947 | { |
948 | char *p; |
948 | char *p; |
949 | int i; |
949 | int i; |
950 | 950 | ||
951 | if(robot_access) return 0; |
951 | if(robot_access) return 0; |
952 | if(strstr(tmp_dir,"sessions/")==NULL) return 0; |
952 | if(strstr(tmp_dir,"sessions/")==NULL) return 0; |
953 | if(strstr(tmp_debug,"yes")!=NULL && checkhost(manager_site)>=1) |
953 | if(strstr(tmp_debug,"yes")!=NULL && checkhost(manager_site)>=1) |
954 | setenv("multiexec_debug","yes",1); |
954 | setenv("multiexec_debug","yes",1); |
955 | p=getvar("wims_multiexec"); |
955 | p=getvar("wims_multiexec"); |
956 | if(p==NULL || wordchr(p,cmd)==NULL) return 0; /* not allowed */ |
956 | if(p==NULL || wordchr(p,cmd)==NULL) return 0; /* not allowed */ |
957 | if(!multiexec_random[0]) { |
957 | if(!multiexec_random[0]) { |
958 | snprintf(multiexec_random, sizeof(multiexec_random), |
958 | snprintf(multiexec_random, sizeof(multiexec_random), |
Line 985... | Line 985... | ||
985 | char buf[MAX_LINELEN+1]; |
985 | char buf[MAX_LINELEN+1]; |
986 | char *arg[1024]; |
986 | char *arg[1024]; |
987 | char *inf=NULL, *outf=NULL, *errf=NULL; |
987 | char *inf=NULL, *outf=NULL, *errf=NULL; |
988 | char *cmdf, *p, *p2; |
988 | char *cmdf, *p, *p2; |
989 | int i, d; |
989 | int i, d; |
990 | 990 | ||
991 | if(robot_access) return 0; |
991 | if(robot_access) return 0; |
992 | va_start(vp,s); |
992 | va_start(vp,s); |
993 | vsnprintf(buf,sizeof(buf),s,vp); |
993 | vsnprintf(buf,sizeof(buf),s,vp); |
994 | va_end(vp); |
994 | va_end(vp); |
995 | p=find_word_start(buf); if(*p==0) return 0; |
995 | p=find_word_start(buf); if(*p==0) return 0; |
996 | cmdf=p; |
996 | cmdf=p; |
997 | for(i=0;*p!=0 && i<1000; p=find_word_start(p2)) { |
997 | for(i=0;*p!=0 && i<1000; p=find_word_start(p2)) { |
Line 1127... | Line 1127... | ||
1127 | 1127 | ||
1128 | void _setdef(char buf[], char *name, char *value) |
1128 | void _setdef(char buf[], char *name, char *value) |
1129 | { |
1129 | { |
1130 | char *p1, *p2, *p3; |
1130 | char *p1, *p2, *p3; |
1131 | int n; |
1131 | int n; |
1132 | 1132 | ||
1133 | for(p1=strstr(buf,name); p1!=NULL; p1=strstr(p1+1,name)) { |
1133 | for(p1=strstr(buf,name); p1!=NULL; p1=strstr(p1+1,name)) { |
1134 | p2=find_word_start(p1+strlen(name)); |
1134 | p2=find_word_start(p1+strlen(name)); |
1135 | if((p1>buf && !isspace(*(p1-1))) || *p2!='=') continue; |
1135 | if((p1>buf && !isspace(*(p1-1))) || *p2!='=') continue; |
1136 | p3=p1; while(p3>buf && *(p3-1)==' ') p3--; |
1136 | p3=p1; while(p3>buf && *(p3-1)==' ') p3--; |
1137 | if(p3>buf && *(p3-1)!='\n') continue; |
1137 | if(p3>buf && *(p3-1)!='\n') continue; |
Line 1141... | Line 1141... | ||
1141 | _setdef_changed++; |
1141 | _setdef_changed++; |
1142 | } |
1142 | } |
1143 | return; |
1143 | return; |
1144 | } |
1144 | } |
1145 | n=strlen(buf); |
1145 | n=strlen(buf); |
1146 | if(n>0 && buf[n-1]!='\n') |
1146 | if(n>0 && buf[n-1]!='\n') |
1147 | snprintf(buf+n,MAX_LINELEN-n,"\n%s=%s\n",name,value); |
1147 | snprintf(buf+n,MAX_LINELEN-n,"\n%s=%s\n",name,value); |
1148 | else |
1148 | else |
1149 | snprintf(buf+n,MAX_LINELEN-n,"%s=%s\n",name,value); |
1149 | snprintf(buf+n,MAX_LINELEN-n,"%s=%s\n",name,value); |
1150 | _setdef_changed++; |
1150 | _setdef_changed++; |
1151 | } |
1151 | } |
1152 | 1152 | ||
1153 | /* Set variable definition to a file. */ |
1153 | /* Set variable definition to a file. */ |
1154 | void setdef(char *fname, char *name) |
1154 | void setdef(char *fname, char *name) |
1155 | { |
1155 | { |
1156 | char buf[MAX_LINELEN+1]; |
1156 | char buf[MAX_LINELEN+1]; |
1157 | char *p1, *p2, *p3; |
1157 | char *p1, *p2, *p3; |
1158 | 1158 | ||
1159 | _setdef_changed=0; |
1159 | _setdef_changed=0; |
1160 | if(strchr(name,'=')==NULL) return; |
1160 | if(strchr(name,'=')==NULL) return; |
1161 | for(p1=name;*p1;p1++) { |
1161 | for(p1=name;*p1;p1++) { |
1162 | if(isspace(*p1) && *p1!=' ' && *p1!='\n') *p1=' '; |
1162 | if(isspace(*p1) && *p1!=' ' && *p1!='\n') *p1=' '; |
1163 | if(*p1==' ') { |
1163 | if(*p1==' ') { |
Line 1178... | Line 1178... | ||
1178 | } |
1178 | } |
1179 | 1179 | ||
1180 | /* check whether connecting host is part of given list. |
1180 | /* check whether connecting host is part of given list. |
1181 | * Returns 0 if no, 1 if yes. */ |
1181 | * Returns 0 if no, 1 if yes. */ |
1182 | int checkhost(char *hlist) |
1182 | int checkhost(char *hlist) |
1183 | { |
1183 | { |
1184 | char buf[MAX_LINELEN+1]; |
1184 | char buf[MAX_LINELEN+1]; |
1185 | char lbuf[1024], hbuf1[256], hbuf2[256]; |
1185 | char lbuf[1024], hbuf1[256], hbuf2[256]; |
1186 | char *p1, *p2, *pb, *pe, *pp; |
1186 | char *p1, *p2, *pb, *pe, *pp; |
1187 | 1187 | ||
1188 | if(*remote_addr==0) return 0; |
1188 | if(*remote_addr==0) return 0; |
1189 | snprintf(hbuf1,sizeof(hbuf1),"+%s+",remote_addr); |
1189 | snprintf(hbuf1,sizeof(hbuf1),"+%s+",remote_addr); |
1190 | if(*remote_host!=0) { |
1190 | if(*remote_host!=0) { |
1191 | snprintf(hbuf2,sizeof(hbuf2),"+%s+",remote_host); |
1191 | snprintf(hbuf2,sizeof(hbuf2),"+%s+",remote_host); |
1192 | for(p1=hbuf2; *p1; p1++) *p1=tolower(*p1); |
1192 | for(p1=hbuf2; *p1; p1++) *p1=tolower(*p1); |
Line 1202... | Line 1202... | ||
1202 | p2=find_word_end(p1); if(*p2) *p2++=0; |
1202 | p2=find_word_end(p1); if(*p2) *p2++=0; |
1203 | if(p2-p1<3) continue; |
1203 | if(p2-p1<3) continue; |
1204 | if(myisalnum(*p1)) pb="+"; else pb=""; |
1204 | if(myisalnum(*p1)) pb="+"; else pb=""; |
1205 | if(myisalnum(*(p2-1))) pe="+"; else pe=""; |
1205 | if(myisalnum(*(p2-1))) pe="+"; else pe=""; |
1206 | snprintf(lbuf,sizeof(lbuf),"%s%s%s",pb,p1,pe); |
1206 | snprintf(lbuf,sizeof(lbuf),"%s%s%s",pb,p1,pe); |
1207 | for(pp=p1; *pp && (myisdigit(*pp) || *pp=='.'); pp++); |
1207 | for(pp=p1; *pp && (myisdigit(*pp) || *pp=='.'); pp++); |
1208 | if(*pp) pp=hbuf2; /* host name */ |
1208 | if(*pp) pp=hbuf2; /* host name */ |
1209 | else pp=hbuf1; /* ip number */ |
1209 | else pp=hbuf1; /* ip number */ |
1210 | if(strstr(pp,lbuf)!=NULL) return 1; /* found */ |
1210 | if(strstr(pp,lbuf)!=NULL) return 1; /* found */ |
1211 | } |
1211 | } |
1212 | return 0; |
1212 | return 0; |
Line 1275... | Line 1275... | ||
1275 | } |
1275 | } |
1276 | 1276 | ||
1277 | struct sockaddr_un sun; |
1277 | struct sockaddr_un sun; |
1278 | 1278 | ||
1279 | /* returns >=0 if OK. */ |
1279 | /* returns >=0 if OK. */ |
- | 1280 | ||
1280 | int kerneld(char *p, int bufsize) |
1281 | int kerneld(char *p, int bufsize) |
1281 | { |
1282 | { |
1282 | int sock, s, t, t1, l, *ip; |
1283 | int sock, s, t, t1, l, *ip; |
1283 | struct timeval tv; |
1284 | struct timeval tv; |
1284 | fd_set rset; |
1285 | fd_set rset; |
1285 | - | ||
1286 | sock=socket(PF_UNIX,SOCK_STREAM,0); |
1286 | sock=socket(PF_UNIX,SOCK_STREAM,0); |
1287 | s=connect(sock,(const struct sockaddr *)&sun,sizeof(sun)); |
1287 | s=connect(sock,(const struct sockaddr *)&sun,sizeof(sun)); |
1288 | if(s) {bad: close(sock); return -1;} |
1288 | if(s) {bad: close(sock); return -1;} |
1289 | ip=(int *) p; |
1289 | ip=(int *) p; |
1290 | l=strlen(p+sizeof(int)); *ip=l; |
1290 | l=strlen(p+sizeof(int)); *ip=l; |
1291 | s=write(sock,p,l+sizeof(int)); if(s!=l+sizeof(int)) goto bad; |
1291 | s=write(sock,p,l+sizeof(int)); if(s!=l+sizeof(int)) goto bad; |
1292 | for(t=0, l=bufsize-1; t<l+sizeof(int);) { |
1292 | for(t=0, l=bufsize-1; t<l+sizeof(int);) { |
1293 | tv.tv_sec=2; tv.tv_usec=0; |
1293 | tv.tv_sec=2; tv.tv_usec=0; |
1294 | FD_ZERO(&rset); FD_SET(sock,&rset); |
1294 | FD_ZERO(&rset); FD_SET(sock,&rset); |
1295 | if(select(sock+1,&rset,NULL,NULL,&tv)<=0) goto bad; |
1295 | if(select(sock+1,&rset,NULL,NULL,&tv)<=0) goto bad; |
1296 | t1=read(sock,p+t,l-t); |
1296 | t1=read(sock,p+t,l+sizeof(int)-t); |
1297 | if(t1+t<sizeof(int)) goto bad; |
1297 | if(t1+t<sizeof(int)) goto bad; |
- | 1298 | if (t1 < 0) goto bad; |
|
1298 | l=*ip; if(l<=0) goto bad; |
1299 | l=*ip; if(l<=0) goto bad; |
1299 | if(l>=bufsize-sizeof(int)-4) user_error("cmd_output_too_long"); |
1300 | if(l>=bufsize-sizeof(int)-4) user_error("cmd_output_too_long"); |
1300 | t+=t1; |
1301 | t+=t1; |
1301 | } |
1302 | } |
1302 | p[l+sizeof(int)]=0; |
1303 | p[l+sizeof(int)]=0; |
Line 1307... | Line 1308... | ||
1307 | void _daemoncmd(char *p) |
1308 | void _daemoncmd(char *p) |
1308 | { |
1309 | { |
1309 | char buf[MAX_LINELEN+1+sizeof(int)]; |
1310 | char buf[MAX_LINELEN+1+sizeof(int)]; |
1310 | char *p1, *p2, *p3; |
1311 | char *p1, *p2, *p3; |
1311 | mystrncpy(buf+sizeof(int),p,sizeof(buf)-sizeof(int)); |
1312 | mystrncpy(buf+sizeof(int),p,sizeof(buf)-sizeof(int)); |
1312 | if(kerneld(buf,sizeof(buf))<0) |
1313 | if(kerneld(buf,sizeof(buf))<0) |
1313 | internal_error("Daemon communication error."); |
1314 | internal_error("Daemon communication error."); |
1314 | p1=find_word_start(buf+sizeof(int)); |
1315 | p1=find_word_start(buf+sizeof(int)); |
1315 | p2=find_word_end(p1); if(*p2) *p2++=0; |
1316 | p2=find_word_end(p1); if(*p2) *p2++=0; |
1316 | if(strcmp(p1,"OK")==0) { |
1317 | if(strcmp(p1,"OK")==0) { |
1317 | mystrncpy(p,p2,MAX_LINELEN); return; |
1318 | mystrncpy(p,p2,MAX_LINELEN); return; |
1318 | } |
1319 | } |
1319 | p1=find_word_start(p2); p2=find_word_end(p1); if(*p2) *p2++=0; |
1320 | p1=find_word_start(p2); p2=find_word_end(p1); if(*p2) *p2++=0; |
1320 | p2=find_word_start(p2); p3=find_word_end(p2); |
1321 | p2=find_word_start(p2); p3=find_word_end(p2); |
1321 | if(*p3) { |
1322 | if(*p3) { |
1322 | *p3++=0; p3=find_word_start(p3); strip_trailing_spaces(p3); |
1323 | *p3++=0; p3=find_word_start(p3); strip_trailing_spaces(p3); |
1323 | setvar("wims_error_data",p3); |
1324 | setvar("wims_error_data",p3); |
1324 | } |
1325 | } |
1325 | switch(*p1) { |
1326 | switch(*p1) { |