Subversion Repositories wimsdev

Rev

Rev 7491 | Rev 8185 | Go to most recent revision | 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 */
19
 
20
char opt_class[MAX_CLASSLEN+1];
21
char opt_module[MAX_FNAME+1];
22
char opt_session[MAX_CLASSLEN+1];
23
char opt_user[MAX_FNAME+1];
24
 
8155 bpr 25
/* returns -1 if error */
10 reyssat 26
int options(void)
27
{
28
    int i;
29
    char c, *p1, *p2, *p3;
30
    opt_class[0]=opt_module[0]=opt_session[0]=opt_user[0]=0;
31
    for(i=0, p1=find_word_start(textptr); *p1=='-'; p1=find_word_start(p2),i++) {
32
        p1++; c=*p1++; p1=find_word_start(p1);
33
        p2=find_word_end(p1); if(*p2) *p2++=0;
34
        switch(c) {
35
            case 'c': {                 /* class */
36
                if(cwdtype!=dir_home) {
37
                    sockerror(2,"option_conflict"); return -1;
38
                }
7491 bpr 39
                if(strlen(p1)>=MAX_CLASSLEN || !myisdigit(*p1) ||
10 reyssat 40
                   strstr(p1,"..")!=NULL) {
41
                    sockerror(2,"illegal_fname %s",p1);
42
                    return -1;
43
                }
3836 kbelabas 44
                (void)chdir(classd); if(chdir(p1)<0) {
10 reyssat 45
                    sockerror(2,"bad_class %s",p1);
46
                    return -1;
47
                }
48
                mystrncpy(opt_class,p1,sizeof(opt_class));
49
                cwdtype=dir_class; break;
50
            }
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
                }
3836 kbelabas 59
                (void)chdir(modd); if(chdir(p1)<0) {
10 reyssat 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
                }
3836 kbelabas 74
                (void)chdir(sesd); if(chdir(p1)<0) {
10 reyssat 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
            }
93
        }
94
    }
95
    textptr=p1; return i;
96
}
97