Back to index

wims  3.65+svn20090927
options.c
Go to the documentation of this file.
00001 /*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
00002  *
00003  *  This program is free software; you can redistribute it and/or modify
00004  *  it under the terms of the GNU General Public License as published by
00005  *  the Free Software Foundation; either version 2 of the License, or
00006  *  (at your option) any later version.
00007  *
00008  *  This program is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *  GNU General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU General Public License
00014  *  along with this program; if not, write to the Free Software
00015  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00016  */
00017 
00018 /* daemon option processing */
00019 
00020 char opt_class[MAX_CLASSLEN+1];
00021 char opt_module[MAX_FNAME+1];
00022 char opt_session[MAX_CLASSLEN+1];
00023 char opt_user[MAX_FNAME+1];
00024 
00025        /* returns -1 if error */
00026 int options(void)
00027 {
00028     int i;
00029     char c, *p1, *p2, *p3;
00030     opt_class[0]=opt_module[0]=opt_session[0]=opt_user[0]=0;
00031     for(i=0, p1=find_word_start(textptr); *p1=='-'; p1=find_word_start(p2),i++) {
00032        p1++; c=*p1++; p1=find_word_start(p1);
00033        p2=find_word_end(p1); if(*p2) *p2++=0;
00034        switch(c) {
00035            case 'c': {                    /* class */
00036               if(cwdtype!=dir_home) {
00037                   sockerror(2,"option_conflict"); return -1;
00038               }
00039               if(strlen(p1)>=MAX_CLASSLEN || !myisdigit(*p1) || 
00040                  strstr(p1,"..")!=NULL) {
00041                   sockerror(2,"illegal_fname %s",p1);
00042                   return -1;
00043               }
00044               chdir(classd); if(chdir(p1)<0) {
00045                   sockerror(2,"bad_class %s",p1);
00046                   return -1;
00047               }
00048               mystrncpy(opt_class,p1,sizeof(opt_class));
00049               cwdtype=dir_class; break;
00050            }
00051            case 'm': {                    /* module */
00052               if(cwdtype!=dir_home) {
00053                   sockerror(2,"option_conflict"); return -1;
00054               }
00055               if(strlen(p1)>MAX_FNAME || *p1=='/' || strstr(p1,"..")!=NULL) {
00056                   sockerror(2,"illegal_fname %s",p1);
00057                   return -1;
00058               }
00059               chdir(modd); if(chdir(p1)<0) {
00060                   sockerror(2,"bad_module:%s",p1);
00061                   return -1;
00062               }
00063               mystrncpy(opt_module,p1,sizeof(opt_module));
00064               cwdtype=dir_module; break;
00065            }
00066            case 's': {                    /* session */
00067               if(cwdtype!=dir_home) {
00068                   sockerror(2,"option_conflict"); return -1;
00069               }
00070               if(strlen(p1)>=MAX_CLASSLEN || *p1=='/' || strstr(p1,"..")!=NULL) {
00071                   sockerror(2,"illegal_fname:%s",p1);
00072                   return -1;
00073               }
00074               chdir(sesd); if(chdir(p1)<0) {
00075                   sockerror(2,"bad_session:%s",p1);
00076                   return -1;
00077               }
00078               mystrncpy(opt_session,p1,sizeof(opt_session));
00079               cwdtype=dir_session; break;
00080            }
00081            case 'u': {                    /* user definition */
00082               if(strchr(p1,'/')!=NULL) {
00083                   sockerror(2,"illegal_fname %s",p1);
00084                   return -1;
00085               }
00086               mystrncpy(opt_user,p1,sizeof(opt_user));
00087               for(p3=strchr(opt_user,'.'); p3!=NULL; p3=strchr(p3,'.')) *p3++='@';
00088               break;
00089            }
00090            default: {
00091               sockerror(2,"bad_option"); return -1;
00092            }
00093        }
00094     }
00095     textptr=p1; return i;
00096 }
00097