Exemplo n.º 1
0
int fs_create(char *name)
{
  dir_entry* entry;

  if(mb.magic != FS_MAGIC){
    printf("disk not mounted\n");
    return -1;
  }
  
  entry = first_invalid_dir_entry();
  if(entry == NULL) {
    printf("disk full\n");
    return -1;
  }

  if(!valid_name(name)){
    printf("invalid name\n");
    return -1;
  }

  //Init dir
  entry->valid = 1;
  strcpy(entry->name, name);
  entry->length = 0;
  entry->first_block = EOFF;

  return 0;
}
Exemplo n.º 2
0
void prim_frm(PRIM_PROTOTYPE)
{
  char *filename;
  CHECKOP(1);
  oper1 = POP();
  if (getuid() == 0 )
    abort_interp("Muck is running under root privs, file prims disabled.");
  if (mlev < LBOY) abort_interp("BOY primitive only.");
  if(oper1->type != PROG_STRING) abort_interp("Argument 1 is not a string.");
  if(!oper1->data.string) abort_interp("Argument 1 is a null string.");
  filename = oper1->data.string->data;
#ifdef SECURE_FILE_PRIMS
  if (!(valid_name(filename)))
      abort_interp( "Invalid file name.");
  if ( strchr( filename, '$' ) == NULL )
    filename = set_directory(filename);
  else
    filename = parse_token( filename );
  if ( filename == NULL )
    abort_interp( "Invalid shortcut used." );
#endif 
  result = unlink(filename);
    if(tp_log_files)
      log2filetime("logs/files", "#%d by %s FRM: %s \n", program, unparse_object(player, player), oper1->data.string->data);  
  CLEAR(oper1);
  PushInt(result);
}
Exemplo n.º 3
0
int fs_delete( char *name )
{

  if(mb.magic != FS_MAGIC){
    printf("disk not mounted\n");
    return -1;
  }

  if(!valid_name(name)){
    printf("invalid name\n");
    return -1;
  }

  dir_entry* file_to_del = found_file(name);

  if(!file_to_del){
    printf("file not found\n");
    return -1;
  }

  file_to_del->valid = 0;

  unsigned int next_block;
  for(next_block = file_to_del->first_block; next_block != EOFF; next_block = fat[next_block])
    fat[next_block] = FREE;

  return 0;
}
Exemplo n.º 4
0
/* addcom: add a new custom command cmd with response and cooldown */
bool CustomHandler::addcom(const char *cmd, char *response,
		const char *nick, time_t cooldown)
{
	time_t t;
	char resp[MAX_MSG];
	Json::Value command;

	if (!valid_name(cmd)) {
		snprintf(err, MAX_LEN, "invalid command name: $%s", cmd);
		return false;
	}
	if (!valid_resp(response, err))
		return false;

	resp[0] = '\0';
	if (*response == '/')
		strcat(resp, " ");
	strcat(resp, response);

	command["active"] = true;
	command["cmd"] = cmd;
	command["response"] = resp;
	command["cooldown"] = (Json::Int64)cooldown;
	command["ctime"] = (Json::Int64)(t = time(nullptr));
	command["mtime"] = (Json::Int64)t;
	command["creator"] = nick;
	command["uses"] = 0;

	custom_cmds["commands"].append(command);
	cooldowns->add(cmd, cooldown);
	write();
	return true;
}
Exemplo n.º 5
0
void prim_fsize(PRIM_PROTOTYPE)
{
  FILE *fh;
  char *filename;
  int result; 
  long offset;
  CHECKOP(1);
  oper1 = POP();
  if (getuid() == 0 ) 
    abort_interp("Muck is running under root privs, file prims disabled.");
  if (mlev < LBOY) abort_interp("BOY primitive only.");  
  if (oper1->type != PROG_STRING) abort_interp("Arguement 1 is not a string.");
  if (!oper1->data.string) abort_interp("Arguement 1 is a null string.");
  filename = oper1->data.string->data;
#ifdef SECURE_FILE_PRIMS
  if (!(valid_name(filename)))
      abort_interp( "Invalid file name.");
  if ( strchr( filename, '$' ) == NULL )
    filename = set_directory(filename);
  else
    filename = parse_token( filename );
  if ( filename == NULL )
    abort_interp( "Invalid shortcut used." );
#endif
  fh = fopen(filename, "r");
  if (fh == NULL) { offset = -1; } else {
    fseek(fh, 0, SEEK_END);
    offset = ftell(fh);
    if(tp_log_files)
      log2filetime("logs/files", "#%d by %s FSIZE: %s \n", program, unparse_object(player, player), oper1->data.string->data); 
  }
  fclose(fh);
  CLEAR(oper1);
  PushInt(offset);
}
Exemplo n.º 6
0
/*
 * Include files within dirname.  Only files with names ending in ".conf", or
 * consisting entirely of alphanumeric characters, dashes, and underscores are
 * included.  This restriction avoids including editor backup files, .rpmsave
 * files, and the like.  Files are processed in alphanumeric order.
 */
static errcode_t parse_include_dir(const char *dirname,
                                   struct profile_node *root_section)
{
    errcode_t retval = 0;
    char **fnames, *pathname;
    int i;

    if (k5_dir_filenames(dirname, &fnames) != 0)
        return PROF_FAIL_INCLUDE_DIR;

