Rev 8849 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
10 | reyssat | 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 | /* daemon option processing */ |
||
8185 | bpr | 19 | #include "wimslogd.h" |
10 | reyssat | 20 | |
21 | char opt_class[MAX_CLASSLEN+1]; |
||
22 | char opt_module[MAX_FNAME+1]; |
||
23 | char opt_session[MAX_CLASSLEN+1]; |
||
24 | char opt_user[MAX_FNAME+1]; |
||
25 | |||
8155 | bpr | 26 | /* returns -1 if error */ |
10 | reyssat | 27 | int options(void) |
28 | { |
||
12474 | bpr | 29 | int i; |
30 | char c, *p1, *p2, *p3; |
||
31 | opt_class[0]=opt_module[0]=opt_session[0]=opt_user[0]=0; |
||
32 | for(i=0, p1=find_word_start(textptr); *p1=='-'; p1=find_word_start(p2),i++) { |
||
33 | p1++; c=*p1++; p1=find_word_start(p1); |
||
34 | p2=find_word_end(p1); if(*p2) *p2++=0; |
||
35 | switch(c) { |
||
36 | case 'c': { /* class */ |
||
37 | if(cwdtype!=dir_home) { |
||
38 | sockerror(2,"option_conflict"); return -1; |
||
39 | } |
||
40 | if(strlen(p1)>=MAX_CLASSLEN || !myisdigit(*p1) || strstr(p1,"..")!=NULL) { |
||
41 | sockerror(2,"illegal_fname %s",p1); |
||
42 | return -1; |
||
43 | } |
||
44 | (void)chdir(classd); if(chdir(p1)<0) { |
||
45 | sockerror(2,"bad_class %s",p1); |
||
46 | return -1; |
||
47 | } |
||
48 | mystrncpy(opt_class,p1,sizeof(opt_class)); |
||
49 | cwdtype=dir_class; break; |
||
8849 | bpr | 50 | } |
12474 | bpr | 51 | case 'm': { /* module */ |
52 | if(cwdtype!=dir_home) { |
||
53 | sockerror(2,"option_conflict"); return -1; |
||
54 | } |
||
55 | if(strlen(p1)>MAX_FNAME || *p1=='/' || strstr(p1,"..")!=NULL) { |
||
56 | sockerror(2,"illegal_fname %s",p1); |
||
57 | return -1; |
||
58 | } |
||
59 | (void)chdir(modd); if(chdir(p1)<0) { |
||
60 | sockerror(2,"bad_module:%s",p1); |
||
61 | return -1; |
||
62 | } |
||
63 | mystrncpy(opt_module,p1,sizeof(opt_module)); |
||
64 | cwdtype=dir_module; break; |
||
65 | } |
||
66 | case 's': { /* session */ |
||
67 | if(cwdtype!=dir_home) { |
||
68 | sockerror(2,"option_conflict"); return -1; |
||
69 | } |
||
70 | if(strlen(p1)>=MAX_CLASSLEN || *p1=='/' || strstr(p1,"..")!=NULL) { |
||
71 | sockerror(2,"illegal_fname:%s",p1); |
||
72 | return -1; |
||
73 | } |
||
74 | (void)chdir(sesd); if(chdir(p1)<0) { |
||
75 | sockerror(2,"bad_session:%s",p1); |
||
76 | return -1; |
||
77 | } |
||
78 | mystrncpy(opt_session,p1,sizeof(opt_session)); |
||
79 | cwdtype=dir_session; break; |
||
80 | } |
||
81 | case 'u': { /* user definition */ |
||
82 | if(strchr(p1,'/')!=NULL) { |
||
83 | sockerror(2,"illegal_fname %s",p1); |
||
84 | return -1; |
||
85 | } |
||
86 | mystrncpy(opt_user,p1,sizeof(opt_user)); |
||
87 | for(p3=strchr(opt_user,'.'); p3!=NULL; p3=strchr(p3,'.')) *p3++='@'; |
||
88 | break; |
||
89 | } |
||
90 | default: { |
||
91 | sockerror(2,"bad_option"); return -1; |
||
92 | } |
||
10 | reyssat | 93 | } |
12474 | bpr | 94 | } |
95 | textptr=p1; return i; |
||
10 | reyssat | 96 | } |