Subversion Repositories wimsdev

Rev

Rev 8849 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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