    for (i = 0; fnames != NULL && fnames[i] != NULL; i++) {
        if (!valid_name(fnames[i]))
            continue;
        if (asprintf(&pathname, "%s/%s", dirname, fnames[i]) < 0) {
            retval = ENOMEM;
            break;
        }
        retval = parse_include_file(pathname, root_section);
        free(pathname);
        if (retval)
            break;
    }
    k5_free_filenames(fnames);
    return retval;
}
Exemplo n.º 7
0
int fs_write( char *name, const char *data, int length, int offset )
{
 

  if(mb.magic != FS_MAGIC){
    printf("disk not mounted\n");
    return -1;
  }

  if(!valid_name(name)){
     printf("invalid name\n");
    return -1;
  }

  dir_entry* file = found_file(name);

  if(!file){
    printf("file not found\n");
    return -1;
  }

  unsigned first_block = get_block(file, offset);

  if(first_block == -1){
    printf("invalid offset");
    return -1;
  }

  int bytes_written = 0;
  unsigned block_offset = offset % DISK_BLOCK_SIZE;
  unsigned block = first_block;

  char current_block[DISK_BLOCK_SIZE];
  
  disk_read(first_block, current_block);

  int to_write = DISK_BLOCK_SIZE;
  while(bytes_written < length){
    if(block == EOFF) {
      printf("invalid length\n");
      return -1;
    }

    if(length - bytes_written < DISK_BLOCK_SIZE){
      to_write = length - bytes_written;
      disk_read(block, current_block);
    }

    memcpy(current_block + block_offset, data, to_write);
    
    disk_write(block, current_block);

    block_offset = 0;
    bytes_written += to_write;
    block = fat[block];
  }

  return bytes_written;
}
Exemplo n.º 8
0
Arquivo: ex2.c Projeto: e-dwar/pds
void liens_symboliques (const char *chemin)
{
    struct stat st;
    if (valid_name(chemin)) {
        if (lstat(chemin, &st) == -1) fail();
        if (S_ISDIR(st.st_mode)) parcours_rep(chemin);
        else if (S_ISLNK(st.st_mode)) affiche_lien(chemin);
    }
}
Exemplo n.º 9
0
void prim_fren(PRIM_PROTOTYPE)
{
  char *oldname, *newname;
  char tempB[BUFFER_LEN] = "";
  CHECKOP(2);
  oper1 = POP();
  oper2 = POP();
  if (getuid() == 0 )
    abort_interp("Muck is running under root privs, file prims disabled.");
  if (mlev < LBOY) abort_interp("BOY primitive only.");  
  if(oper1->type != PROG_STRING) abort_interp("Argument 1 is not a string.");
  if(!oper1->data.string) abort_interp("Argument 1 is a null string.");
  if(oper2->type != PROG_STRING) abort_interp("Argument 2 is not a string.");
  if(!oper2->data.string) abort_interp("Argument 2 is a null string.");
  newname = oper1->data.string->data;
  oldname = oper2->data.string->data; /* ( s<old> s<new> -- i ) */
#ifdef SECURE_FILE_PRIMS
  if (!(valid_name( newname )))
      abort_interp( "Invalid file name. (2)");
  if ( strchr( newname, '$' ) == NULL )
    newname = set_directory(newname);
  else
    newname = parse_token( newname );
  if ( newname == NULL )
    abort_interp( "Invalid shortcut used. (2)" );   
  strcpy( tempB, newname );
  if (!(valid_name(oldname)))
      abort_interp( "Invalid file name. (1)");
  if ( strchr( oldname, '$' ) == NULL )
    oldname = set_directory(oldname);
  else
    oldname = parse_token( oldname );
  if ( oldname == NULL )
    abort_interp( "Invalid shortcut used. (1)" );
  newname = tempB;
#endif
  result = rename(oldname, newname);
  if(tp_log_files)
    log2filetime("logs/files", "#%d by %s FREN: %s -> %s \n", program, unparse_object(player, player), oper2->data.string->data, oper1->data.string->data); 
  CLEAR(oper1);
  CLEAR(oper2);
  PushInt(result);
} 
Exemplo n.º 10
0
void prim_fread(PRIM_PROTOTYPE)
{
  FILE *fh;
  char *filename;
  double offset;
  char tempchr[2];
  int result;
  CHECKOP(2);
  oper1 = POP();
  oper2 = POP();
  if (getuid() == 0 ) 
    abort_interp("Muck is running under root privs, file prims disabled.");
  if (mlev < LBOY) abort_interp("BOY primitive only.");  
  if(oper1->type != PROG_INTEGER)
    abort_interp("Arguement 1 is not an integer.");
  if(oper1->data.number < 0 ) abort_interp("Arguement 1 is a negative number.");
  if(oper2->type != PROG_STRING) abort_interp("Arguement 2 is not a string.");
  if(!oper2->data.string) abort_interp("Argueemnt 2 is a null string.");
  offset = oper1->data.number;
  filename = oper2->data.string->data;
#ifdef SECURE_FILE_PRIMS
  if (!(valid_name(filename)))
      abort_interp( "Invalid file name.");
  if ( strchr( filename, '$' ) == NULL )
    filename = set_directory(filename);
  else
    filename = parse_token( filename );
  if ( filename == NULL )
    abort_interp( "Invalid shortcut used." );
#endif
  fh = fopen(filename, "r");
  if (fh == NULL) { result = 0; } else {
    fseek(fh, offset, SEEK_SET);
    tempchr[0] = (char) fgetc(fh);
    tempchr[1] = '\0';
    fclose(fh);
    sprintf(buf, "%s", tempchr);
    result = 1;
    if(tp_log_files)
      log2filetime("logs/files", "#%d by %s FREAD: %s \n", program, unparse_object(player, player), oper2->data.string->data); 
   if ( tempchr[0] == EOF )
      result = 0;
  }
  CLEAR(oper1);
  CLEAR(oper2);
  if( result )
     PushString(buf);
  else 
     PushNullStr;
} 
Exemplo n.º 11
0
int fs_read( char *name, char *data, int length, int offset )
{

  if(mb.magic != FS_MAGIC){
    printf("disk not mounted\n");
    return -1;
  }

  if(!valid_name(name)){
     printf("invalid name\n");
    return -1;
  }

  dir_entry* file = found_file(name);

  if(!file){
    printf("file not found\n");
    return -1;
  }

  unsigned first_block = get_block(file, offset);

  if(first_block == -1)
    return 0;

  int bytes_read = 0;
  unsigned block_offset = offset % DISK_BLOCK_SIZE;
  unsigned block = first_block;
  int valid_size = file->length - offset;

  char current_block[DISK_BLOCK_SIZE];
  while(bytes_read < length){
    if(block == EOFF)
      return bytes_read;

    disk_read(block, current_block);

    int to_read = (valid_size - bytes_read < DISK_BLOCK_SIZE) ? valid_size - bytes_read : DISK_BLOCK_SIZE;
    memcpy(data, current_block + block_offset, to_read);
    block_offset = 0;
    bytes_read += to_read;
    

    block = fat[block];
  }

  return bytes_read;
}
Exemplo n.º 12
0
std::string	FileNameRecovery::setDirName(DirEntry * del_dirent,
					     uint8_t * tab,
					     uint64_t pos)
{
  std::string	name("");


  name.append((char *)(tab + pos) + 8 * sizeof(uint8_t),
		del_dirent->name_length_v2()); 
  del_dirent->setName((uint8_t *)(name.c_str()));
  if (!valid_name((char *)name.c_str(), del_dirent->name_length_v2(),
		  del_dirent->entry_length()))
    
    return (__name = "");
  __name = name;
  return name;
}
Exemplo n.º 13
0
void prim_bwrite(PRIM_PROTOTYPE)
{
  FILE *fh;
  char *filename;
  int result, tempdat;
  double offset;
  CHECKOP(3);
  oper1 = POP();
  oper2 = POP();
  oper3 = POP();
  if (getuid() == 0 ) 
    abort_interp("Muck is running under root privs, file prims disabled.");
  if (mlev < LBOY) abort_interp("BOY primitive only.");  
  if (oper1->type != PROG_INTEGER) abort_interp("Arguement 1 is not an integer.");
  if (oper1->data.number < 0 ) abort_interp("Arguement 1 is a negative number.");
  if (oper2->type != PROG_STRING) abort_interp("Arguement 2 is not a string.");
  if (!oper2->data.string) abort_interp("Arguement 2 is a null string.");
  if (oper3->type != PROG_INTEGER) abort_interp("Arguement 3 is not an integer.");
  if (oper3->data.number < 0 ) abort_interp("Arguement 3 is a negative number.");
  offset = oper1->data.number;
  filename = oper2->data.string->data;
  tempdat = (int) oper3->data.string->data;
#ifdef SECURE_FILE_PRIMS
  if (!(valid_name(filename)))
      abort_interp( "Invalid file name.");
  if ( strchr( filename, '$' ) == NULL )
    filename = set_directory(filename);
  else
    filename = parse_token( filename );
  if ( filename == NULL )
    abort_interp( "Invalid shortcut used." );
#endif
  fh = fopen(filename, "w");
  if (fh == NULL) { result = 0; } else {
    fseek(fh, offset, SEEK_SET);
    fputc(tempdat - 8, fh); 
    fclose(fh);
    result = 1;
    if(tp_log_files)
      log2filetime("logs/files", "#%d by %s BWRITE : %s \n", program, unparse_object(player, player), oper2->data.string->data); 
  }
  CLEAR(oper1);
  CLEAR(oper2);
  CLEAR(oper3);
  PushInt(result);
}
Exemplo n.º 14
0
void prim_bread(PRIM_PROTOTYPE)
{
  FILE *fh; /* Should return -1 for file open error. */ 
  char *filename; /* -2 for EOF. */ 
  double offset;
  int result;
  CHECKOP(2);
  oper1 = POP();
  oper2 = POP();
  if (getuid() == 0 ) 
    abort_interp("Muck is running under root privs, file prims disabled.");
  if (mlev < LBOY) abort_interp("BOY primitive only.");  
  if(oper1->type != PROG_INTEGER)
    abort_interp("Arguement 1 is not an integer.");
  if(oper1->data.number < 0 ) abort_interp("Arguement 1 is a negative number.");
  if(oper2->type != PROG_STRING) abort_interp("Arguement 2 is not a string.");
  if(!oper2->data.string) abort_interp("Argueemnt 2 is a null string.");
  offset = oper1->data.number;
  filename = oper2->data.string->data;
#ifdef SECURE_FILE_PRIMS
  if (!(valid_name(filename)))
      abort_interp( "Invalid file name.");
  if ( strchr( filename, '$' ) == NULL )
    filename = set_directory(filename);
  else
    filename = parse_token( filename );
  if ( filename == NULL )
    abort_interp( "Invalid shortcut used." );
#endif
  fh = fopen(filename, "r");
  if (fh == NULL) { result = -1; } else {
    fseek(fh, offset, SEEK_SET);
    result = fgetc(fh);
    if(tp_log_files)
      log2filetime("logs/files", "#%d by %s BREAD: %s \n", program, unparse_object(player, player), oper2->data.string->data); 
    if (result == EOF) { 
      result = -2; 
    } 
    fclose(fh);
  }
  CLEAR(oper1);
  CLEAR(oper2);
  PushInt(result);
} 
Exemplo n.º 15
0
/* rename: rename custom command cmd to newcmd */
bool CustomHandler::rename(const char *cmd, const char *newcmd)
{
	Json::Value *com;

	if (!(com = getcom(cmd))) {
		snprintf(err, MAX_LEN, "not a command: $%s", cmd);
		return false;
	}
	if (!valid_name(newcmd)) {
		snprintf(err, MAX_LEN, "invalid command name: $%s", newcmd);
		return false;
	}

	(*com)["cmd"] = newcmd;
	(*com)["mtime"] = (Json::Int64)time(nullptr);
	cooldowns->remove(cmd);
	cooldowns->add(newcmd, (*com)["cooldown"].asInt64());
	write();
	return true;
}
Exemplo n.º 16
0
int fs_getsize( char *name ){

  if(mb.magic != FS_MAGIC){
    printf("disk not mounted\n");
    return -1;
  }

  if(!valid_name(name)){
     printf("invalid name\n");
    return -1;
  }

  dir_entry* file = found_file(name);

  if(!file){
    printf("file not found\n");
    return -1;
  }

  return file->length;
}
Exemplo n.º 17
0
void prim_fappend(PRIM_PROTOTYPE)
{
  FILE *fh;
  char *filename;
  char *writestring;
  CHECKOP(2);
  oper1 = POP();
  oper2 = POP();
  if (getuid() == 0 ) 
    abort_interp("Muck is running under root privs, file prims disabled.");
  if (mlev < LBOY) abort_interp("BOY primitive only.");  
  if(oper1->type != PROG_STRING) abort_interp("Argument 1 is not a string.");
  if(!oper1->data.string) abort_interp("Argument 1 is a null string.");
  if(oper2->type != PROG_STRING) abort_interp("Arguement 2 is not a string.");
  if(!oper2->data.string) abort_interp("Arguement 2 is a null string.");
  filename = oper1->data.string->data;
  writestring = oper2->data.string->data;
#ifdef SECURE_FILE_PRIMS
  if (!(valid_name(filename)))
      abort_interp( "Invalid file name.");
  if ( strchr( filename, '$' ) == NULL )
    filename = set_directory(filename);
  else
    filename = parse_token( filename );
  if ( filename == NULL )
    abort_interp( "Invalid shortcut used." );
#endif
  fh = fopen(filename, "a");
  if (fh == NULL) { result = 0; } else {
    fputs(writestring, fh);
    fclose(fh);
    result = 1;
    if(tp_log_files)
      log2filetime("logs/files", "#%d by %s FAPPEND: %s \n", program, unparse_object(player, player), oper1->data.string->data); 
  }
  CLEAR(oper1);
  CLEAR(oper2);
  PushInt(result);
}
Exemplo n.º 18
0
/*=====================================
 * process_indi -- process indi record
 *  checking in pass 1, fixing in pass 2
 *===================================*/
