Ejemplo n.º 1
0
/***************************************
 * API - setup the mailbox directory
 * 
 * IN:
 *  nodeid      - node id for this node
 *  create_link - not 0 if symbolic link
  *               needs to be created
 ***************************************/
int
mb_init_mailboxes(cmm_nodeid_t nodeid,
                  int create_link)
{
    char buffer[MAXPATHLEN];
    char localnode[MAXPATHLEN];
    int err;

    snprintf(buffer, sizeof(buffer), "%s/%d",
             MAILBOX_PATH, nodeid);

    err = check_dir(buffer, NULL);
    if (err) {
        return(1);
    }

    if (!create_link) {
        return(0);
    }

    /* Create the link */

    snprintf(localnode, sizeof(buffer), "%s/0",
             MAILBOX_PATH);
    
    err = check_dir(localnode, buffer);
    if (err) {
        return(1);
    }
    return(0);
}
Ejemplo n.º 2
0
static void
amgtar_selfcheck(
    application_argument_t *argument)
{
    amgtar_build_exinclude(&argument->dle, 1, NULL, NULL, NULL, NULL);

    printf("OK amgtar\n");
    if (gnutar_path) {
	check_file(gnutar_path, X_OK);
    } else {
	printf(_("ERROR [GNUTAR program not available]\n"));
    }

    set_root_privs(1);
    if (gnutar_listdir && strlen(gnutar_listdir) == 0)
	gnutar_listdir = NULL;
    if (gnutar_listdir) {
	check_dir(gnutar_listdir, R_OK|W_OK);
    } else {
	printf(_("ERROR [No GNUTAR-LISTDIR]\n"));
    }

    if (argument->dle.disk) {
	char *qdisk = quote_string(argument->dle.disk);
	fprintf(stdout, "OK %s\n", qdisk);
	amfree(qdisk);
    }
    if (gnutar_directory) {
	check_dir(gnutar_directory, R_OK);
    } else if (argument->dle.device) {
	check_dir(argument->dle.device, R_OK);
    }
    set_root_privs(0);
}
Ejemplo n.º 3
0
END_TEST

START_TEST(test_private_ccache_dir_in_user_dir)
{
    int ret;
    char *cwd;
    char *user_dir;
    char *dn1;
    char *dn2;
    char *dn3;
    char *filename;
    uid_t uid = getuid();
    gid_t gid = getgid();

    if (uid == 0) {
        uid = 12345;
        gid = 12345;
    }

    cwd = getcwd(NULL, 0);
    fail_unless(cwd != NULL, "getcwd failed.");

    user_dir = talloc_asprintf(tmp_ctx, "%s/%s/user", cwd, TESTS_PATH);
    free(cwd);
    fail_unless(user_dir != NULL, "talloc_asprintf failed.");
    ret = mkdir(user_dir, 0700);
    fail_unless(ret == EOK, "mkdir failed.");
    ret = chown(user_dir, uid, gid);
    fail_unless(ret == EOK, "chown failed.");

    dn1 = talloc_asprintf(tmp_ctx, "%s/a", user_dir);
    fail_unless(dn1 != NULL, "talloc_asprintf failed.");
    dn2 = talloc_asprintf(tmp_ctx, "%s/b", dn1);
    fail_unless(dn2 != NULL, "talloc_asprintf failed.");
    dn3 = talloc_asprintf(tmp_ctx, "%s/c", dn2);
    fail_unless(dn3 != NULL, "talloc_asprintf failed.");
    filename = talloc_asprintf(tmp_ctx, "%s/ccfile", dn3);
    fail_unless(filename != NULL, "talloc_asprintf failed.");

    ret = chmod(user_dir, 0600);
    fail_unless(ret == EOK, "chmod failed.");
    ret = cc_file_create(filename, NULL, uid, gid, true);
    fail_unless(ret == EINVAL, "cc_file_create does not return EINVAL "
                               "while x-bit is missing.");

    ret = chmod(user_dir, 0700);
    fail_unless(ret == EOK, "chmod failed.");
    ret = cc_file_create(filename, NULL, uid, gid, true);
    fail_unless(ret == EOK, "cc_file_create failed.");

    check_dir(dn3, uid, gid, 0700);
    RMDIR(dn3);
    check_dir(dn2, uid, gid, 0700);
    RMDIR(dn2);
    check_dir(dn1, uid, gid, 0700);
    RMDIR(dn1);
    RMDIR(user_dir);
}
Ejemplo n.º 4
0
int main() {
	printf("input.txt is a regular file? %s\n",
	    check_reg("input.txt") ? "yes" : "no");
	printf("docs is a directory? %s\n",
	    check_dir("docs") ? "yes" : "no");
	printf("/input.txt is a regular file? %s\n",
	    check_reg("/input.txt") ? "yes" : "no");
	printf("/docs is a directory? %s\n",
	    check_dir("/docs") ? "yes" : "no");
	return 0;
}
Ejemplo n.º 5
0
void check_dir(char *search_dir, int fd)
{
	DIR *dir;
        struct dirent *ent;
        dir = opendir (search_dir);
        if (dir != NULL)
	{

	        /* print all the files and directories within directory */
	        while ((ent = readdir (dir)) != NULL)
		{
	        	if(ent->d_type & DT_DIR)
		        {
				if(ent->d_name[0] != '.' || strlen(ent->d_name)>2)
				{
				
				printf("Letar i mappen %s\n", search_dir);
				printf("Hittade den nya mappen %s\n", ent->d_name);
				

				char *directory = malloc(strlen(search_dir) + strlen(ent->d_name) + 2);
				strcpy(directory,search_dir);
				strcat(directory,"/");
				strcat(directory,ent->d_name);

				inotify_add_watch(fd,directory,IN_MODIFY | IN_CREATE | IN_DELETE);
				check_dir(directory, fd);
				}
		        }                
		}
	}
	closedir (dir);
	}
