Subversion Repositories wimsdev

Rev

Rev 8155 | Rev 8849 | 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 */
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
{
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
                }
7491 bpr 40
                if(strlen(p1)>=MAX_CLASSLEN || !myisdigit(*p1) ||
10 reyssat 41
                   strstr(p1,"..")!=NULL) {
42
                    sockerror(2,"illegal_fname %s",p1);
43
                    return -1;
44
                }
3836 kbelabas 45
                (void)chdir(classd); if(chdir(p1)<0) {
10 reyssat 46
                    sockerror(2,"bad_class %s",p1);
47
                    return -1;
48
                }
49
                mystrncpy(opt_class,p1,sizeof(opt_class));
50
                cwdtype=dir_class; break;
51
            }
52
            case 'm': {                 /* module */
53
                if(cwdtype!=dir_home) {
54
                    sockerror(2,"option_conflict"); return -1;
55
                }
56
                if(strlen(p1)>MAX_FNAME || *p1=='/' || strstr(p1,"..")!=NULL) {
57
                    sockerror(2,"illegal_fname %s",p1);
58
                    return -1;
59
                }
3836 kbelabas 60
                (void)chdir(modd); if(chdir(p1)<0) {
10 reyssat 61
                    sockerror(2,"bad_module:%s",p1);
62
                    return -1;
63
                }
64
                mystrncpy(opt_module,p1,sizeof(opt_module));
65
                cwdtype=dir_module; break;
66
            }
67
            case 's': {                 /* session */
68
                if(cwdtype!=dir_home) {
69
                    sockerror(2,"option_conflict"); return -1;
70
                }
71
                if(strlen(p1)>=MAX_CLASSLEN || *p1=='/' || strstr(p1,"..")!=NULL) {
72
                    sockerror(2,"illegal_fname:%s",p1);
73
                    return -1;
74
                }
3836 kbelabas 75
                (void)chdir(sesd); if(chdir(p1)<0) {
10 reyssat 76
                    sockerror(2,"bad_session:%s",p1);
77
                    return -1;
78
                }
79
                mystrncpy(opt_session,p1,sizeof(opt_session));
80
                cwdtype=dir_session; break;
81
            }
82
            case 'u': {                 /* user definition */
83
                if(strchr(p1,'/')!=NULL) {
84
                    sockerror(2,"illegal_fname %s",p1);
85
                    return -1;
86
                }
87
                mystrncpy(opt_user,p1,sizeof(opt_user));
88
                for(p3=strchr(opt_user,'.'); p3!=NULL; p3=strchr(p3,'.')) *p3++='@';
89
                break;
90
            }
91
            default: {
92
                sockerror(2,"bad_option"); return -1;
93
            }
94
        }
95
    }
96
    textptr=p1; return i;
97
}
98