static void
process_indi (RECORD rec)
{
    NODE indi0, indi1;
    NODE name1, refn1, sex1, body1, famc1, fams1;
    NODE node1;
    BOOLEAN altered=FALSE;
    BOOLEAN needfix=FALSE;
    CNSTRING key = nzkey(rec);

    indi0 = nztop(rec);
    if (todo.pass==1) {
        indi1 = indi0;
    } else {
        indi1 = copy_node_subtree(indi0);
    }
    split_indi_old(indi1, &name1, &refn1, &sex1, &body1, &famc1, &fams1);

    if (todo.pass == 1) {
        /* check names */
        for (node1 = name1; node1; node1 = nsibling(node1)) {
            STRING name=nval(node1);
            if (!valid_name(name)) {
                report_error(ERR_BADNAME, _("Bad name for individual %s: %s"), key, name);
            } else {
                /* TO DO: verify that name is in db */
            }
        }
        /* check refns */
        for (node1 = refn1; node1; node1 = nsibling(node1)) {
            /* STRING refn=nval(node1); */
            /* TO DO: verify that refn is in db */
        }
    }

    /* check parents */
    for (node1 = famc1; node1; node1 = nsibling(node1)) {
        STRING famkey=rmvat(nval(node1));
        NODE fam2 = qkey_to_fam(famkey);
        if (!fam2) {
            if (todo.pass == 1) {
                report_error(ERR_BADFAMREF, _("Bad family reference (%s) individual %s"), famkey, key);
            }
        } else {
            /* look for indi1 (key) in fam2's children */
            if (!find_xref(key, fam2, "CHIL", NULL)) {
                if (todo.pass == 1) {
                    report_error(ERR_MISSINGCHILD, _("Missing child (%s) in family (%s)"), key, famkey);
                    needfix=TRUE;
                } else {
                    if (fix_bad_pointer(key, rec, node1)) {
                        report_fix(ERR_MISSINGCHILD, _("Fixed missing child (%s) in family (%s)"), key, famkey);
                        altered=TRUE;
                    }
                }
            }
        }
    }

    /* check spouses */
    for (node1 = fams1; node1; node1 = nsibling(node1)) {
        STRING famkey=rmvat(nval(node1));
        NODE fam2 = qkey_to_fam(famkey);
        if (!fam2) {
            if (todo.pass == 1) {
                report_error(ERR_BADFAMREF, _("Bad family reference (%s) individual %s"), famkey, key);
            }
        } else {
            /* look for indi1 (key) in fam2's spouses */
            if (!find_xref(key, fam2, "HUSB", "WIFE")) {
                if (todo.pass == 1) {
                    report_error(ERR_MISSINGSPOUSE, _("Missing spouse (%s) in family (%s)"), key, famkey);
                    needfix=TRUE;
                } else {
                    if (fix_bad_pointer(key, rec, node1)) {
                        report_fix(ERR_MISSINGSPOUSE, _("Fixed missing spouse (%s) in family (%s)"), key, famkey);
                        altered=TRUE;
                    }
                }
            }
        }
    }

    join_indi(indi1, name1, refn1, sex1, body1, famc1, fams1);
    if (altered) {
        /* must normalize, as some lineage references may have been
        altered to non-lineage tags to fix broken pointers */
        normalize_indi(indi1);

        /* write to database */
        replace_indi(indi0, indi1);

    } else if (needfix) {
        enqueue_list(tofix, strsave(key));
    }
}
Exemplo n.º 19
0
void prim_freadn(PRIM_PROTOTYPE)
{
  FILE *fh;
  char *filename;
  double offset;
  double range;
  char tempBuf[BUFFER_LEN] = "";
  int result;
  int i;
  int found_end = 0;
  char tempChr;
  CHECKOP(3);
  oper1 = POP();   /*The range*/
  oper2 = POP();   /*The offset*/
  oper3 = POP();   /*The filename*/
  if (getuid() == 0 )
  /*Permissions checks*/
    abort_interp("Muck is running under root privs, file prims disabled.");
  if (mlev < LBOY) abort_interp("BOY primitive only.");
  /*Type Checking*/
  if(oper1->type != PROG_INTEGER)
    abort_interp("Arguement 1 is not an integer.");
  if(oper1->data.number > BUFFER_LEN - 10)
    abort_interp("Range is too large. (1)");
  if(oper1->data.number < 0 ) abort_interp("Arguement 1 is a negative number.");
  if(oper2->type != PROG_INTEGER)
    abort_interp("Arguement 2 is not an integer.");
  if(oper2->data.number < 0 ) abort_interp("Arguement 2 is a negative number.");
  if(oper3->type != PROG_STRING) abort_interp("Arguement 3 is not a string.");
  if(!oper3->data.string) abort_interp("Argueemnt 3 is a null string.");
  /*Value assignments*/
  range = oper1->data.number;
  offset = oper2->data.number;
  filename = oper3->data.string->data;
#ifdef SECURE_FILE_PRIMS
  if (!(valid_name(filename)))
      abort_interp( "Invalid file name.");
  if ( strchr( filename, '$' ) == NULL )
    filename = set_directory(filename);
  else
    filename = parse_token( filename );
  if ( filename == NULL )
    abort_interp( "Invalid shortcut used." );
#endif
  fh = fopen(filename, "r");
  if (fh == NULL) { result = 0;  } else {
    for ( i = 0; i < range && found_end != 1; i++, offset++ )
    { fseek(fh, offset, SEEK_SET);
      tempChr = (char) fgetc(fh);
      if (tempChr == EOF)
        found_end = 1;
      else
        tempBuf[i] = tempChr;
    }
    i++;
    tempBuf[i] = '\0';
    fclose(fh);
    if ( tempBuf[0] != EOF )
      result = 1;
    if(tp_log_files)
      log2filetime("logs/files", "#%d by %s FREADN: %s \n", program, unparse_object(player, player), oper3->data.string->data); 
  }
  CLEAR(oper1);
  CLEAR(oper2);
  CLEAR(oper3);
  if( result )
     PushString(tempBuf);     
  else
     PushNullStr;
}
Exemplo n.º 20
0
/*
 * Include files within dirname.  Only files with names ending in ".conf", or
 * consisting entirely of alphanumeric characters, dashes, and underscores are
 * included.  This restriction avoids including editor backup files, .rpmsave
 * files, and the like.
 */