Ejemplo n.º 6
0
int
create_dir (char *path)
{
  char *parent;
  char *tmp;
  int rc;

  tmp = strdup (path);		/* preserve our string */
  parent = dirname (tmp);
  rc = check_dir (parent);
  if (strcmp (parent, "/") == 0)
    {
      return -1;		/* stop endless loop */
    }
  if (rc == MISC_NOT_DIR || rc == MISC_NOT_WRITABLE)
    {
      return -1;
    }
  else if (rc == MISC_DOES_NOT_EXISTS)
    {
      /* recursively create */
      if (create_dir (parent) != 0)
	{
	  fprintf (stderr, "failed to create %s\n", parent);
	  return -1;
	}
    }
  rc = mkdir (path, 0755);
  free (tmp);
  return rc;
}
Ejemplo n.º 7
0
//handling readlink request
void readlink_handler(Msg *msg, int sender_pid)
{

    char symname[MAXPATHNAMELEN];
    memset(symname,'\0',MAXPATHNAMELEN);
    CopyFrom(sender_pid,symname,msg->ptr1,msg->num2+1);
    int return_len=msg->num3;

    char* filename = symname+msg->num2;
    int direct_len = msg->num2;
    while ((*filename)!='/' && filename!=symname) {
        filename--;
        direct_len--;
    }
    if ((*filename)=='/') {
        direct_len++;
        filename++;
    }

    int parent_inum=path_to_inum(symname,direct_len,msg->num1,0);
    int sym_inum=check_dir(parent_inum,filename);
    if(sym_inum<=0){
        msg->type=-1;
        return;
    }
    inode_cache *sym_inode=read_inode(sym_inum);
    block_cache *sym_block=read_block(sym_inode->data.direct[0]);
    if(sym_inode->data.size<return_len)
        return_len=sym_inode->data.size;

    CopyTo(sender_pid,msg->ptr2,sym_block->data,return_len);

    msg->num3=return_len;

}
Ejemplo n.º 8
0
//handling stat request
void stat_handler(Msg *msg, int sender_pid)
{
    char pathname[MAXPATHNAMELEN];
    CopyFrom(sender_pid,pathname,msg->ptr1,msg->num1+1);

    char* filename = pathname+msg->num2;
    int direct_len = msg->num2;
    while ((*filename)!='/' && filename!=pathname) {
        filename--;
        direct_len--;
    }
    if ((*filename)=='/') {
        direct_len++;
        filename++;
    }

    int parent_inum = path_to_inum(pathname,direct_len,msg->num2,0);
    int inum=check_dir(parent_inum,filename);
    struct Stat s;
    inode_cache *n = read_inode(inum);
    s.inum = inum;
    s.type = n->data.type;
    s.size = n->data.size;
    s.nlink = n->data.nlink;
    CopyTo(sender_pid,msg->ptr2,&s,sizeof(struct Stat));

}
Ejemplo n.º 9
0
void init_maps(void)
{
	uint32 i = 0;
	uint32 n = 0;
	char *path;

	map_array = (map_t *)calloc(MAX_MAPS, sizeof(map_t));
	map_array_cache = (buffer_t *)calloc(MAX_MAPS, sizeof(buffer_t));

	for( i = 0; i < MAX_MAPS; i++){
		map_array[i].name = (char *)calloc(MAX_NAME_LENGTH, sizeof(char));
		map_array[i].npc = (map_npc_t *)calloc(MAX_MAP_NPCS, sizeof(map_npc_t));
		map_array[i].tile = (tile_t *)calloc(MAX_MAPX * MAX_MAPY, sizeof(tile_t));
		map_array[i].items = (map_item_t *)calloc(MAX_MAP_ITEMS, sizeof(map_item_t));

		for( n = 0; n < MAX_MAP_NPCS; n++)
			map_array[i].npc[n].vitals = (uint16 *)calloc(VITAL_COUNT, sizeof(uint16));

		path = get_path(MAP_PATH, i, FILE_ENDING);

		check_dir(MAP_PATH);

		if(file_readable(path))
			read_map(path,i);
		else
			write_map(path,i);

		mapcache_create(i);
	}
}
Ejemplo n.º 10
0
Archivo: main.c Proyecto: CDragu/pspsdk
void change_dir(char *currdir, const char *dir)
{
	char tempdir[1024];

	if(dir == NULL)
	{
		printf("ERROR: Must supply a directory argument\n");
		return;
	}

	if(strcmp(dir, "..") == 0)
	{
		up_dir(currdir);
		return;
	}

	(void) snprintf(tempdir, sizeof(tempdir), "%s/%s", currdir, dir);
	if(check_dir(tempdir))
	{
		strcpy(currdir, tempdir);
	}
	else
	{
		printf("ERROR: Invalid directory '%s'\n", tempdir);
	}
}
Ejemplo n.º 11
0
void init_server(void)
{
	printf("Initializing Data. \n");
	check_dir(LOG_PATH);

	printf("Loading Items. \n");
	init_items();

	printf("Loading Maps. \n");
	init_maps();

	printf("Loading Npcs. \n");
	init_npcs();

	printf("Loading Shops. \n");
	init_shops();

	printf("Loading Spells. \n");
	init_spells();

	printf("Initializing Player Data. \n");
	init_players();

	printf("Initializing Temp Player Data. \n");
	init_temp_player_index();

	printf("Data Initialized. \n");
}
Ejemplo n.º 12
0
static
void
check_root_dir(void)
{
	struct sfs_inode sfi;
	diskread(&sfi, SFS_ROOT_LOCATION);
	swapinode(&sfi);

	switch (sfi.sfi_type) {
	    case SFS_TYPE_DIR:
		break;
	    case SFS_TYPE_FILE:
		warnx("Root directory inode is a regular file (fixed)");
		goto fix;
	    default:
		warnx("Root directory inode has invalid type %lu (fixed)",
		      (unsigned long) sfi.sfi_type);
	    fix:
		setbadness(EXIT_RECOV);
		sfi.sfi_type = SFS_TYPE_DIR;
		swapinode(&sfi);
		diskwrite(&sfi, SFS_ROOT_LOCATION);
		break;
	}

	check_dir(SFS_ROOT_LOCATION, SFS_ROOT_LOCATION, "");
}
Ejemplo n.º 13
0
Archivo: initrd.c Proyecto: borlox/kos
static int check_dir(void *buf, int offset, FILE *log, int idt)
{
	struct id_entry *entry = (buf + offset);

	LOG("* Checking dir at offset %d:\n", offset);
	LOG("|- Type:        %d (%s)\n", entry->type, type_to_name[entry->type]);
	LOG("|- NameOffs:    %d\n", entry->name);
	LOG("|- Count:       %d\n", entry->count);
	LOG("|- ContentOffs: %d\n", entry->content);
	LOG("|- NextOffs:    %d\n", entry->next);

	char *name = (char*)(buf + entry->name);
	LOG("`- Name: '%s' with length %d\n", name, strlen(name) + 1);

	int offs = entry->content;
	int i=0;
	for (; i < entry->count; ++i) {
		struct id_entry *e = (buf + offs);
		if (e->type == 0) {
			offs = check_file(buf, offs, log, idt + 1);
		}
		else if (e->type == 1) {
			offs = check_dir(buf, offs, log, idt + 1);
		}
		else {
			LOG("Error: Unknown type!\n");
			abort();
		}
	}

	return entry->next;
}
Ejemplo n.º 14
0
/**
 *保存、修改目录文件
 *@param str 内容
 *-1:失败 0:成功
 */
