Back to index

wims  3.65+svn20090927
Functions | Variables
files.c File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void secure_exec (void)
void _filewrite (char *prefix, char *fname, char *content, char *type)
void filewrite (char *p)
void fileappend (char *p)

Variables

int fwrite_calls = 0
int fwrite_sizes = 0

Function Documentation

void _filewrite ( char *  prefix,
char *  fname,
char *  content,
char *  type 
)

Definition at line 24 of file files.c.

{
    char *m, buf[MAX_LINELEN+1];
    FILE *f;
    int n,checklink;
    struct stat stl;
    checklink=0;
    if(strstr(fname,parent_dir_string)!=NULL){
       setvar(error_data_string,fname);
       module_error("illegal_fname"); return;
    }
    m=getvar(ro_name[ro_module]);
    if(m==NULL || *m==0) return;
    if(strncmp(fname,"TEMP_",5)==0 && strchr(fname,'/')==NULL &&
       strstr(session_prefix,"robot")==NULL) {
       mystrncpy(buf,tmp_dir,sizeof(buf));
       goto add;
    }
    if(strncmp(fname,"getfile/",strlen("getfile/"))==0) {
       if(strchr(fname+strlen("getfile/"),'/')!=NULL) {
denied:
           setvar(error_data_string,fname);
           module_error("file_access_denied"); return;
       }
       fname+=strlen("getfile/");
       snprintf(buf,sizeof(buf),"%s/getfile",session_prefix);
       mkdirs(buf);
       checklink=1; goto add;
    }
    if(trusted_module() && !is_class_module && strncmp(fname,"wimshome/",9)==0) {
       mystrncpy(buf,getvar("wims_home"),sizeof(buf));
       fname+=9; goto add;
    }
    if(strncmp(m,"adm/",4)==0 || strcmp(m,home_module)==0) {
       mystrncpy(buf,prefix,sizeof(buf));
    }
    else {
       if(!trusted_module() && strchr(fname,'/')!=NULL) return; /* silent */
       snprintf(buf,sizeof(buf),"w/%s",prefix);
       mkdirs(buf);
    }
    add: snprintf(buf+strlen(buf),sizeof(buf)-strlen(buf),"/%s",fname);
    if(!trusted_module() || is_class_module) {
       if(fwrite_calls>=MAX_FWRITE) goto denied;
       fwrite_calls++;
       n=strlen(content)+1;
       if(fwrite_sizes+n>MAX_FWRITE_SIZE) goto denied;
       fwrite_sizes+=n;
    }
    if(checklink && lstat(buf,&stl)==0 && S_ISLNK(stl.st_mode))
      goto denied;
    lastdatafile[0]=lastftest[0]=0;
    f=fopen(buf,type); if(f==NULL) return;
    fprintf(f,"%s\n",content);
    fclose(f);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void fileappend ( char *  p)

Definition at line 95 of file files.c.

{
    char *p1, *p2;
    secure_exec();
    p1=find_word_start(p);
    p2=find_word_end(p1);
    if(*p1==0) {*p=0;return;}
    if(*p2!=0) *p2++=0;
    _filewrite(module_prefix,p1,p2,"a");
    *p=0;
}

Here is the call graph for this function:

void filewrite ( char *  p)

Definition at line 82 of file files.c.

{
    char *p1, *p2;
    secure_exec();
    p1=find_word_start(p);
    p2=find_word_end(p1);
    if(*p1==0) {*p=0;return;}
    if(*p2!=0) *p2++=0;
    _filewrite(module_prefix,p1,p2,"w");
    *p=0;
}

Here is the call graph for this function:

void secure_exec ( void  )

Definition at line 25 of file calc.c.

{
    if((untrust&6)==0) return;
    module_error("Illegal_command");
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int fwrite_calls = 0

Definition at line 20 of file files.c.

int fwrite_sizes = 0

Definition at line 21 of file files.c.