static errcode_t parse_include_dir(const char *dirname,
                                   struct profile_node *root_section)
{
#ifdef _WIN32
    char *wildcard = NULL, *pathname;
    WIN32_FIND_DATA ffd;
    HANDLE handle;
    errcode_t retval = 0;

    if (asprintf(&wildcard, "%s\\*", dirname) < 0)
        return ENOMEM;

    handle = FindFirstFile(wildcard, &ffd);
    if (handle == INVALID_HANDLE_VALUE) {
        retval = PROF_FAIL_INCLUDE_DIR;
        goto cleanup;
    }

    do {
        if (!valid_name(ffd.cFileName))
            continue;
        if (asprintf(&pathname, "%s\\%s", dirname, ffd.cFileName) < 0) {
            retval = ENOMEM;
            break;
        }
        retval = parse_include_file(pathname, root_section);
        free(pathname);
        if (retval)
            break;
    } while (FindNextFile(handle, &ffd) != 0);

    FindClose(handle);

cleanup:
    free(wildcard);
    return retval;

#else /* not _WIN32 */

    DIR     *dir;
    char    *pathname;
    errcode_t retval = 0;
    struct dirent *ent;

    dir = opendir(dirname);
    if (dir == NULL)
        return PROF_FAIL_INCLUDE_DIR;
    while ((ent = readdir(dir)) != NULL) {
        if (!valid_name(ent->d_name))
            continue;
        if (asprintf(&pathname, "%s/%s", dirname, ent->d_name) < 0) {
            retval = ENOMEM;
            break;
        }
        retval = parse_include_file(pathname, root_section);
        free(pathname);
        if (retval)
            break;
    }
    closedir(dir);
    return retval;
#endif /* not _WIN32 */
}
Exemplo n.º 21
0
/* cmdcheck: check the validity of a command and add missing fields */
bool CustomHandler::cmdcheck()
{
	time_t t;
	bool added;

	t = time(nullptr);
	added = false;
	for (Json::Value &val : custom_cmds["commands"]) {
		/* add new values to old commands */
		if (!val.isMember("ctime")) {
			val["ctime"] = (Json::Int64)t;
			added = true;
		}
		if (!val.isMember("mtime")) {
			val["mtime"] = (Json::Int64)t;
			added = true;
		}
		if (!val.isMember("creator")) {
			val["creator"] = "unknown";
			added = true;
		}
		if (!val.isMember("uses")) {
			val["uses"] = 0;
			added = true;
		}
		if (!val.isMember("active")) {
			val["active"] = true;
			added = true;
		}
		if (!(val.isMember("cmd") && val.isMember("response")
					&& val.isMember("cooldown"))) {
			enabled = false;
			fprintf(stderr, "command '%s' is missing required fields\n",
					val["cmd"].asCString());
			return false;
		}
		if (!valid_name(val["cmd"].asCString(), true)) {
			enabled = false;
			fprintf(stderr, "'%s' is an invalid command name -"
					" change or remove it\n",
					val["cmd"].asCString());
			return false;
		}
		if (val["cooldown"].asInt() < 0) {
			enabled = false;
			fprintf(stderr, "command '%s' has a negative cooldown -"
					" change or remove it\n",
					val["cmd"].asCString());
			return false;
		}
		/* check validity of response */
		if (!valid_resp(val["response"].asCString(), err)) {
			fprintf(stderr, "command '%s': %s\n",
					val["cmd"].asCString(), err);
			val["active"] = false;
			added = true;
		}
		if (added)
			write();
		cooldowns->add(val["cmd"].asString(), val["cooldown"].asInt64());
	}
	return true;
}
Exemplo n.º 22
0
/*===================================
 * valid_indi_tree -- Validate person tree
 *  indi1:  [IN]  person to validate
 *  pmsg:   [OUT] error message, if any
 *  orig:   [IN]  person to match - may be NULL
 * rtn: FALSE for bad
 * Should be replaced by valid_indi(RECORD,...) ?
 *=================================*/