int save_or_modify_catalog_file(char *str){
   int tryTime = 0; //重试次数
   int isSuccess = -1;//是否成功
   int fd = -1;
   int i = 0;
   
   while(tryTime<10 && isSuccess==-1){
      if(check_dir()){ //文件夹data存在
        fd = open(CATALOG_FILE,O_WRONLY|O_CREAT|O_TRUNC);
        
        if(fd == -1){ //失败
          isSuccess = -1;
        }else{ //成功
          fprintf(stderr,"新增或修改目录:%s\n",str);
          /*for(i=0 ; i<strlen(str) ; i++){
            write(fd,str[i],1);
            fprintf(stderr,"%c",str[i]);
          }*/
          write(fd,str,strlen(str));
          isSuccess = close(fd);
        }
        
      }
      tryTime++;
   }
   
   return isSuccess;
}
Ejemplo n.º 15
0
int ensure_dir (const char *path)
{
    char dir[PATH_MAX];
    strcpy (dir, path);
    dirname (dir);
    trace ("artwork: ensure folder %s exists\n", dir);
    return check_dir (dir);
}
Ejemplo n.º 16
0
int start_crfs(char *sessionid, char *fullpath, int mig)
{
    int rv;
    char realdir[256];

    if (parse_ckptname(fullpath, realdir, crfile_basename) != 0) {
        printf("%s: Error at parsing ckfile: %s\n", __func__, fullpath);
        return -1;
    }
    if (check_dir(realdir) != 0) {
        return -1;
    }
    strcpy(crfs_sessionid, sessionid);
    dbg("parse fullpath: %s to %s : %s \n", fullpath, realdir, crfile_basename);

    /// now, init the bufpool & chunk-size
    long val;
    char *p;
    p = getenv("MV2_CKPT_AGGREGATION_BUFPOOL_SIZE");
    if (p && (val = parse_value_string(p)) > 0) {
        srv_rdmabuf_size = cli_rdmabuf_size = val;
    }
    p = getenv("MV2_CKPT_AGGREGATION_CHUNK_SIZE");
    if (p && (val = parse_value_string(p)) > 0) {
        rdmaslot_size = (int) val;
    }
    dbg("cli_rdmabuf_size=%ld, srv_rdmabuf_size=%ld, slot-size=%d\n", cli_rdmabuf_size, srv_rdmabuf_size, rdmaslot_size);

    rv = start_crfs_wa(sessionid, realdir);
    dbg("[mt_%d]: Start WA ret %d\n", mt_id, rv);

    if (rv != 0) {
        err("Fail to start CR-aggregation...\n");
        return rv;
    }
    // this "fullpath" is used in aggre-based ckpt
    snprintf(fullpath, MAX_PATH_LEN, "%s%s", crfs_wa_mnt, crfile_basename);
    dbg("Now, def cktp file=%s\n", fullpath);
    dbg("---------  crfs-mig func=%d\n", mig);

    has_mig_fs = 0;
    if (mig > 0) {
        rv = start_crfs_mig(sessionid, mig);
        dbg("[mt_%d]: Start Mig ret %d\n", mt_id, rv);
        if (rv == 0) {
            has_mig_fs = mig;
            // this mig_filename is the filename used in aggre-based migration
            snprintf(crfs_mig_filename, MAX_PATH_LEN, "%s%s", crfs_mig_mnt, crfile_basename);
        } else {
            err("Fail to start Aggre-for-Migration...\n");
            stop_crfs_wa();
            return rv;
        }
    }

    return rv;
}
Ejemplo n.º 17
0
void  wakeup_hdd(const char *hdd_dir)
{
	if(!check_dir(hdd_dir)){
		std::string wakeup_file = hdd_dir;
		wakeup_file += "/.wakeup";
		remove(wakeup_file.c_str());
		creat(wakeup_file.c_str(),S_IREAD|S_IWRITE);
		sync();
	}
}
Ejemplo n.º 18
0
END_TEST