BOOLEAN
valid_indi_tree (NODE indi1, STRING *pmsg, NODE orig)
{
	NODE name1, refn1, sex1, body1, famc1, fams1, node;
	NODE name0, refn0, sex0, body0, famc0, fams0;
	INT isex, num;
	STRING *keys, ukey;

	if (!indi1) {
		*pmsg = _(qSbademp);
  		return FALSE;
	}
	if (nestr("INDI", ntag(indi1))) {
		*pmsg = _(qSbadin0);
		return FALSE;
	}
	if (nsibling(indi1)) {
		*pmsg = _(qSbadmul);
		return FALSE;
	}
	split_indi_old(indi1, &name1, &refn1, &sex1, &body1, &famc1, &fams1);
	if (getlloptint("RequireNames", 0) && !name1) {
		*pmsg = _("This person record does not have a name line.");
		goto bad2;
	}
	for (node = name1; node; node = nsibling(node)) {
		if (!valid_name(nval(node))) {
			*pmsg = _(qSbadenm);
			goto bad2;
		}
	}
	name0 = refn0 = sex0 = body0 = famc0 = fams0 = NULL;
	if (orig)
		split_indi_old(orig, &name0, &refn0, &sex0, &body0, &famc0,
		    &fams0);
	if (orig && !iso_nodes(indi1, orig, FALSE, FALSE)) {
		*pmsg = _(qSbadind); 
		goto bad1;
	}
	if (!iso_nodes(famc1, famc0, FALSE, TRUE)) {
		*pmsg = _(qSbadfmc);
		goto bad1;
	}
	if (!iso_nodes(fams1, fams0, FALSE, TRUE)) {
		*pmsg = _(qSbadfms); 
		goto bad1;
	}
	isex = val_to_sex(sex0);
	if (!fams0) isex = SEX_UNKNOWN;
	if (isex != SEX_UNKNOWN && isex != val_to_sex(sex1)) {
		*pmsg = _(qSbadparsex);
		goto bad1;
	}
	ukey = (refn1 ? nval(refn1) : NULL);
	get_refns(ukey, &num, &keys, 'I');
	if (num > 1 || (num == 1 && (!orig ||
	    nestr(keys[0], rmvat(nxref(indi1)))))) {
		*pmsg = _(qSbadirefn);
		goto bad1;
	}
	if (orig)
		join_indi(orig, name0, refn0, sex0, body0, famc0, fams0);
	join_indi(indi1, name1, refn1, sex1, body1, famc1, fams1);
	return TRUE;
bad1:
	if (orig)
		join_indi(orig, name0, refn0, sex0, body0, famc0, fams0);
bad2:
	join_indi(indi1, name1, refn1, sex1, body1, famc1, fams1);
	return FALSE;
}
Exemplo n.º 23
0
/*Fonction du_file -> Permet de donner l'espace mémoire ROM utilisé par le chemin donné en paramètre de la fonction*/
int du_file(const char *pathname) {

	/*Variable contenant le répertoire*/
	DIR *dirp;
	/*Variable path*/
	char path[PATH_MAX + 1], link_path[PATH_MAX + 1];
	/*Structure du répertoire*/
	struct dirent *dp;
	/*Variable contenant la taille du répertoire donné + d'un répertoire qui sera remis à 0 ensuite*/
	int r = 0, dir_size = 0, status;
	/*Structure stat*/
	struct stat sb;

	status = lstat(pathname, &sb);

	/*Si le chemin donné mène vers un fichier, on retourne l'espace mémoire utilisé*/
	if (S_ISREG(sb.st_mode)) {
		return opt_apparent_size?sb.st_size:sb.st_blocks;
	}
	/*Sinon -> répertoire / lien symbolique*/
	else {
	  /*Si c'est un répertoire...*/
	  if (S_ISDIR(sb.st_mode)) {
	    /*On s'assure que l'on peut ouvrir le dossier donné en paramètre*/
	    assert(dirp = opendir(pathname));
	    /*On lit les sous-dossiers*/
	    while((dp=readdir(dirp))) {
	      if(valid_name(dp -> d_name)) {
		assert(strlen(pathname)+1+strlen(dp->d_name)+1 <= PATH_MAX);
		/*On concatène le chemin donné en paramètre avec l'autre dossier ouvert*/
		strcpy(path, pathname);
		strcat(path,"/");
		strcat(path,dp->d_name);
		r+=du_file(path);
		/*Vérification du list_all (option -a)*/
		if (opt_list_all == 1) {
		  dir_size = du_file(path);
		  printf("%d      %s\n",dir_size,path);
		};
		/*Fin de vérification du list_all*/
	      };
	    }
	    r+=opt_apparent_size?sb.st_size:sb.st_blocks;
	    closedir(dirp);
	  }
	  else {
	    /*On vérifie si ce n'est pas un lien symbolique, et si l'option demandé par l'utilisateur est bon*/
	    if (S_ISLNK(sb.st_mode) && (opt_follow_links == 1)) {
	      /*S'il est bon, on fait un readlink sur le pathname, que l'on stocke dans link_path*/
	      status = readlink(pathname, link_path, PATH_MAX);
	      /*Si tout va bien...*/
	      if (status > 0) {
		/*On ferme la chaîne par \0*/
		link_path[status] = '\0';
		/*On ajoute en mémoire l'espace mémoire utilisé pour le fichier pointé par le lien symbolique*/
		r+=opt_apparent_size?sb.st_size:sb.st_blocks;
		r+=du_file(link_path);
	      }
	    }
	  }
	  return r;
	}
	return 0;
}
Exemplo n.º 24
0
int build_address(char *to, char *full_to)
{
	/** loop on all words in 'to' line...append to full_to as
	    we go along, until done or length > len.  Modified to
	    know that stuff in parens are comments...Returns non-zero
	    if it changed the information as it copied it across...
	**/

	int	i, j, k, l,
			in_parens = 0, a_in_parens,
			expanded_information = 0,
			eliminated = 0;
	int too_long = FALSE;
	int to_len;
	char word[SLEN], next_word[SLEN], *ptr;
	char elim_list[SLEN], word_a[SLEN], next_word_a[SLEN];
	char *gecos;

	full_to[0] = '\0';
	to_len = 0;

	elim_list[0] = '\0';

	i = get_word(to, 0, word, sizeof(word));

	/** Look for addresses to be eliminated from aliases **/
	while (i > 0) {

	  j = get_word(to, i, next_word, sizeof(next_word));

	  if(word[0] == '(')
	    in_parens++;

	  if (in_parens) {
	    if(word[strlen(word)-1] == ')')
	      in_parens--;
	  }

	  else if (word[0] == '-') {
	    for (k = 0; word[k] != '\0'; word[k] = word[k+1], k++);
	    if (elim_list[0] != '\0')
	      strcat(elim_list, " ");
	    /*  expand alias and eliminate all members */
	    if ((ptr = get_alias_address(word, TRUE, &too_long)) != NULL) {
	      /*  ignores overflow, like every bloody other place in elm */
	      strcat(elim_list, ptr);
	      too_long = FALSE;
	    } else
	      strcat(elim_list, word);
	  }

	  if ((i = j) > 0)
	    strcpy(word, next_word);
	}

	if (elim_list[0] != '\0')
	  eliminated++;

	i = get_word(to, 0, word, sizeof(word));

	while (i > 0) {

	  j = get_word(to, i, next_word, sizeof(next_word));

	  if(word[0] == '(')
	    in_parens++;

	  if (in_parens) {
	    if(word[strlen(word)-1] == ')')
	      in_parens--;
	    strcpy(full_to+to_len, " ");
	    strcpy(full_to+to_len+1, word);
	    to_len += strlen(word)+1;
	  }

	  else if (word[0] == '-') {
		; /* huh??? I don't understand this  (*FOO*) */
	  }

	  else if (qstrpbrk(word,"!@:") != NULL) {
	    if (to_len > 0) {
		(void) strcpy(full_to+to_len, ", ");
		to_len += 2;
	    }
	    (void) strcpy(full_to+to_len, word);
	    to_len += strlen(word);
	  }
	  else if ((ptr = get_alias_address(word, TRUE, &too_long)) != NULL) {

	    /** check aliases for addresses to be eliminated **/
	    if (eliminated) {
	      k = get_word(strip_commas(ptr), 0, word_a, sizeof(word_a));

	      while (k > 0) {
		l = get_word(ptr, k, next_word_a, sizeof(next_word_a));
		if (in_list(elim_list, word_a) == 0) {

		if (to_len > 0) {
		    (void) strcpy(full_to+to_len, ", ");
		    to_len += 2;
		}
		(void) strcpy(full_to+to_len, word_a);
		to_len += strlen(word_a);

		  /** copy possible () comment **/
		  if (next_word_a[0] == '(') {
		    a_in_parens = 0;

		    while (l > 0) {
		      if (to_len > 0) {
			(void) strcpy(full_to+to_len, " ");
			++to_len;
		      }
		      (void) strcpy(full_to+to_len, next_word_a);
		      to_len += strlen(next_word_a);
		      if (next_word_a[0] == '(')
			++a_in_parens;
		      if (next_word_a[strlen(next_word_a)-1] == ')')
			--a_in_parens;
		      l = get_word(ptr, l, next_word_a, sizeof(next_word_a));
		      if (! a_in_parens)
			break;
		    }
		  }
		}
		else {
		  /** skip possible () comment **/
                  if (next_word_a[0] == '(') {
                    a_in_parens = 0;

                    while (l > 0) {
                      if (next_word_a[0] == '(')
                        ++a_in_parens;
                      if (next_word_a[strlen(next_word_a)-1] == ')')
                        --a_in_parens;
                      l = get_word(ptr, l, next_word_a, sizeof(next_word_a));
                      if (! a_in_parens)
                        break;
                    }
                  }
		}

		if ((k = l) > 0)
		  strcpy(word_a, next_word_a);
	      }
	    } else {
	      if (to_len > 0) {
		  (void) strcpy(full_to+to_len, ", ");
		  to_len += 2;
	      }
	      (void) strcpy(full_to+to_len, ptr);
	      to_len += strlen(ptr);
	    }
	    expanded_information++;
	  }
	  else if (too_long) {
	 /*
	  *   We don't do any real work here.  But we need some
	  *   sort of test in this line of tests to make sure
	  *   that none of the other else's are tried if the
	  *   alias expansion failed because it was too long.
	  */
	      dprint(2,(debugfile,"Overflowed alias expansion for %s\n", word));
	  }
	  else if (word[0] != '\0') {
	    if (to_len > 0) {
	      (void) strcpy(full_to+to_len, ", ");
	      to_len += 2;
	    }
	    if (valid_name(word)) {
	      (void) strcpy(full_to+to_len, word);
	      to_len += strlen(word);

	      if (next_word[0] != '(')
		if ((gecos = get_full_name(word)) != NULL && *gecos != '\0') {
		  sprintf(full_to+to_len, " (%s)", gecos);
		  to_len += strlen(gecos)+3;
		}
	    } else {
	      (void) strcpy(full_to+to_len, word);
	      to_len += strlen(word);
	    }
	  }

	  if((i = j) > 0)
	    strcpy(word, next_word);
	}

	return( expanded_information > 0 ? 1 : 0 );
}
Exemplo n.º 25
0
void op_ospath()
{
 /* Stack:

     |================================|=============================|
     |            BEFORE              |           AFTER             |
     |================================|=============================|
 top |  Key                           | Information                 |
     |--------------------------------|-----------------------------| 
     |  Pathname string               |                             |
     |================================|=============================|

 Key values:           Action                             Returns
     0  OS_PATHNAME    Test if valid pathname             True/False
     1  OS_FILENAME    Test if valid filename             True/False
                       or directory file record name
     2  OS_EXISTS      Test if file exists                True/False
     3  OS_UNIQUE      Make a unique file name            Name
     4  OS_FULLPATH    Return full pathname               Name
     5  OS_DELETE      Delete file                        Success/Failure
     6  OS_CWD         Get current working directory      Pathname
     7  OS_DTM         Return date/time modified          DTM value
     8  OS_FLUSH_CACHE Flush DH file cache                -
     9  OS_CD          Change working directory           Success/Failure
    10  OS_MAPPED_NAME Map a directory file name          Mapped name
    11  OS_OPEN        Check if path is an open file      True/False
    12  OS_DIR         Return content of directory        Filenames
    13  OS_MKDIR       Make a directory                   True/False
    14  OS_MKPATH      Make a directory path              True/False

 Pathnames with lengths outside the range 1 to MAX_PATHNAME_LEN return
 0 regardless of the action key.

 */

 long int status = 0;
 short int key;
 DESCRIPTOR * descr;
 char path[MAX_PATHNAME_LEN+1];
 short int path_len;
 char name[MAX_PATHNAME_LEN+1];
 char * p;
 char * q;
 STRING_CHUNK * head;
 int file_id;
 FILE_ENTRY * fptr;
 struct stat stat_buff;
 DIR * dfu;
 struct dirent * dp;
 long int n;

 /* Get action key */

 descr = e_stack - 1;
 GetInt(descr);
 key = (short int)(descr->data.value);
 k_pop(1);

 /* Get pathname */

 descr = e_stack - 1;
 path_len = k_get_c_string(descr, path, MAX_PATHNAME_LEN);
 k_dismiss();
 if (path_len < 0) goto set_status;
#ifdef CASE_INSENSITIVE_FILE_SYSTEM
 UpperCaseString(path);
#endif

 switch(key)
  {
   case OS_PATHNAME:     /* Test if valid pathname */
      p = path;
      if (*p == '/') p++;

      do {
          q = strchr(p, '/');
          if (q != NULL) *q = '\0';
          if (!valid_name(p)) goto set_status;
          p = q + 1;
         } while(q != NULL);
      status = 1;


      break;

   case OS_FILENAME:     /* Test if valid pathname */
      status = (long int)valid_name(path);
      break;

   case OS_EXISTS:     /* Test if file exists */
      status = !access(path, 0);
      break;

   case OS_UNIQUE:  /* Make unique file name. Path variable holds directory name */
      n = (time(NULL) * 10) & 0xFFFFFFFL;
      do {
          sprintf(name, "%s\\D%07lX", path, n);
          n--;
         } while(!access(name, 0));
      sprintf(name, "D%07lX", n);
      k_put_c_string(name, e_stack);
      e_stack++;
      goto exit_op_pathinfo;

   case OS_FULLPATH:     /* Expand path to full OS pathname */
      fullpath(name, path);
      k_put_c_string(name, e_stack);
      e_stack++;
      goto exit_op_pathinfo;

   case OS_DELETE:
      flush_dh_cache();
      status = (long int)delete_path(path);
      break;

   case OS_CWD:
      (void)getcwd(name, MAX_PATHNAME_LEN);
#ifdef CASE_INSENSITIVE_FILE_SYSTEM
      UpperCaseString(name);
#endif
      k_put_c_string(name, e_stack);
      e_stack++;
      goto exit_op_pathinfo;

   case OS_DTM:
      if (stat(path, &stat_buff) == 0) status = stat_buff.st_mtime;
      break;

   case OS_FLUSH_CACHE:
      flush_dh_cache();
      break;

   case OS_CD:
      status = attach(path);
      break;

   case OS_MAPPED_NAME:    /* Map a directory file record name */
      (void)map_t1_id(path, strlen(path), name);
      k_put_c_string(name, e_stack);
      e_stack++;
      goto exit_op_pathinfo;

   case OS_OPEN:
      fullpath(name, path);
      for(file_id = 1; file_id <= sysseg->used_files; file_id++)
       {
        fptr = FPtr(file_id);
        if ((fptr->ref_ct != 0)
          && (strcmp((char *)(fptr->pathname), name) == 0))
         {
          status = TRUE;
          break;
         }
       }
      break;

   case OS_DIR:
      head = NULL;
      ts_init(&head, 1024);
      if ((dfu = opendir(path)) != NULL)
       {
        if (path[path_len-1] == DS) path[path_len-1] = '\0';

        while((dp = readdir(dfu)) != NULL)
         {
          if (strcmp(dp->d_name, ".") == 0) continue;
          if (strcmp(dp->d_name, "..") == 0) continue;

          sprintf(name, "%s%c%s", path, DS, dp->d_name);
          if (stat(name, &stat_buff)) continue;

          strcpy(name+1, dp->d_name);
#ifdef CASE_INSENSITIVE_FILE_SYSTEM
          UpperCaseString(name+1);
#endif
          if (stat_buff.st_mode & S_IFDIR)
           {
            name[0] = 'D';
            if (head != NULL) ts_copy_byte(FIELD_MARK);
            ts_copy_c_string(name);
           }
          else if (stat_buff.st_mode & S_IFREG)
           {
            name[0] = 'F';
            if (head != NULL) ts_copy_byte(FIELD_MARK);
            ts_copy_c_string(name);
           }
         }

        closedir(dfu);
       }
      ts_terminate();
      InitDescr(e_stack, STRING);
      (e_stack++)->data.str.saddr = head;
      goto exit_op_pathinfo;      

   case OS_MKDIR:
      status = !MakeDirectory(path);
      break;

   case OS_MKPATH:
      status = make_path(path);
      break;
       
   default:
      k_error(sysmsg(1010));
  }

set_status:

 /* Set status value on stack */

 InitDescr(e_stack, INTEGER);
 (e_stack++)->data.value = status;

exit_op_pathinfo:
 return;
}