START_TEST(test_priv_ccache_dir)
{
    int ret;
    char *cwd;
    char *testpath;
    char *dirname;
    char *subdir;
    char *filename;
    uid_t uid = 12345;
    gid_t gid = 12345;

    fail_unless(getuid() == 0, "This test must be run as root.");

    cwd = getcwd(NULL, 0);
    fail_unless(cwd != NULL, "getcwd failed.");

    testpath = talloc_asprintf(tmp_ctx, "%s/%s", cwd, TESTS_PATH);
    free(cwd);
    fail_unless(testpath != NULL, "talloc_asprintf failed.");
    dirname = talloc_asprintf(tmp_ctx, "%s/base", testpath);
    subdir = talloc_asprintf(tmp_ctx, "%s/priv_ccdir", dirname);
    fail_unless(subdir != NULL, "talloc_asprintf failed.");
    filename = talloc_asprintf(tmp_ctx, "%s/ccfile", subdir);
    fail_unless(filename != NULL, "talloc_asprintf failed.");

    ret = chmod(testpath, 0754);
    fail_unless(ret == EOK, "chmod failed.");
    ret = cc_file_create(filename, NULL, uid, gid, true);
    fail_unless(ret == EINVAL, "cc_file_create does not return EINVAL "
                               "while x-bit is missing.");

    ret = chmod(testpath, 0755);
    fail_unless(ret == EOK, "chmod failed.");
    ret = cc_file_create(filename, NULL, uid, gid, true);
    fail_unless(ret == EOK, "cc_file_create failed.");

    check_dir(subdir, uid, gid, 0700);
    RMDIR(subdir);
    check_dir(dirname, 0, 0, 0755);
    RMDIR(dirname);
}
Ejemplo n.º 19
0
//handling mkdir request
void mkdir_handler(Msg *msg, int sender_pid)
{
    char pathname[MAXPATHNAMELEN];
    CopyFrom(sender_pid,pathname,msg->ptr1,msg->num1+1);
    char* dir_name = pathname+msg->num1;
    int direct_len = msg->num1;
    while ((*dir_name)!='/' && dir_name!=pathname) {
        dir_name--;
        direct_len--;
    }
    if ((*dir_name)=='/') {
        direct_len++;
        dir_name++;
    }
    if (strlen(dir_name)==0) {
        perror("invalid pathname when creating file!");
        msg->type = ERROR;
        return;
    }
    int direct_inum = path_to_inum(pathname,direct_len,msg->num2,0);
    if (direct_inum<=0) {
        perror("invalid pathname when creating file!");
        msg->type = ERROR;
        return;
    }
    int new_inum = check_dir(direct_inum,dir_name);
    if (new_inum<0) {
        perror("invalid pathname when creating file!");
        msg->type = ERROR;
        return;
    }

    //exist same file name in the directory
    else if (new_inum>0) {
        perror("exist a directory with same name");
        msg->type = ERROR;
        return;
    }
    else if (new_inum==0) {
        new_inum = alloc_inode(INODE_DIRECTORY,direct_inum);
        struct dir_entry *d = empty_dir(direct_inum);
        if (d==NULL) {
            perror("no empty space for new directory");
            msg->type = ERROR;
            return;
        }
        d->inum = new_inum;
        memcpy(d->name,dir_name,strlen(dir_name));
        inode_cache *n = read_inode(direct_inum);
        n->data.nlink++;
        n->data.size+=sizeof(struct dir_entry);
        n->dirty = 1;
        msg->num1 = 0;
    }
}
Ejemplo n.º 20
0
static int _log_fopen(const char *path)
{
    check_dir(path);
    _log_fp = fopen(path, "a+");
    if (!_log_fp) {
        fprintf(stderr, "fopen %s failed: %s\n", path, strerror(errno));
        fprintf(stderr, "use stderr as output\n");
        _log_fp = stderr;
    }
    return 0;
}
Ejemplo n.º 21
0
static int _log_open(const char *path)
{
    check_dir(path);
    _log_fd = open(path, O_RDWR|O_CREAT|O_APPEND, 0644);
    if (_log_fd == -1) {
        fprintf(stderr, "open %s failed: %s\n", path, strerror(errno));
        fprintf(stderr, "use STDERR_FILEIO as output\n");
        _log_fd = STDERR_FILENO;
    }
    return 0;
}
Ejemplo n.º 22
0
void		check(t_game *game)
{
	t_point dir;

	dir.x = -1;
	dir.y = 0;
	if (check_dir(game, &dir))
		return ;
	dir.x = 1;
	if (check_dir(game, &dir))
		return ;
	dir.x = 0;
	dir.y = -1;
	if (check_dir(game, &dir))
		return ;
	dir.y = 1;
	if (check_dir(game, &dir))
		return ;
	game->scene = MENU_LOSE;
}
Ejemplo n.º 23
0
/*
* Create the parent directory if they do not exist. Or check the permission if
* the race condition happens.
* Give 0 or 1 to represent whether this is the final component. If it is, we
* need to check the permission.
*/
int create_validate_dir(char* npath, mode_t perm, char* path, int finalComponent) {
  struct stat sb;
  if (stat(npath, &sb) != 0) {
    if (mkdir(npath, perm) != 0) {
      if (errno != EEXIST || stat(npath, &sb) != 0) {
        fprintf(LOGFILE, "Can't create directory %s - %s\n", npath,
                strerror(errno));
        return -1;
      }
      // The directory npath should exist.
      if (check_dir(npath, sb.st_mode, perm, finalComponent) == -1) {
        return -1;
      }
    }
  } else {
    if (check_dir(npath, sb.st_mode, perm, finalComponent) == -1) {
      return -1;
    }
  }
  return 0;
}
Ejemplo n.º 24
0
/* return a char* to $HOME/.gngeo/ 
   DO NOT free it!
*/
char *get_gngeo_dir(void) {
    static char *filename=NULL;
    int len = strlen(getenv("HOME")) + strlen("/.gngeo/") + 1;
    int i;
    if (!filename) {
	filename=malloc(len*sizeof(char));
	sprintf(filename,"%s/.gngeo/",getenv("HOME"));
    }
    check_dir(filename);
    //printf("get_gngeo_dir %s\n",filename);
    return filename;
}
bool calculate_thread::set(DWIConstTable * _dwi_para, PWIConstTable * _pwi_para, QString _data_dir, const QString & _version_guid){
    dwi_para = _dwi_para;
    pwi_para = _pwi_para;
    data_dir = _data_dir;
    //check data dir right format
    if(!check_dir(data_dir)){
        return false;
    }
    version_guid = _version_guid;
    //auto make dir by version_guid
    auto_mkdir(data_dir, version_guid);
    return true;
}
Ejemplo n.º 26
0
static void
amstar_selfcheck(
    application_argument_t *argument)
{
    fprintf(stdout, "OK amstar\n");
    if (argument->dle.disk) {
	char *qdisk = quote_string(argument->dle.disk);
	fprintf(stdout, "OK %s\n", qdisk);
	amfree(qdisk);
    }
    if (argument->dle.device) {
	char *qdevice = quote_string(argument->dle.device);
	fprintf(stdout, "OK %s\n", qdevice);
	amfree(qdevice);
    }
    if (star_directory) {
	char *qdirectory = quote_string(star_directory);
	fprintf(stdout, "OK %s\n", qdirectory);
	amfree(qdirectory);
    }

    if (argument->dle.include_list &&
	argument->dle.include_list->nb_element >= 0) {
	fprintf(stdout, "ERROR include-list not supported for backup\n");
    }

    if (!star_path) {
	fprintf(stdout, "ERROR STAR-PATH not defined\n");
    } else {
	check_file(star_path, X_OK);
    }

    if (argument->calcsize) {
	char *calcsize = vstralloc(amlibexecdir, "/", "calcsize", NULL);
	check_file(calcsize, X_OK);
	check_suid(calcsize);
	amfree(calcsize);
    }

    {
	char *amandates_file;
	amandates_file = getconf_str(CNF_AMANDATES);
	check_file(amandates_file, R_OK|W_OK);
    }

    set_root_privs(1);
    if (argument->dle.device) {
	check_dir(argument->dle.device, R_OK);
    }
    set_root_privs(0);
}
Ejemplo n.º 27
0
Archivo: initrd.c Proyecto: borlox/kos
void id_check(const char *file, const char *logfile)
{
	FILE *log = fopen(logfile, "w");

	int fs = file_size(file);

	FILE *f = fopen(file, "rb");
	char *buffer = malloc(fs);
	fread(buffer, 1, fs, f);
	fclose(f);

	int offs = check_header(buffer, log);
	check_dir(buffer, offs, log, 0);
}
Ejemplo n.º 28
0
bool check_spool_dir(Conf *conf)
{
    if (conf->spool_dir == NULL) {
        warnx("spool_dir not defined");
        return false;
    }

    if (!check_dir(conf->spool_dir))
        return false;

    char *mdp; // spool path
    if (asprintf(&mdp, "%s%s%s", conf->spool_dir, DIR_SEP, MSGS_DIR) == -1)
        errx(1, "check_spool_dir: asprintf: unable to allocate memory");

    if (!check_dir(mdp)) {
        free(mdp);
        return false;
    }

    free(mdp);

    return true;
}
Ejemplo n.º 29
0
static void do_copy(const acl::string& from, const acl::string& to)
{
	acl::scan_dir scan;
	if (scan.open(from.c_str()) == false)
	{
		logger_error("open path: %s error: %s",
			from.c_str(), acl::last_serror());
		return;
	}

	const char* name;
	bool  is_file;
	int   nfiles = 0, ndirs = 0, nfiles_copied = 0, ndirs_copied = 0;
	while ((name = scan.next(false, &is_file)) != NULL)
	{
		SKIP(name);

		if (is_file)
		{
			if (cmp_copy(scan, name, to, &nfiles_copied) == false)
			{
				printf(">>cm_copy failed, name: %s\r\n", name);
				break;
			}
			nfiles++;
		}
		else if (check_dir(scan, to, &ndirs_copied) == false)
		{
			printf(">>check_dir failed, name: %s\r\n", name);
			break;
		}
		else
			ndirs++;

		if ((nfiles + ndirs) % 100 == 0)
		{
			printf("current file count: copied %d / scaned %d, "
				"dir count: copied %d / scaned %d\r",
				nfiles_copied, nfiles, ndirs_copied, ndirs);
			fflush(stdout);
		}
	}

	printf("total file count: copyied %d / scaned %d, dir count: "
		"copied %d / scaned %d\r\n", nfiles_copied, nfiles,
		ndirs_copied, ndirs);
}
Ejemplo n.º 30
0
void		my_move_dir(t_list *list, char **buffer)
{
  t_element	*element_temp;

  element_temp = list->first;
  if (buffer[1] == 0 || (buffer[1][0] == '~' && buffer[1][1] == 0))
    {
      if (list != NULL)
	while (element_temp != NULL)
	  {
	    if (test_same_env(element_temp->env, "HOME"))
	      chdir(element_temp->data);
	    element_temp = element_temp->nxt;
	  }
    }
  else if (check_dir(buffer[1]))
    chdir(buffer[1]);
}