Ejemplo n.º 1
0
int nss_check_group(const char *full_name)
{
	return check_name(full_name, cmd_checkgroup);
}
Ejemplo n.º 2
0
int
cifs_atomic_open(struct inode *inode, struct dentry *direntry,
		 struct file *file, unsigned oflags, umode_t mode,
		 int *opened)
{
	int rc;
	unsigned int xid;
	struct tcon_link *tlink;
	struct cifs_tcon *tcon;
	struct TCP_Server_Info *server;
	struct cifs_fid fid;
	struct cifs_pending_open open;
	__u32 oplock;
	struct cifsFileInfo *file_info;

	/*
	 * Posix open is only called (at lookup time) for file create now. For
	 * opens (rather than creates), because we do not know if it is a file
	 * or directory yet, and current Samba no longer allows us to do posix
	 * open on dirs, we could end up wasting an open call on what turns out
	 * to be a dir. For file opens, we wait to call posix open till
	 * cifs_open.  It could be added to atomic_open in the future but the
	 * performance tradeoff of the extra network request when EISDIR or
	 * EACCES is returned would have to be weighed against the 50% reduction
	 * in network traffic in the other paths.
	 */
	if (!(oflags & O_CREAT)) {
		struct dentry *res;

		/*
		 * Check for hashed negative dentry. We have already revalidated
		 * the dentry and it is fine. No need to perform another lookup.
		 */
		if (!d_unhashed(direntry))
			return -ENOENT;

		res = cifs_lookup(inode, direntry, 0);
		if (IS_ERR(res))
			return PTR_ERR(res);

		return finish_no_open(file, res);
	}

	rc = check_name(direntry);
	if (rc)
		return rc;

	xid = get_xid();

	cifs_dbg(FYI, "parent inode = 0x%p name is: %s and dentry = 0x%p\n",
		 inode, direntry->d_name.name, direntry);

	tlink = cifs_sb_tlink(CIFS_SB(inode->i_sb));
	if (IS_ERR(tlink)) {
		rc = PTR_ERR(tlink);
		goto out_free_xid;
	}

	tcon = tlink_tcon(tlink);
	server = tcon->ses->server;

	if (server->ops->new_lease_key)
		server->ops->new_lease_key(&fid);

	cifs_add_pending_open(&fid, tlink, &open);

	rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
			    &oplock, &fid, opened);

	if (rc) {
		cifs_del_pending_open(&open);
		goto out;
	}

	rc = finish_open(file, direntry, generic_file_open, opened);
	if (rc) {
		if (server->ops->close)
			server->ops->close(xid, tcon, &fid);
		cifs_del_pending_open(&open);
		goto out;
	}

	file_info = cifs_new_fileinfo(&fid, file, tlink, oplock);
	if (file_info == NULL) {
		if (server->ops->close)
			server->ops->close(xid, tcon, &fid);
		cifs_del_pending_open(&open);
		fput(file);
		rc = -ENOMEM;
	}

out:
	cifs_put_tlink(tlink);
out_free_xid:
	free_xid(xid);
	return rc;
}
Ejemplo n.º 3
0
/**
 * scenarios_ok_clicked_cb:
 * @button:
 * @state:
 *
 * Run the scenario manager tool.
 **/
static void
scenario_add_ok_clicked_cb (G_GNUC_UNUSED GtkWidget *button,
			    ScenariosState *state)
{
	data_analysis_output_t  dao;
	WorkbookControl         *wbc;
	gchar                   *name;
	gchar                   *comment;
	GnmValue                   *cell_range;
	GtkWidget               *entry, *comment_view;
	GtkTextBuffer           *buf;
	GtkTextIter             start, end;
	GnmScenario             *sc;
	GnmSheetRange           sr;

	cell_range = gnm_expr_entry_parse_as_value
		(GNM_EXPR_ENTRY (state->base.input_entry), state->base.sheet);

	if (!cell_range || !gnm_sheet_range_from_value (&sr, cell_range)) {
		go_gtk_notice_dialog (GTK_WINDOW (state->base.dialog),
				 GTK_MESSAGE_ERROR,
				 _("Invalid changing cells"));
		gnm_expr_entry_grab_focus (state->base.input_entry, TRUE);
		return;
	}

	if (sr.sheet && sr.sheet != state->base.sheet) {
		go_gtk_notice_dialog (GTK_WINDOW (state->base.dialog),
				 GTK_MESSAGE_ERROR,
				 _("Changing cells should be on the current "
				   "sheet only."));
		gnm_expr_entry_grab_focus (state->base.input_entry, TRUE);
		goto out;
	}
	entry = go_gtk_builder_get_widget (state->base.gui, "name_entry");

	name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
	if (scenario_name_used (state->base.sheet->scenarios, name)) {
	        g_free (name);
		go_gtk_notice_dialog (GTK_WINDOW (state->base.dialog),
				 GTK_MESSAGE_ERROR,
				 _("Scenario name already used"));
		goto out;
	} else if (check_name (name)) {
	        g_free (name);
		go_gtk_notice_dialog (GTK_WINDOW (state->base.dialog),
				 GTK_MESSAGE_ERROR,
				 _("Invalid scenario name"));
		goto out;
	}

	comment_view = go_gtk_builder_get_widget (state->base.gui, "comment_view");
	buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (comment_view));
	gtk_text_buffer_get_start_iter (buf, &start);
	gtk_text_buffer_get_end_iter (buf, &end);
	comment = g_strdup (gtk_text_buffer_get_text (buf, &start, &end,
						      FALSE));

	dao_init_new_sheet (&dao);
	dao.sheet = state->base.sheet;

	wbc = WORKBOOK_CONTROL (state->base.wbcg);

	sc = gnm_sheet_scenario_new (state->base.sheet, name);
	if (comment && comment[0])
		gnm_scenario_set_comment (sc, comment);
	gnm_scenario_add_area (sc, &sr);

	cmd_scenario_add (wbc, sc, state->base.sheet);

	g_free (name);
	g_free (comment);
	gtk_widget_destroy (state->base.dialog);
 out:
	value_release (cell_range);
	return;
}
Ejemplo n.º 4
0
static int check_dir_block(ext2_filsys fs,
			   struct ext2_db_entry *db,
			   void *priv_data)
{
 	struct dx_dir_info	*dx_dir;
#ifdef ENABLE_HTREE
	struct dx_dirblock_info	*dx_db = 0;
#endif 
	struct ext2_dir_entry 	*dirent, *prev;
	ext2_dirhash_t		hash;
	unsigned int		offset = 0;
	const char *		old_op;
	int			dir_modified = 0;
	int			dot_state;
	unsigned int		rec_len;
	blk_t			block_nr = db->blk;
	ext2_ino_t 		ino = db->ino;
	ext2_ino_t 		subdir_parent;
	__u16			links;
	struct check_dir_struct	*cd;
	char 			*buf;
	e2fsck_t		ctx;
	int			problem;
	struct ext2_dx_root_info *root;
	struct ext2_dx_countlimit *limit;
	static dict_t de_dict;
	struct problem_context	pctx;
	int	dups_found = 0;
	int	ret;

	cd = (struct check_dir_struct *) priv_data;
	buf = cd->buf;
	ctx = cd->ctx;

	if (ctx->flags & E2F_FLAG_SIGNAL_MASK || ctx->flags & E2F_FLAG_RESTART)
		return DIRENT_ABORT;

	if (ctx->progress && (ctx->progress)(ctx, 2, cd->count++, cd->max))
		return DIRENT_ABORT;

	if (!(ext2fs_test_inode_bitmap(ctx->inode_used_map, ino)))
		return 0;

	cd->pctx.ino = ino;
	cd->pctx.blk = block_nr;
	cd->pctx.blkcount = db->blockcnt;
	cd->pctx.ino2 = 0;
	cd->pctx.dirent = 0;
	cd->pctx.num = 0;

	if (db->blk == 0) {
		if (allocate_dir_block(ctx, db, buf, &cd->pctx))
			return 0;
		block_nr = db->blk;
	}

	if (db->blockcnt)
		dot_state = 2;
	else
		dot_state = 0;

	if (ctx->dirs_to_hash &&
	    ext2fs_u32_list_test(ctx->dirs_to_hash, ino))
		dups_found++;

#if 0
	printf("In process_dir_block block %lu, #%d, inode %lu\n", block_nr,
	       db->blockcnt, ino);
#endif

	old_op = ehandler_operation(_("reading directory block"));
	cd->pctx.errcode = ext2fs_read_dir_block(fs, block_nr, buf);
	ehandler_operation(0);
	if (cd->pctx.errcode == EXT2_ET_DIR_CORRUPTED)
		cd->pctx.errcode = 0; 
	if (cd->pctx.errcode) {
		if (!fix_problem(ctx, PR_2_READ_DIRBLOCK, &cd->pctx)) {
			ctx->flags |= E2F_FLAG_ABORT;
			return DIRENT_ABORT;
		}
		memset(buf, 0, fs->blocksize);
	}
#ifdef ENABLE_HTREE
	dx_dir = e2fsck_get_dx_dir_info(ctx, ino);
	if (dx_dir && dx_dir->numblocks) {
		if (db->blockcnt >= dx_dir->numblocks) {
			if (fix_problem(ctx, PR_2_UNEXPECTED_HTREE_BLOCK,
					&pctx)) {
				clear_htree(ctx, ino);
				dx_dir->numblocks = 0;
				dx_db = 0;
				goto out_htree;
			}
			fatal_error(ctx, _("Can not continue."));
		}
		dx_db = &dx_dir->dx_block[db->blockcnt];
		dx_db->type = DX_DIRBLOCK_LEAF;
		dx_db->phys = block_nr;
		dx_db->min_hash = ~0;
		dx_db->max_hash = 0;

		dirent = (struct ext2_dir_entry *) buf;
		(void) ext2fs_get_rec_len(fs, dirent, &rec_len);
		limit = (struct ext2_dx_countlimit *) (buf+8);
		if (db->blockcnt == 0) {
			root = (struct ext2_dx_root_info *) (buf + 24);
			dx_db->type = DX_DIRBLOCK_ROOT;
			dx_db->flags |= DX_FLAG_FIRST | DX_FLAG_LAST;
			if ((root->reserved_zero ||
			     root->info_length < 8 ||
			     root->indirect_levels > 1) &&
			    fix_problem(ctx, PR_2_HTREE_BAD_ROOT, &cd->pctx)) {
				clear_htree(ctx, ino);
				dx_dir->numblocks = 0;
				dx_db = 0;
			}
			dx_dir->hashversion = root->hash_version;
			if ((dx_dir->hashversion <= EXT2_HASH_TEA) &&
			    (fs->super->s_flags & EXT2_FLAGS_UNSIGNED_HASH))
				dx_dir->hashversion += 3;
			dx_dir->depth = root->indirect_levels + 1;
		} else if ((dirent->inode == 0) &&
			   (rec_len == fs->blocksize) &&
			   (dirent->name_len == 0) &&
			   (ext2fs_le16_to_cpu(limit->limit) ==
			    ((fs->blocksize-8) /
			     sizeof(struct ext2_dx_entry))))
			dx_db->type = DX_DIRBLOCK_NODE;
	}
out_htree:
#endif 

	dict_init(&de_dict, DICTCOUNT_T_MAX, dict_de_cmp);
	prev = 0;
	do {
		int group;
		ext2_ino_t first_unused_inode;

		problem = 0;
		dirent = (struct ext2_dir_entry *) (buf + offset);
		(void) ext2fs_get_rec_len(fs, dirent, &rec_len);
		cd->pctx.dirent = dirent;
		cd->pctx.num = offset;
		if (((offset + rec_len) > fs->blocksize) ||
		    (rec_len < 12) ||
		    ((rec_len % 4) != 0) ||
		    (((dirent->name_len & (unsigned) 0xFF)+8) > rec_len)) {
			if (fix_problem(ctx, PR_2_DIR_CORRUPTED, &cd->pctx)) {
				salvage_directory(fs, dirent, prev, &offset);
				dir_modified++;
				continue;
			} else
				goto abort_free_dict;
		}
		if ((dirent->name_len & 0xFF) > EXT2_NAME_LEN) {
			if (fix_problem(ctx, PR_2_FILENAME_LONG, &cd->pctx)) {
				dirent->name_len = EXT2_NAME_LEN;
				dir_modified++;
			}
		}

		if (dot_state == 0) {
			if (check_dot(ctx, dirent, ino, &cd->pctx))
				dir_modified++;
		} else if (dot_state == 1) {
			ret = check_dotdot(ctx, dirent, ino, &cd->pctx);
			if (ret < 0)
				goto abort_free_dict;
			if (ret)
				dir_modified++;
		} else if (dirent->inode == ino) {
			problem = PR_2_LINK_DOT;
			if (fix_problem(ctx, PR_2_LINK_DOT, &cd->pctx)) {
				dirent->inode = 0;
				dir_modified++;
				goto next;
			}
		}
		if (!dirent->inode)
			goto next;

		if (((dirent->inode != EXT2_ROOT_INO) &&
		     (dirent->inode < EXT2_FIRST_INODE(fs->super))) ||
		    (dirent->inode > fs->super->s_inodes_count)) {
			problem = PR_2_BAD_INO;
		} else if (ctx->inode_bb_map &&
			   (ext2fs_test_inode_bitmap(ctx->inode_bb_map,
						     dirent->inode))) {
			problem = PR_2_BB_INODE;
		} else if ((dot_state > 1) &&
			   ((dirent->name_len & 0xFF) == 1) &&
			   (dirent->name[0] == '.')) {
			problem = PR_2_DUP_DOT;
		} else if ((dot_state > 1) &&
			   ((dirent->name_len & 0xFF) == 2) &&
			   (dirent->name[0] == '.') &&
			   (dirent->name[1] == '.')) {
			problem = PR_2_DUP_DOT_DOT;
		} else if ((dot_state > 1) &&
			   (dirent->inode == EXT2_ROOT_INO)) {
			problem = PR_2_LINK_ROOT;
		} else if ((dot_state > 1) &&
			   (dirent->name_len & 0xFF) == 0) {
			problem = PR_2_NULL_NAME;
		}

		if (problem) {
			if (fix_problem(ctx, problem, &cd->pctx)) {
				dirent->inode = 0;
				dir_modified++;
				goto next;
			} else {
				ext2fs_unmark_valid(fs);
				if (problem == PR_2_BAD_INO)
					goto next;
			}
		}

		if (ctx->inode_bad_map &&
		    ext2fs_test_inode_bitmap(ctx->inode_bad_map,
					     dirent->inode)) {
			if (e2fsck_process_bad_inode(ctx, ino,
						     dirent->inode,
						     buf + fs->blocksize)) {
				dirent->inode = 0;
				dir_modified++;
				goto next;
			}
			if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
				return DIRENT_ABORT;
		}

		group = ext2fs_group_of_ino(fs, dirent->inode);
		first_unused_inode = group * fs->super->s_inodes_per_group +
					1 + fs->super->s_inodes_per_group -
					fs->group_desc[group].bg_itable_unused;
		cd->pctx.group = group;

		if (fs->group_desc[group].bg_flags & EXT2_BG_INODE_UNINIT) {
			pctx.num = dirent->inode;
			if (fix_problem(ctx, PR_2_INOREF_BG_INO_UNINIT,
					&cd->pctx)){
				fs->group_desc[group].bg_flags &=
					~EXT2_BG_INODE_UNINIT;
				ext2fs_mark_super_dirty(fs);
				ctx->flags |= E2F_FLAG_RESTART_LATER;
			} else {
				ext2fs_unmark_valid(fs);
				if (problem == PR_2_BAD_INO)
					goto next;
			}
		} else if (dirent->inode >= first_unused_inode) {
			pctx.num = dirent->inode;
			if (fix_problem(ctx, PR_2_INOREF_IN_UNUSED, &cd->pctx)){
				fs->group_desc[group].bg_itable_unused = 0;
				ext2fs_mark_super_dirty(fs);
				ctx->flags |= E2F_FLAG_RESTART_LATER;
			} else {
				ext2fs_unmark_valid(fs);
				if (problem == PR_2_BAD_INO)
					goto next;
			}
		}

		if (!(ctx->flags & E2F_FLAG_RESTART_LATER) &&
		    !(ext2fs_test_inode_bitmap(ctx->inode_used_map,
					       dirent->inode)))
			problem = PR_2_UNUSED_INODE;

		if (problem) {
			if (fix_problem(ctx, problem, &cd->pctx)) {
				dirent->inode = 0;
				dir_modified++;
				goto next;
			} else {
				ext2fs_unmark_valid(fs);
				if (problem == PR_2_BAD_INO)
					goto next;
			}
		}

		if (check_name(ctx, dirent, ino, &cd->pctx))
			dir_modified++;

		if (check_filetype(ctx, dirent, ino, &cd->pctx))
			dir_modified++;

#ifdef ENABLE_HTREE
		if (dx_db) {
			ext2fs_dirhash(dx_dir->hashversion, dirent->name,
				       (dirent->name_len & 0xFF),
				       fs->super->s_hash_seed, &hash, 0);
			if (hash < dx_db->min_hash)
				dx_db->min_hash = hash;
			if (hash > dx_db->max_hash)
				dx_db->max_hash = hash;
		}
#endif

		if ((dot_state > 1) &&
		    (ext2fs_test_inode_bitmap(ctx->inode_dir_map,
					      dirent->inode))) {
			if (e2fsck_dir_info_get_parent(ctx, dirent->inode,
						       &subdir_parent)) {
				cd->pctx.ino = dirent->inode;
				fix_problem(ctx, PR_2_NO_DIRINFO, &cd->pctx);
				goto abort_free_dict;
			}
			if (subdir_parent) {
				cd->pctx.ino2 = subdir_parent;
				if (fix_problem(ctx, PR_2_LINK_DIR,
						&cd->pctx)) {
					dirent->inode = 0;
					dir_modified++;
					goto next;
				}
				cd->pctx.ino2 = 0;
			} else {
				(void) e2fsck_dir_info_set_parent(ctx,
						  dirent->inode, ino);
			}
		}

		if (dups_found) {
			;
		} else if (dict_lookup(&de_dict, dirent)) {
			clear_problem_context(&pctx);
			pctx.ino = ino;
			pctx.dirent = dirent;
			fix_problem(ctx, PR_2_REPORT_DUP_DIRENT, &pctx);
			if (!ctx->dirs_to_hash)
				ext2fs_u32_list_create(&ctx->dirs_to_hash, 50);
			if (ctx->dirs_to_hash)
				ext2fs_u32_list_add(ctx->dirs_to_hash, ino);
			dups_found++;
		} else
			dict_alloc_insert(&de_dict, dirent, dirent);

		ext2fs_icount_increment(ctx->inode_count, dirent->inode,
					&links);
		if (links > 1)
			ctx->fs_links_count++;
		ctx->fs_total_count++;
	next:
		prev = dirent;
		if (dir_modified)
			(void) ext2fs_get_rec_len(fs, dirent, &rec_len);
		offset += rec_len;
		dot_state++;
	} while (offset < fs->blocksize);
#if 0
	printf("\n");
#endif
#ifdef ENABLE_HTREE
	if (dx_db) {
#ifdef DX_DEBUG
		printf("db_block %d, type %d, min_hash 0x%0x, max_hash 0x%0x\n",
		       db->blockcnt, dx_db->type,
		       dx_db->min_hash, dx_db->max_hash);
#endif
		cd->pctx.dir = cd->pctx.ino;
		if ((dx_db->type == DX_DIRBLOCK_ROOT) ||
		    (dx_db->type == DX_DIRBLOCK_NODE))
			parse_int_node(fs, db, cd, dx_dir, buf);
	}
#endif 
	if (offset != fs->blocksize) {
		cd->pctx.num = rec_len - fs->blocksize + offset;
		if (fix_problem(ctx, PR_2_FINAL_RECLEN, &cd->pctx)) {
			dirent->rec_len = cd->pctx.num;
			dir_modified++;
		}
	}
	if (dir_modified) {
		cd->pctx.errcode = ext2fs_write_dir_block(fs, block_nr, buf);
		if (cd->pctx.errcode) {
			if (!fix_problem(ctx, PR_2_WRITE_DIRBLOCK,
					 &cd->pctx))
				goto abort_free_dict;
		}
		ext2fs_mark_changed(fs);
	}
	dict_free_nodes(&de_dict);
	return 0;
abort_free_dict:
	ctx->flags |= E2F_FLAG_ABORT;
	dict_free_nodes(&de_dict);
	return DIRENT_ABORT;
}
Ejemplo n.º 5
0
static grub_err_t 
recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)),
	   struct grub_net_buff *nb,
	   void *data_)
{
  struct dns_header *head;
  struct recv_data *data = data_;
  int i, j;
  grub_uint8_t *ptr, *reparse_ptr;
  int redirect_cnt = 0;
  char *redirect_save = NULL;
  grub_uint32_t ttl_all = ~0U;

  head = (struct dns_header *) nb->data;
  ptr = (grub_uint8_t *) (head + 1);
  if (ptr >= nb->tail)
    {
      grub_netbuff_free (nb);
      return GRUB_ERR_NONE;
    }
  
  if (head->id != data->id)
    {
      grub_netbuff_free (nb);
      return GRUB_ERR_NONE;
    }
  if (!(head->flags & FLAGS_RESPONSE) || (head->flags & FLAGS_OPCODE))
    {
      grub_netbuff_free (nb);
      return GRUB_ERR_NONE;
    }
  if (head->ra_z_r_code & ERRCODE_MASK)
    {
      data->dns_err = 1;
      grub_netbuff_free (nb);
      return GRUB_ERR_NONE;
    }
  for (i = 0; i < grub_cpu_to_be16 (head->qdcount); i++)
    {
      if (ptr >= nb->tail)
	{
	  grub_netbuff_free (nb);
	  return GRUB_ERR_NONE;
	}
      while (ptr < nb->tail && !((*ptr & 0xc0) || *ptr == 0))
	ptr += *ptr + 1;
      if (ptr < nb->tail && (*ptr & 0xc0))
	ptr++;
      ptr++;
      ptr += 4;
    }
  *data->addresses = grub_malloc (sizeof ((*data->addresses)[0])
				 * grub_cpu_to_be16 (head->ancount));
  if (!*data->addresses)
    {
      grub_errno = GRUB_ERR_NONE;
      grub_netbuff_free (nb);
      return GRUB_ERR_NONE;
    }
  reparse_ptr = ptr;
 reparse:
  for (i = 0, ptr = reparse_ptr; i < grub_cpu_to_be16 (head->ancount); i++)
    {
      int ignored = 0;
      grub_uint8_t class;
      grub_uint32_t ttl = 0;
      grub_uint16_t length;
      if (ptr >= nb->tail)
	{
	  if (!*data->naddresses)
	    grub_free (*data->addresses);
	  return GRUB_ERR_NONE;
	}
      ignored = !check_name (ptr, nb->data, nb->tail, data->name);
      while (ptr < nb->tail && !((*ptr & 0xc0) || *ptr == 0))
	ptr += *ptr + 1;
      if (ptr < nb->tail && (*ptr & 0xc0))
	ptr++;
      ptr++;
      if (ptr + 10 >= nb->tail)
	{
	  if (!*data->naddresses)
	    grub_free (*data->addresses);
	  grub_netbuff_free (nb);
	  return GRUB_ERR_NONE;
	}
      if (*ptr++ != 0)
	ignored = 1;
      class = *ptr++;
      if (*ptr++ != 0)
	ignored = 1;
      if (*ptr++ != 1)
	ignored = 1;
      for (j = 0; j < 4; j++)
	{
	  ttl <<= 8;
	  ttl |= *ptr++;
	}
      length = *ptr++ << 8;
      length |= *ptr++;
      if (ptr + length > nb->tail)
	{
	  if (!*data->naddresses)
	    grub_free (*data->addresses);
	  grub_netbuff_free (nb);
	  return GRUB_ERR_NONE;
	}
      if (!ignored)
	{
	  if (ttl_all > ttl)
	    ttl_all = ttl;
	  switch (class)
	    {
	    case DNS_CLASS_A:
	      if (length != 4)
		break;
	      (*data->addresses)[*data->naddresses].type
		= GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
	      grub_memcpy (&(*data->addresses)[*data->naddresses].ipv4,
			   ptr, 4);
	      (*data->naddresses)++;
	      data->stop = 1;
	      break;
	    case DNS_CLASS_AAAA:
	      if (length != 16)
		break;
	      (*data->addresses)[*data->naddresses].type
		= GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6;
	      grub_memcpy (&(*data->addresses)[*data->naddresses].ipv6,
			   ptr, 16);
	      (*data->naddresses)++;
	      data->stop = 1;
	      break;
	    case DNS_CLASS_CNAME:
	      if (!(redirect_cnt & (redirect_cnt - 1)))
		{
		  grub_free (redirect_save);
		  redirect_save = data->name;
		}
	      else
		grub_free (data->name);
	      redirect_cnt++;
	      data->name = get_name (ptr, nb->data, nb->tail);
	      if (!data->name)
		{
		  data->dns_err = 1;
		  grub_errno = 0;
		  return GRUB_ERR_NONE;
		}
	      grub_dprintf ("dns", "CNAME %s\n", data->name);
	      if (grub_strcmp (redirect_save, data->name) == 0)
		{
		  data->dns_err = 1;
		  grub_free (redirect_save);
		  return GRUB_ERR_NONE;
		}
	      goto reparse;
	    }
	}
      ptr += length;
    }
  if (ttl_all && *data->naddresses && data->cache)
    {
      int h;
      grub_dprintf ("dns", "caching for %d seconds\n", ttl_all);
      h = hash (data->oname);
      grub_free (dns_cache[h].name);
      dns_cache[h].name = 0;
      grub_free (dns_cache[h].addresses);
      dns_cache[h].addresses = 0;
      dns_cache[h].name = grub_strdup (data->oname);
      dns_cache[h].naddresses = *data->naddresses;
      dns_cache[h].addresses = grub_malloc (*data->naddresses
					    * sizeof (dns_cache[h].addresses[0]));
      dns_cache[h].limit_time = grub_get_time_ms () + 1000 * ttl_all;
      if (!dns_cache[h].addresses || !dns_cache[h].name)
	{
	  grub_free (dns_cache[h].name);
	  dns_cache[h].name = 0;
	  grub_free (dns_cache[h].addresses);
	  dns_cache[h].addresses = 0;
	}
      grub_memcpy (dns_cache[h].addresses, *data->addresses,
		   *data->naddresses
		   * sizeof (dns_cache[h].addresses[0]));
    }
  grub_netbuff_free (nb);
  grub_free (redirect_save);
  return GRUB_ERR_NONE;
}
Ejemplo n.º 6
0
/**
 * Go through all the steps to validate a filename.
 *
 * @param ctx		talloc_ctx to allocate memory with.
 * @param conn		connection struct for vfs calls.
 * @param dfs_path	Whether this path requires dfs resolution.
 * @param name_in	The unconverted name.
 * @param ucf_flags	flags to pass through to unix_convert().
 *			UCF_ALWAYS_ALLOW_WCARD_LCOMP will be OR'd in if
 *			p_cont_wcard != NULL and is true and
 *			UCF_COND_ALLOW_WCARD_LCOMP.
 * @param p_cont_wcard	If not NULL, will be set to true if the dfs path
 *			resolution detects a wildcard.
 * @param pp_smb_fname	The final converted name will be allocated if the
 *			return is NT_STATUS_OK.
 *
 * @return NT_STATUS_OK if all operations completed succesfully, appropriate
 * 	   error otherwise.
 */
NTSTATUS filename_convert(TALLOC_CTX *ctx,
				connection_struct *conn,
				bool dfs_path,
				const char *name_in,
				uint32_t ucf_flags,
				bool *ppath_contains_wcard,
				struct smb_filename **pp_smb_fname)
{
	NTSTATUS status;
	bool allow_wcards = (ucf_flags & (UCF_COND_ALLOW_WCARD_LCOMP|UCF_ALWAYS_ALLOW_WCARD_LCOMP));
	char *fname = NULL;

	*pp_smb_fname = NULL;

	status = resolve_dfspath_wcard(ctx, conn,
				dfs_path,
				name_in,
				allow_wcards,
				&fname,
				ppath_contains_wcard);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(10,("filename_convert: resolve_dfspath failed "
			"for name %s with %s\n",
			name_in,
			nt_errstr(status) ));
		return status;
	}

	if (is_fake_file_path(name_in)) {
		SMB_STRUCT_STAT st;
		ZERO_STRUCT(st);
		st.st_ex_nlink = 1;
		status = create_synthetic_smb_fname_split(ctx,
							  name_in,
							  &st,
							  pp_smb_fname);
		return status;
	}

	/*
	 * If the caller conditionally allows wildcard lookups, only add the
	 * always allow if the path actually does contain a wildcard.
	 */
	if (ucf_flags & UCF_COND_ALLOW_WCARD_LCOMP &&
	    ppath_contains_wcard != NULL && *ppath_contains_wcard) {
		ucf_flags |= UCF_ALWAYS_ALLOW_WCARD_LCOMP;
	}

	status = unix_convert(ctx, conn, fname, pp_smb_fname, ucf_flags);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(10,("filename_convert: unix_convert failed "
			"for name %s with %s\n",
			fname,
			nt_errstr(status) ));
		return status;
	}

	if ((ucf_flags & UCF_UNIX_NAME_LOOKUP) &&
			VALID_STAT((*pp_smb_fname)->st) &&
			S_ISLNK((*pp_smb_fname)->st.st_ex_mode)) {
		return check_veto_path(conn, (*pp_smb_fname)->base_name);
	}

	status = check_name(conn, (*pp_smb_fname)->base_name);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(3,("filename_convert: check_name failed "
			"for name %s with %s\n",
			smb_fname_str_dbg(*pp_smb_fname),
			nt_errstr(status) ));
		TALLOC_FREE(*pp_smb_fname);
		return status;
	}

	return status;
}
Ejemplo n.º 7
0
int
lex(void)
{	int c;
again:
	c = Getchar();
	yytext[0] = (char) c;
	yytext[1] = '\0';
	switch (c) {
	case EOF:
		return c;
	case '\n':		/* newline */
		lineno++;
		/* make most semi-colons optional */
		if (implied_semis
		&&  context
		&&  in_seq
		&&  par_cnt == 0
		&&  follows_token(last_token))
		{	if (0)
			{	printf("insert ; line %d, last_token %d in_seq %d\n",
				 lineno-1, last_token, in_seq);
			}
			ValToken(1, SEMI);
		}
		/* else fall thru */
	case '\r':		/* carriage return */
		goto again;

	case  ' ': case '\t': case '\f':	/* white space */
		goto again;

	case '#':		/* preprocessor directive */
		if (in_comment) goto again;
		if (pp_mode)
		{	last_token = PREPROC;
			return pre_proc();
		}
		do_directive(c);
		goto again;

	case '\"':
		getword(c, notquote);
		if (Getchar() != '\"')
			fatal("string not terminated", yytext);
		strcat(yytext, "\"");
		SymToken(lookup(yytext), STRING)

	case '$':
		getword('\"', notdollar);
		if (Getchar() != '$')
			fatal("ltl definition not terminated", yytext);
		strcat(yytext, "\""); 
		SymToken(lookup(yytext), STRING)

	case '\'':	/* new 3.0.9 */
		c = Getchar();
		if (c == '\\')
		{	c = Getchar();
			if (c == 'n') c = '\n';
			else if (c == 'r') c = '\r';
			else if (c == 't') c = '\t';
			else if (c == 'f') c = '\f';
		}
		if (Getchar() != '\'' && !in_comment)
			fatal("character quote missing: %s", yytext);
		ValToken(c, CONST)

	default:
		break;
	}

	if (isdigit_(c))
	{	long int nr;
		getword(c, isdigit_);
		errno = 0;
		nr = strtol(yytext, NULL, 10);
		if (errno != 0)
		{	fprintf(stderr, "spin: value out of range: '%s' read as '%d'\n",
				yytext, (int) nr);
		}
		ValToken((int)nr, CONST)
	}

	if (isalpha_(c) || c == '_')
	{	getword(c, isalnum_);
		if (!in_comment)
		{	c = check_name(yytext);
			if (c)
			{	last_token = c;
				return c;
			}
			/* else fall through */
		}
		goto again;
	}

	if (ltl_mode)
	{	switch (c) {
		case '-': c = follow('>', IMPLIES,    '-'); break;
		case '[': c = follow(']', ALWAYS,     '['); break;
		case '<': c = follow('>', EVENTUALLY, '<');
			  if (c == '<')
			  {	c = Getchar();
				if (c == '-')
				{	c = follow('>', EQUIV, '-');
					if (c == '-')
					{	Ungetch(c);
						c = '<';
					}
				} else
				{	Ungetch(c);
					c = '<';
			  }	}
		default:  break;
	}	}

	switch (c) {
	case '/': c = follow('*', 0, '/');
		  if (!c) { in_comment = 1; goto again; }
		  break;
	case '*': c = follow('/', 0, '*');
		  if (!c) { in_comment = 0; goto again; }
		  break;
	case ':': c = follow(':', SEP, ':'); break;
	case '-': c = follow('>', ARROW, follow('-', DECR, '-')); break;
	case '+': c = follow('+', INCR, '+'); break;
	case '<': c = follow('<', LSHIFT, follow('=', LE, LT)); break;
	case '>': c = follow('>', RSHIFT, follow('=', GE, GT)); break;
	case '=': c = follow('=', EQ, ASGN); break;
	case '!': c = follow('=', NE, follow('!', O_SND, SND)); break;
	case '?': c = follow('?', R_RCV, RCV); break;
	case '&': c = follow('&', AND, '&'); break;
	case '|': c = follow('|', OR, '|'); break;
	case ';': c = SEMI; break;
	case '.': c = follow('.', DOTDOT, '.'); break;
	case '{': scope_seq[scope_level++]++; set_cur_scope(); break;
	case '}': scope_level--; set_cur_scope(); break;
	default : break;
	}
	ValToken(0, c)
}
Ejemplo n.º 8
0
static int check_dir_block(ext2_filsys fs,
                           struct ext2_db_entry *db,
                           void *priv_data)
{
    struct dir_info		*subdir, *dir;
    struct ext2_dir_entry 	*dirent;
    int			offset = 0;
    int			dir_modified = 0;
    int			dot_state;
    blk_t			block_nr = db->blk;
    ext2_ino_t 		ino = db->ino;
    __u16			links;
    struct check_dir_struct	*cd;
    char 			*buf;
    e2fsck_t		ctx;
    int			problem;

    cd = (struct check_dir_struct *) priv_data;
    buf = cd->buf;
    ctx = cd->ctx;

    if (ctx->progress)
        if ((ctx->progress)(ctx, 2, cd->count++, cd->max))
            return DIRENT_ABORT;

    /*
     * Make sure the inode is still in use (could have been
     * deleted in the duplicate/bad blocks pass.
     */
    if (!(ext2fs_test_inode_bitmap(ctx->inode_used_map, ino)))
        return 0;

    cd->pctx.ino = ino;
    cd->pctx.blk = block_nr;
    cd->pctx.blkcount = db->blockcnt;
    cd->pctx.ino2 = 0;
    cd->pctx.dirent = 0;
    cd->pctx.num = 0;

    if (db->blk == 0) {
        if (allocate_dir_block(ctx, db, buf, &cd->pctx))
            return 0;
        block_nr = db->blk;
    }

    if (db->blockcnt)
        dot_state = 2;
    else
        dot_state = 0;

#if 0
    printf("In process_dir_block block %lu, #%d, inode %lu\n", block_nr,
           db->blockcnt, ino);
#endif

    cd->pctx.errcode = ext2fs_read_dir_block(fs, block_nr, buf);
    if (cd->pctx.errcode == EXT2_ET_DIR_CORRUPTED)
        cd->pctx.errcode = 0; /* We'll handle this ourselves */
    if (cd->pctx.errcode) {
        if (!fix_problem(ctx, PR_2_READ_DIRBLOCK, &cd->pctx)) {
            ctx->flags |= E2F_FLAG_ABORT;
            return DIRENT_ABORT;
        }
        memset(buf, 0, fs->blocksize);
    }

    do {
        dot_state++;
        problem = 0;
        dirent = (struct ext2_dir_entry *) (buf + offset);
        cd->pctx.dirent = dirent;
        cd->pctx.num = offset;
        if (((offset + dirent->rec_len) > fs->blocksize) ||
                (dirent->rec_len < 12) ||
                ((dirent->rec_len % 4) != 0) ||
                (((dirent->name_len & 0xFF)+8) > dirent->rec_len)) {
            if (fix_problem(ctx, PR_2_DIR_CORRUPTED, &cd->pctx)) {
                dirent->rec_len = fs->blocksize - offset;
                dirent->name_len = 0;
                dirent->inode = 0;
                dir_modified++;
            } else
                return DIRENT_ABORT;
        }
        if ((dirent->name_len & 0xFF) > EXT2_NAME_LEN) {
            if (fix_problem(ctx, PR_2_FILENAME_LONG, &cd->pctx)) {
                dirent->name_len = EXT2_NAME_LEN;
                dir_modified++;
            }
        }

        if (dot_state == 1) {
            if (check_dot(ctx, dirent, ino, &cd->pctx))
                dir_modified++;
        } else if (dot_state == 2) {
            dir = e2fsck_get_dir_info(ctx, ino);
            if (!dir) {
                fix_problem(ctx, PR_2_NO_DIRINFO, &cd->pctx);
                ctx->flags |= E2F_FLAG_ABORT;
                return DIRENT_ABORT;
            }
            if (check_dotdot(ctx, dirent, dir, &cd->pctx))
                dir_modified++;
        } else if (dirent->inode == ino) {
            problem = PR_2_LINK_DOT;
            if (fix_problem(ctx, PR_2_LINK_DOT, &cd->pctx)) {
                dirent->inode = 0;
                dir_modified++;
                goto next;
            }
        }
        if (!dirent->inode)
            goto next;

        /*
         * Make sure the inode listed is a legal one.
         */
        if (((dirent->inode != EXT2_ROOT_INO) &&
                (dirent->inode < EXT2_FIRST_INODE(fs->super))) ||
                (dirent->inode > fs->super->s_inodes_count)) {
            problem = PR_2_BAD_INO;
        } else if (!(ext2fs_test_inode_bitmap(ctx->inode_used_map,
                                              dirent->inode))) {
            /*
             * If the inode is unused, offer to clear it.
             */
            problem = PR_2_UNUSED_INODE;
        } else if (ctx->inode_bb_map &&
                   (ext2fs_test_inode_bitmap(ctx->inode_bb_map,
                                             dirent->inode))) {
            /*
             * If the inode is in a bad block, offer to
             * clear it.
             */
            problem = PR_2_BB_INODE;
        } else if ((dot_state > 2) &&
                   ((dirent->name_len & 0xFF) == 1) &&
                   (dirent->name[0] == '.')) {
            /*
             * If there's a '.' entry in anything other
             * than the first directory entry, it's a
             * duplicate entry that should be removed.
             */
            problem = PR_2_DUP_DOT;
        } else if ((dot_state > 2) &&
                   ((dirent->name_len & 0xFF) == 2) &&
                   (dirent->name[0] == '.') &&
                   (dirent->name[1] == '.')) {
            /*
             * If there's a '..' entry in anything other
             * than the second directory entry, it's a
             * duplicate entry that should be removed.
             */
            problem = PR_2_DUP_DOT_DOT;
        } else if ((dot_state > 2) &&
                   (dirent->inode == EXT2_ROOT_INO)) {
            /*
             * Don't allow links to the root directory.
             * We check this specially to make sure we
             * catch this error case even if the root
             * directory hasn't been created yet.
             */
            problem = PR_2_LINK_ROOT;
        } else if ((dot_state > 2) &&
                   (dirent->name_len & 0xFF) == 0) {
            /*
             * Don't allow zero-length directory names.
             */
            problem = PR_2_NULL_NAME;
        }

        if (problem) {
            if (fix_problem(ctx, problem, &cd->pctx)) {
                dirent->inode = 0;
                dir_modified++;
                goto next;
            } else {
                ext2fs_unmark_valid(fs);
                if (problem == PR_2_BAD_INO)
                    goto next;
            }
        }

        /*
         * If the inode was marked as having bad fields in
         * pass1, process it and offer to fix/clear it.
         * (We wait until now so that we can display the
         * pathname to the user.)
         */
        if (ctx->inode_bad_map &&
                ext2fs_test_inode_bitmap(ctx->inode_bad_map,
                                         dirent->inode)) {
            if (e2fsck_process_bad_inode(ctx, ino,
                                         dirent->inode)) {
                dirent->inode = 0;
                dir_modified++;
                goto next;
            }
            if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
                return DIRENT_ABORT;
        }

        if (check_name(ctx, dirent, ino, &cd->pctx))
            dir_modified++;

        if (check_filetype(ctx, dirent, ino, &cd->pctx))
            dir_modified++;

        /*
         * If this is a directory, then mark its parent in its
         * dir_info structure.  If the parent field is already
         * filled in, then this directory has more than one
         * hard link.  We assume the first link is correct,
         * and ask the user if he/she wants to clear this one.
         */
        if ((dot_state > 2) &&
                (ext2fs_test_inode_bitmap(ctx->inode_dir_map,
                                          dirent->inode))) {
            subdir = e2fsck_get_dir_info(ctx, dirent->inode);
            if (!subdir) {
                cd->pctx.ino = dirent->inode;
                fix_problem(ctx, PR_2_NO_DIRINFO, &cd->pctx);
                ctx->flags |= E2F_FLAG_ABORT;
                return DIRENT_ABORT;
            }
            if (subdir->parent) {
                cd->pctx.ino2 = subdir->parent;
                if (fix_problem(ctx, PR_2_LINK_DIR,
                                &cd->pctx)) {
                    dirent->inode = 0;
                    dir_modified++;
                    goto next;
                }
                cd->pctx.ino2 = 0;
            } else
                subdir->parent = ino;
        }

        ext2fs_icount_increment(ctx->inode_count, dirent->inode,
                                &links);
        if (links > 1)
            ctx->fs_links_count++;
        ctx->fs_total_count++;
next:
        offset += dirent->rec_len;
    } while (offset < fs->blocksize);
#if 0
    printf("\n");
#endif
    if (offset != fs->blocksize) {
        cd->pctx.num = dirent->rec_len - fs->blocksize + offset;
        if (fix_problem(ctx, PR_2_FINAL_RECLEN, &cd->pctx)) {
            dirent->rec_len = cd->pctx.num;
            dir_modified++;
        }
    }
    if (dir_modified) {
        cd->pctx.errcode = ext2fs_write_dir_block(fs, block_nr, buf);
        if (cd->pctx.errcode) {
            if (!fix_problem(ctx, PR_2_WRITE_DIRBLOCK,
                             &cd->pctx)) {
                ctx->flags |= E2F_FLAG_ABORT;
                return DIRENT_ABORT;
            }
        }
        ext2fs_mark_changed(fs);
    }
    return 0;
}
Ejemplo n.º 9
0
int check_basename(char *name)
{
	check_name(name, &logbasename);
	return 0;
}
Ejemplo n.º 10
0
int
main(int argc, char **argv)
{
    krb5_ccache ccinitial, ccu1, ccu2;
    krb5_principal princ1, princ2, princ3;
    const char *collection_name, *typename;
    char *initial_primary_name, *unique1_name, *unique2_name;

    /*
     * Get the collection name from the command line.  This is a ccache name
     * with collection semantics, like DIR:/path/to/directory.  This test
     * program assumes that the collection is empty to start with.
     */
    assert(argc == 2);
    collection_name = argv[1];

    /*
     * Set the default ccache for the context to be the collection name, so the
     * library can find the collection.
     */
    check(krb5_init_context(&ctx));
    check(krb5_cc_set_default_name(ctx, collection_name));

    /*
     * Resolve the collection name.  Since the collection is empty, this should
     * generate a subsidiary name of an uninitialized cache.  Getting the name
     * of the resulting cache should give us the subsidiary name, not the
     * collection name.  This resulting subsidiary name should be consistent if
     * we resolve the collection name again, and the collection should still be
     * empty since we haven't initialized the cache.
     */
    check(krb5_cc_resolve(ctx, collection_name, &ccinitial));
    check(krb5_cc_get_full_name(ctx, ccinitial, &initial_primary_name));
    assert(strcmp(initial_primary_name, collection_name) != 0);
    check_primary_name(collection_name, initial_primary_name);
    check_collection(NULL, 0);
    check_princ(collection_name, NULL);
    check_princ(initial_primary_name, NULL);

    /*
     * Before initializing the primary ccache, generate and initialize two
     * unique caches of the collection's type.  Check that the cache names
     * resolve to the generated caches and appear in the collection.  (They
     * might appear before being initialized; that's not currently considered
     * important).  The primary cache for the collection should remain as the
     * unitialized cache from the previous step.
     */
    typename = krb5_cc_get_type(ctx, ccinitial);
    check(krb5_cc_new_unique(ctx, typename, NULL, &ccu1));
    check(krb5_cc_get_full_name(ctx, ccu1, &unique1_name));
    check(krb5_parse_name(ctx, "princ1@X", &princ1));
    check(krb5_cc_initialize(ctx, ccu1, princ1));
    check_princ(unique1_name, princ1);
    check_match(princ1, unique1_name);
    check_collection(NULL, 1, unique1_name);
    check(krb5_cc_new_unique(ctx, typename, NULL, &ccu2));
    check(krb5_cc_get_full_name(ctx, ccu2, &unique2_name));
    check(krb5_parse_name(ctx, "princ2@X", &princ2));
    check(krb5_cc_initialize(ctx, ccu2, princ2));
    check_princ(unique2_name, princ2);
    check_match(princ1, unique1_name);
    check_match(princ2, unique2_name);
    check_collection(NULL, 2, unique1_name, unique2_name);
    assert(strcmp(unique1_name, initial_primary_name) != 0);
    assert(strcmp(unique1_name, collection_name) != 0);
    assert(strcmp(unique2_name, initial_primary_name) != 0);
    assert(strcmp(unique2_name, collection_name) != 0);
    assert(strcmp(unique2_name, unique1_name) != 0);
    check_primary_name(collection_name, initial_primary_name);

    /*
     * Initialize the initial primary cache.  Make sure it didn't change names,
     * that the previously retrieved name and the collection name both resolve
     * to the initialized cache, and that it now appears first in the
     * collection.
     */
    check(krb5_parse_name(ctx, "princ3@X", &princ3));
    check(krb5_cc_initialize(ctx, ccinitial, princ3));
    check_name(ccinitial, initial_primary_name);
    check_princ(initial_primary_name, princ3);
    check_princ(collection_name, princ3);
    check_match(princ3, initial_primary_name);
    check_collection(initial_primary_name, 2, unique1_name, unique2_name);

    /*
     * Switch the primary cache to each cache we have open.  One each switch,
     * check the primary name, check that the collection resolves to the
     * expected cache, and check that the new primary name appears first in the
     * collection.
     */
    check(krb5_cc_switch(ctx, ccu1));
    check_primary_name(collection_name, unique1_name);
    check_princ(collection_name, princ1);
    check_collection(unique1_name, 2, initial_primary_name, unique2_name);
    check(krb5_cc_switch(ctx, ccu2));
    check_primary_name(collection_name, unique2_name);
    check_princ(collection_name, princ2);
    check_collection(unique2_name, 2, initial_primary_name, unique1_name);
    check(krb5_cc_switch(ctx, ccinitial));
    check_primary_name(collection_name, initial_primary_name);
    check_princ(collection_name, princ3);
    check_collection(initial_primary_name, 2, unique1_name, unique2_name);

    /*
     * Temporarily set the context default ccache to a subsidiary name, and
     * check that iterating over the collection yields that subsidiary cache
     * and no others.
     */
    check(krb5_cc_set_default_name(ctx, unique1_name));
    check_collection(unique1_name, 0);
    check(krb5_cc_set_default_name(ctx, collection_name));

    /*
     * Destroy the primary cache.  Make sure this causes both the initial
     * primary name and the collection name to resolve to an uninitialized
     * cache.  Make sure the primary name doesn't change and doesn't appear in
     * the collection any more.
     */
    check(krb5_cc_destroy(ctx, ccinitial));
    check_princ(initial_primary_name, NULL);
    check_princ(collection_name, NULL);
    check_primary_name(collection_name, initial_primary_name);
    check_match(princ1, unique1_name);
    check_match(princ2, unique2_name);
    check_match(princ3, NULL);
    check_collection(NULL, 2, unique1_name, unique2_name);

    /*
     * Switch to the first unique cache after destroying the primary cache.
     * Check that the collection name resolves to this cache and that the new
     * primary name appears first in the collection.
     */
    check(krb5_cc_switch(ctx, ccu1));
    check_primary_name(collection_name, unique1_name);
    check_princ(collection_name, princ1);
    check_collection(unique1_name, 1, unique2_name);

    /*
     * Destroy the second unique cache (which is not the current primary),
     * check that it is on longer initialized, and check that it no longer
     * appears in the collection.  Check that destroying the non-primary cache
     * doesn't affect the primary name.
     */
    check(krb5_cc_destroy(ctx, ccu2));
    check_princ(unique2_name, NULL);
    check_match(princ2, NULL);
    check_collection(unique1_name, 0);
    check_primary_name(collection_name, unique1_name);
    check_match(princ1, unique1_name);
    check_princ(collection_name, princ1);

    /*
     * Destroy the first unique cache.  Check that the collection is empty and
     * still has the same primary name.
     */
    check(krb5_cc_destroy(ctx, ccu1));
    check_princ(unique1_name, NULL);
    check_princ(collection_name, NULL);
    check_primary_name(collection_name, unique1_name);
    check_match(princ1, NULL);
    check_collection(NULL, 0);

    krb5_free_string(ctx, initial_primary_name);
    krb5_free_string(ctx, unique1_name);
    krb5_free_string(ctx, unique2_name);
    krb5_free_principal(ctx, princ1);
    krb5_free_principal(ctx, princ2);
    krb5_free_principal(ctx, princ3);
    krb5_free_context(ctx);
    return 0;
}
Ejemplo n.º 11
0
/*创建新的目录项*/
int make_file(int inode, char* name, int type)
{
	char original_name_path[30];
	int original_inode = inode_num;//记录当前的inode

	strcpy(original_name_path, name);
	if (eat_path(name) == -1) {
		if (type == File)
			printf("touch: cannot touch‘%s’: No such file or directory\n", original_name_path);
		if (type == Directory)
			printf("mkdir: cannot create directory ‘%s’: No such file or directory\n", original_name_path);
		return -1;
	}

	int new_node;
	int blk_need = 1;//本目录需要增加磁盘块则blk_need=2
	int t;
	Inode temp;

	/*读取当前目录的Inode*/
	fseek(Disk, InodeBeg + sizeof(Inode)*inode, SEEK_SET);
	fread(&temp, sizeof(Inode), 1, Disk);

	if (temp.access[1] == 0) { //当前目录不允许写
		if (type == Directory)
			printf("mkdir: cannot create directory ‘%s’: Permission denied\n", original_name_path);
		if (type == File)
			printf("touch: cannot touch ‘%s’: Permission denied\n", original_name_path);
		close_dir(inode_num);
		inode_num = original_inode;
		open_dir(inode_num);
		return -1;
	}
	if (dir_num>MaxDirNum) {//超过了目录文件能包含的最大目录项
		if (type == Directory)
			printf("mkdir: cannot create directory '%s' : Directory full\n", original_name_path);
		if (type == File)
			printf("touch: cannot create file '%s' : Directory full\n", original_name_path);
		close_dir(inode_num);
		inode_num = original_inode;
		open_dir(inode_num);
		return -1;
	}

	if (check_name(inode, name) != -1) {//防止重命名
		if (type == Directory)
			printf("mkdir: cannnot create directory '%s' : Directory exist\n", original_name_path);
		if (type == File)
			printf("touch: cannot create file '%s' : File exist\n", original_name_path);
		close_dir(inode_num);
		inode_num = original_inode;
		open_dir(inode_num);
		return -1;
	}

	if (dir_num / DirPerBlk != (dir_num + 1) / DirPerBlk) {//本目录也要增加磁盘块
		blk_need = 2;
	}

	//	printf("blk_used:%d\n",super_blk.blk_used);
	if (super_blk.blk_used + blk_need>BlkNum) {
		if (type == Directory)
			printf("mkdir: cannot create directory '%s' :Block used up\n", original_name_path);
		if (type == File)
			printf("touch: cannot create file '%s' : Block used up\n", original_name_path);
		close_dir(inode_num);
		inode_num = original_inode;
		open_dir(inode_num);
		return -1;
	}

	if (blk_need == 2) {//本目录需要增加磁盘块
		t = curr_inode.blk_num++;
		curr_inode.blk_identifier[t] = get_blk();
	}

	/*申请inode*/
	new_node = apply_inode();

	if (new_node == -1) {
		if (type == Directory)
			printf("mkdir: cannot create directory '%s' :Inode used up\n", original_name_path);
		if (type == File)
			printf("touch: cannot create file '%s' : Inode used up\n", original_name_path);
		close_dir(inode_num);
		inode_num = original_inode;
		open_dir(inode_num);
		return -1;
	}

	if (type == Directory) {
		/*初始化新建目录的inode*/
		init_dir_inode(new_node, inode);
	}
	else if (type == File) {
		/*初始化新建文件的inode*/
		init_file_inode(new_node);
	}

	strcpy(dir_table[dir_num].name, name);
	dir_table[dir_num++].inode_num = new_node;

	close_dir(inode_num);
	inode_num = original_inode;
	open_dir(inode_num);
	return 0;
}
Ejemplo n.º 12
0
/*修改文件读写权限*/
int change_mode(char* parameter, char* name)
{
	int inode;
	Inode temp;
	char original_name_path[30];
	int original_inode = inode_num;//记录当前的inode

	strcpy(original_name_path, name);
	if (eat_path(name) == -1) {
		printf("chmod: cannot access‘%s’: No such file or directory\n", original_name_path);
		return -1;
	}
	inode = check_name(inode_num, name);
	if (inode == -1) {
		printf("stat: cannot stat '%s': No such file or directory\n", original_name_path);
		close_dir(inode_num);
		inode_num = original_inode;
		open_dir(inode_num);
		return -1;
	}

	fseek(Disk, InodeBeg + sizeof(Inode)*inode, SEEK_SET);
	fread(&temp, sizeof(Inode), 1, Disk);

	if (strcmp(parameter, "+r") == 0) {
		temp.access[0][user_num] = 1;
		temp.i_ctime = time(NULL);
	}
	else if (strcmp(parameter, "-r") == 0) {
		temp.access[0][user_num] = 0;
		temp.i_ctime = time(NULL);
	}
	else if (strcmp(parameter, "+w") == 0) {
		temp.access[1][user_num] = 1;
		temp.i_ctime = time(NULL);
	}
	else if (strcmp(parameter, "-w") == 0) {
		temp.access[1][user_num] = 0;
		temp.i_ctime = time(NULL);
	}
	else if (strcmp(parameter, "+x") == 0) {
		temp.access[2][user_num] = 1;
		temp.i_ctime = time(NULL);
	}
	else if (strcmp(parameter, "-x") == 0) {
		temp.access[2][user_num] = 0;
		temp.i_ctime = time(NULL);
	}
	else {
		printf("chmod: invalid option -- '%s'\n", parameter);
	}

	/*将修改后的Inode写回*/
	fseek(Disk, InodeBeg + sizeof(Inode)*inode, SEEK_SET);
	fwrite(&temp, sizeof(Inode), 1, Disk);

	close_dir(inode_num);
	inode_num = original_inode;
	open_dir(inode_num);
	return 0;
}
Ejemplo n.º 13
0
int file_move(char* name, char* mvname)
{
	int originalInode = inode_num;//记录当前的inode
	int source_inode_num, dest_inode_num;
	int inode;//原文件的inode
	char originalNamePath[30];
	char originalMvNamePath[30];

	strcpy(originalNamePath, name);
	strcpy(originalMvNamePath, mvname);

	if (eat_path(name) == -1) {
		printf("mv: cannot stat ‘%s’: No such file or directory\n", originalNamePath);
		return -1;
	}
	if (type_check(name) != File) {
		printf("mv: cannot move '%s': Not a file or no exist\n", originalNamePath);
		close_dir(inode_num);
		inode_num = originalInode;
		open_dir(inode_num);//返回操作前的目录位置
		return -1;
	}

	source_inode_num = inode_num;//记录原文件的父目录节点

	close_dir(inode_num);
	inode_num = originalInode;
	open_dir(inode_num);//返回操作前的目录位置

	if (eat_path(mvname) == -1) {
		printf("mv: cannot stat ‘%s’: No such file or directory\n", originalMvNamePath);
		return -1;
	}
	dest_inode_num = inode_num;//记录目标目录的父目录节点

	if (source_inode_num == dest_inode_num && strcmp(name, mvname) == 0) {
		printf("mv: '%s' and '%s' are the same file\n", originalNamePath, originalMvNamePath);
		close_dir(inode_num);
		inode_num = originalInode;
		open_dir(inode_num);//返回操作前的目录位置
		return -1;
	}

	Inode temp;
	/*读取原文件目录的inode节点,判断该目录是否可写*/
	fseek(Disk, InodeBeg + sizeof(Inode)*source_inode_num, SEEK_SET);
	fread(&temp, sizeof(Inode), 1, Disk);

	if (temp.access[1][user_num] == 0) { //原文件目录不可写
		if (type_check(mvname) == Directory)
			printf("mv: cannot move ‘%s’ to ‘%s/%s’: Permission denied\n", originalNamePath, originalMvNamePath, name);
		else 
			printf("mv: cannot move ‘%s’ to ‘%s’: Permission denied\n", originalNamePath, originalMvNamePath);
		close_dir(inode_num);
		inode_num = originalInode;
		open_dir(inode_num);//返回操作前的目录位置
		return -1;
	}

	/*形如:mv a.txt b.txt*/
	if (type_check(mvname) == -1) {  //如果b.txt不存在

		/*读取b.txt的父目录的inode,判断是否可写*/
		fseek(Disk, InodeBeg + sizeof(Inode)*dest_inode_num, SEEK_SET);
		fread(&temp, sizeof(temp), 1, Disk);

		if (temp.access[1][user_num] == 0) { //b.txt的父目录不可写
			printf("mv: cannot move ‘%s’ to ‘%s’: Permission denied\n", originalNamePath, originalMvNamePath);
			close_dir(inode_num);
			inode_num = originalInode;
			open_dir(inode_num);//返回操作前的目录位置
			return -1;
		}

		if (source_inode_num == dest_inode_num) {//如果b.txt不存在,且a.txt 与 b.txt 在同一父目录下,则相当于a.txt重命名
			for (int pos = 0; pos < dir_num; ++pos) {
				if (strcmp(dir_table[pos].name, name) == 0)
					strcpy(dir_table[pos].name, mvname);
			}
		}
		else {//如果b.txt不存在,且a.txt 与 b.txt 不在同一父目录下,则将a.txt的目录项删除,创建b.txt的目录项指向a.txt的inode
			inode_num = source_inode_num;
			open_dir(source_inode_num);//返回a.txt父目录位置
			inode = check_name(inode_num, name);
			adjust_dir(name);//删除a.txt的目录项

			close_dir(inode_num);
			inode_num = dest_inode_num;
			open_dir(dest_inode_num);//返回b.txt父目录位置
			strcpy(dir_table[dir_num].name, mvname);
			dir_table[dir_num++].inode_num = inode;
		}
	}
	else if (type_check(mvname) == File) {//如果b.txt为文件
		if (source_inode_num == dest_inode_num) {//若b.txt 与 a.txt在同一父目录下,则删除b.txt的目录项,同时将a.txt的目录项重命名
			adjust_dir(mvname);						//b.txt 与 a.txt在同一父目录下,则b.txt的父目录权限在前面已经判断,是可写的
			for (int pos = 0; pos < dir_num; ++pos) {
				if (strcmp(dir_table[pos].name, name) == 0)
					strcpy(dir_table[pos].name, mvname);
			}
		}
		else {//b.txt 已经存在 且 a.txt与b.txt不在同一目录,则将a.txt的目录项删除,修改b.txt的目录项指向a.txt的inode
			inode_num = source_inode_num;
			open_dir(source_inode_num);//返回a.txt父目录位置
			inode = check_name(inode_num, name);
			adjust_dir(name);//删除a.txt的目录项

			close_dir(inode_num);
			inode_num = dest_inode_num;
			open_dir(dest_inode_num);//返回b.txt父目录位置
			for (int pos = 0; pos < dir_num; ++pos) {
				if (strcmp(dir_table[pos].name, mvname) == 0)
					dir_table[pos].inode_num = inode;
			}
		}
	}
	else {  //如果b.txt为目录
		if (source_inode_num == dest_inode_num && strcmp(mvname, ".") == 0) {
			printf("mv: '%s' and '%s/%s' are the same file\n", originalNamePath, originalMvNamePath, name);
			return -1;//移动到本目录下,即不需要移动	
		}
		//如果b.txt是目录项,进入b.txt目录中,创建一个目录项指向a.txt, 再将a.txt的目录项删除,

		inode_num = source_inode_num;
		open_dir(source_inode_num);//返回a.txt父目录位置
		inode = check_name(inode_num, name);//记录a.txt的inode

		close_dir(inode_num);
		inode_num = dest_inode_num;
		open_dir(dest_inode_num);//返回b.txt父目录位置

		enter_child_dir(inode_num, mvname);
		if (check_name(inode_num, mvname) == -1) { //b.txt目录下不存在与a.txt重名的项目,则创建一个目录项指向a.txt

            /*读取b.txt的inode,判断是否可写*/
			fseek(Disk, InodeBeg + sizeof(Inode)*inode_num, SEEK_SET);
			fread(&temp, sizeof(Inode), 1, Disk);

			if (temp.access[1][user_num] == 0) { //b.txt不可写
				printf("mv: cannot move ‘%s’ to ‘%s/%s’: Permission denied\n", originalNamePath, originalMvNamePath, name);
				close_dir(inode_num);
				inode_num = originalInode;
				open_dir(inode_num);//返回操作前的目录位置
				return -1;
			}

			strcpy(dir_table[dir_num].name, name);
			dir_table[dir_num++].inode_num = inode;
		}
		else { //b.txt目录下存在与a.txt重名的项目,修改该项目的目录项指向a.txt的inode
			dir_table[check_name(inode, mvname)].inode_num = inode;
		}
		close_dir(inode_num);
		inode_num = source_inode_num;
		open_dir(source_inode_num);//返回a.txt父目录位置
		inode = check_name(inode_num, name);
		adjust_dir(name);//删除a.txt的目录项
	}

	close_dir(inode_num);
	inode_num = originalInode;
	open_dir(inode_num);//返回操作前的目录位置
	return 0;
}
Ejemplo n.º 14
0
int file_copy(char* name, char* cpname)
{
	int originalInode = inode_num;//记录当前的inode
	int source_inode_num, dest_inode_num;
	char originalNamePath[30];
	char originalCpNamePath[30];

	strcpy(originalNamePath, name);
	strcpy(originalCpNamePath, cpname);

	if (eat_path(name) == -1) {
		printf("cp: cannot stat ‘%s’: No such file or directory\n", originalNamePath);
		return -1;
	}
	if (type_check(name) != File) {
		printf("cp: cannot copy '%s': Not a file\n", originalNamePath);
		close_dir(inode_num);
		inode_num = originalInode;
		open_dir(inode_num);//返回操作前的目录位置
		return -1;
	}

	if (file_read(name) == -1) {//若原文件不可读
		printf("cp: cannot open '%s' for reading: Permission denied\n", originalNamePath);
		close_dir(inode_num);
		inode_num = originalInode;
		open_dir(inode_num);//返回操作前的目录位置
		return -1;
	}
	source_inode_num = inode_num;//记录原文件的父目录节点

	close_dir(inode_num);
	inode_num = originalInode;
	open_dir(inode_num);//返回操作前的目录位置

	if (eat_path(cpname) == -1) {
		printf("cp: cannot stat ‘%s’: No such file or directory\n", originalCpNamePath);
		return -1;
	}
	dest_inode_num = inode_num;//记录目标目录的父目录节点

	if (source_inode_num == dest_inode_num && strcmp(name, cpname) == 0) {
		printf("cp: '%s' and '%s' are the same file\n", originalNamePath, originalCpNamePath);
		close_dir(inode_num);
		inode_num = originalInode;
		open_dir(inode_num);//返回操作前的目录位置
		return -1;
	}

	Inode temp;

	/*将原文件拷贝到另一文件中*/
	if (type_check(cpname) != Directory) {
		if (check_name(inode_num, cpname) != -1) {//目标文件已经存在,则将数据拷贝进去
			if (file_write(cpname) == -1) { //若目标文件不可写
				printf("cp: cannot create regular file‘%s’: Permission denied\n", originalCpNamePath);
				close_dir(inode_num);
				inode_num = originalInode;
				open_dir(inode_num);//返回操作前的目录位置
				return -1;
			}
		}
		else {									 //目标文件不存在,创建文件,并将数据拷贝进去
			/*读取目标目录的inode节点,判断该目录是否可写*/
			fseek(Disk, InodeBeg + sizeof(Inode)*dest_inode_num, SEEK_SET);
			fread(&temp, sizeof(Inode), 1, Disk);

			if (temp.access[1][user_num] == 0) { //目标目录不可写
				printf("cp: cannot create regular file ‘%s’: Permission denied\n", originalCpNamePath);
				close_dir(inode_num);
				inode_num = originalInode;
				open_dir(inode_num);//返回操作前的目录位置
				return -1;
			}
			make_file(inode_num, cpname, File);
			file_write(cpname);//将数据从BUFF写入文件
		}		
	}
	/*将原文件拷贝到某个子目录下,包括当前目录(.), 原目录的父目录(..)*/
	else {
		if (source_inode_num == dest_inode_num && strcmp(cpname, ".") == 0) {//将当前目录下的某个文件复制到当前目录,提示已经存在
			printf("cp: '%s' and '%s/%s' are the same file\n", originalNamePath, originalCpNamePath, name);
			return -1;
		}

		enter_child_dir(inode_num, cpname);//进入子目录或父目录

		/*记录原目录名*/
		int pos = strlen(path) - 1; 
		for (; pos >= 0; --pos) {
			if (path[pos] == '/') {
				break;
			}
		}
		char curDirName[30];
		int i = 0;
		for (pos = pos + 1; pos <= strlen(path); ++pos)
			curDirName[i++] = path[pos];
		//printf("%s\n", curDirName);

		if (check_name(inode_num, name) != -1) {//是否已有同名文件	
			file_write(name);//将数据从BUFF写入文件
		}
		else {
			/*读取目标目录的inode节点,判断该目录是否可写*/
			fseek(Disk, InodeBeg + sizeof(Inode)*inode_num, SEEK_SET);
			fread(&temp, sizeof(Inode), 1, Disk);

			if (temp.access[1][user_num] == 0) { //目标目录不可写
				printf("cp: cannot create regular file ‘./%s’: Permission denied\n", name);
				close_dir(inode_num);
				inode_num = originalInode;
				open_dir(inode_num);//返回操作前的目录位置
				return -1;
			}

			make_file(inode_num, name, File);
			file_write(name);//将数据从BUFF写入文件
		}
		/*返回原目录*/
	
		if (strcmp(cpname, "..") == 0)
			enter_child_dir(inode_num, curDirName);//如果复制到父目录,则复制完返回原目录
		else
			enter_child_dir(inode_num, "..");//如果复制到子目录,则复制完返回到子目录的".."目录,即原目录
	}

	close_dir(inode_num);
	inode_num = originalInode;
	open_dir(inode_num);//返回操作前的目录位置
	return 0;
}
static void
on_dialog_add_edit_reponse (GtkWidget *dialog, int response_id,
                            LogviewFilterManager *manager)
{
  GtkWidget *entry_name, *entry_regex;
  GtkWidget *radio_color, *radio_visible;
  GtkWidget *check_foreground, *check_background;
  GtkWidget *color_foreground, *color_background;
  gchar *old_name;
  const gchar *name;
  const gchar *regex;
  LogviewFilter *filter;
  GtkTextTag *tag;
  GtkBuilder *builder;

  old_name = g_object_get_data (G_OBJECT (manager), "old_name");
  builder = manager->priv->builder;

  entry_name = GTK_WIDGET (gtk_builder_get_object (builder,
                                                   "entry_name"));
  entry_regex = GTK_WIDGET (gtk_builder_get_object (builder,
                                                    "entry_regex"));
  radio_color = GTK_WIDGET (gtk_builder_get_object (builder,
                                                    "radio_color"));
  radio_visible = GTK_WIDGET (gtk_builder_get_object (builder,
                                                      "radio_visible"));
  check_foreground = GTK_WIDGET (gtk_builder_get_object (builder,
                                                         "check_foreground"));
  check_background = GTK_WIDGET (gtk_builder_get_object (builder,
                                                         "check_background"));
  color_foreground = GTK_WIDGET (gtk_builder_get_object (builder,
                                                         "color_foreground"));
  color_background = GTK_WIDGET (gtk_builder_get_object (builder,
                                                         "color_background"));

  if (response_id == GTK_RESPONSE_APPLY) {
    name = gtk_entry_get_text (GTK_ENTRY (entry_name));
    regex = gtk_entry_get_text (GTK_ENTRY (entry_regex));

    if (!check_name (manager, name) || !check_regex (manager, regex)) {
      return;
    }

    filter = logview_filter_new (name, regex);
    tag = gtk_text_tag_new (name);

    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_color))) {
      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_foreground))) {
        GdkColor foreground_color;
        gtk_color_button_get_color (GTK_COLOR_BUTTON (color_foreground),
                                    &foreground_color);
        g_object_set (G_OBJECT (tag), 
                      "foreground-gdk", &foreground_color,
                      "foreground-set", TRUE, NULL);
      }

      if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_background))) {
        GdkColor background_color;
        gtk_color_button_get_color (GTK_COLOR_BUTTON (color_background),
                                    &background_color);
        g_object_set (tag, 
                      "paragraph-background-gdk", &background_color,
                      "paragraph-background-set", TRUE, NULL);
      }
      
      if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_foreground))
          && !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_background))) {
          GtkWidget *error_dialog;

          error_dialog = gtk_message_dialog_new (GTK_WINDOW (manager),
                                                 GTK_DIALOG_MODAL,
                                                 GTK_MESSAGE_ERROR,
                                                 GTK_BUTTONS_CLOSE,
                                                 "%s",
                                                 _("Please specify either foreground or background color!"));
          gtk_dialog_run (GTK_DIALOG (error_dialog));
          gtk_widget_destroy (error_dialog);
          g_object_unref (tag);
          g_object_unref (filter);

          return;
      }
    } else { /* !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_color)) */
      g_object_set (tag, "invisible", TRUE, NULL);
    }

    if (old_name && !g_str_equal (old_name, name)) {
      logview_prefs_remove_filter (manager->priv->prefs, old_name);
    }

    g_object_set (G_OBJECT (filter), "texttag", tag, NULL);
    g_object_unref (tag);

    logview_prefs_add_filter (manager->priv->prefs, filter);
    g_object_unref (filter);

    logview_filter_manager_update_model (manager);
  }

  gtk_widget_destroy (dialog);
}
Ejemplo n.º 16
0
void getopts(int argc, char *argv[])
{
	int i;
	int got_nos = 0;
	int got_nol = 0;
	int got_bn  = 0;
	int got_pn  = 0;
	int got_of  = 0;
	int got_f   = 0;
	int got_wd  = 0;
	int got_cmd = 0;
	char *endptr;

	for(i = 1; i < argc; i++) {
		if(!strcmp(argv[i], "-s")) {
			i++;
			if(i >= argc)	usage(argv, (char*) "Expected another parameter (number of segments)");
			if(got_nos)	usage(argv, (char*) "Number of segments specified twice");
			no_of_segments = (int) strtol(argv[i], &endptr, 10);
			if((*endptr != '\0') || (no_of_segments < 0))	usage(argv, (char*) "Invalid numeric value for number of segments");
			got_nos = 1;
		} else if(!strcmp(argv[i], "-l")) {
			i++;
			if(i >= argc)	usage(argv, (char*) "Expected another parameter (number of lines per segment)");
			if(got_nol)	usage(argv, (char*) "Number of lines per segment specified twice");
			no_of_lines = (int) strtol(argv[i], &endptr, 10);
			if((*endptr != '\0') || (no_of_lines < 1))	usage(argv, (char*) "Invalid numeric value for number of lines per segment");
			got_nol = 1;
		} else if(!strcmp(argv[i], "-n")) {
			i++;
			if(i >= argc)	usage(argv, (char*) "Expected another parameter (basename)");
			if(got_bn)	usage(argv, (char*) "Basename of outputfiles specified twice");
			if(check_basename(argv[i]))	usage(argv, (char*) "Invalid basename");
			got_bn = 1;
		} else if(!strcmp(argv[i], "-o")) {
			i++;
			if(i >= argc)	usage(argv, (char*) "Expected another parameter (outputfile)");
			if(got_of)	usage(argv, (char*) "Outputfile specified twice");
			if(check_name(argv[i], &outputfile))	usage(argv, (char*) "Invalid outputfilename");
			got_of = 1;
		} else if(!strcmp(argv[i], "-w")) {
			i++;
			if(i >= argc)	usage(argv, (char*) "Expected another parameter (workdir)");
			if(got_wd)	usage(argv, (char*) "Workdir specified twice");
			if(check_name(argv[i], &workdir))	usage(argv, (char*) "Invalid workdir");
			got_wd = 1;
		} else if(!strcmp(argv[i], "-e")) {
			i++;
			if(i >= argc)	usage(argv, (char*) "Expected another parameter (commandline)");
			if(got_cmd)	usage(argv, (char*) "Command specified twice");
			cmd = argv+i;
			got_cmd = 1;
			i = argc;
		} else if(!strcmp(argv[i], "-h")) {
			usage(argv, NULL);
		} else if(!strcmp(argv[i], "-v")) {
			verbose = 1;
		} else if(!strcmp(argv[i], "-f")) {
			if(got_f)	usage(argv, (char*) "Nodaemonflag specified twice");
			run_as_daemon = 0;
			got_f = 1;
		} else if(!strcmp(argv[i], "-D")) {
			i++;
			if(i >= argc)	{
				usage(argv, (char*) "Expected another parameter (environment variable specification)");
			}
			if(parseAndSetEnvironment(argc, argv, &i))	{
				usage(argv, (char*) "Invalid environment specification");
			}
		} else {
			if(got_pn)	usage(argv, (char*) "Pipename specified twice");
			if(check_pipename(argv[i]))	usage(argv, (char*) "Invalid pipename");
			got_pn = 1;
		}
	}
	if(!got_pn)	usage(argv, (char*) "Pipename missing");
	if(!got_bn)	logbasename = pipename;
	if(no_of_segments < 2)	usage(argv, (char*) "Number of segments should be at least 2");
	analyzer = getenv(ANALYZER);
}
Ejemplo n.º 17
0
/**
 * maggen [OPTIONS]
 * where OPTIONS include:
 *         -f  file      Define the input file of the tool. Othercase, uses the standart input (cin).
  *        -i  header    Including header '.h' or '.hpp' file for resolve externs variables in generated code.
 *         -fo folder    Defines the folder output for output generated information. Othercase, uses "./out_maggen/".
 *         -o  name      Defines the names files generated tool. Otherwise, uses "mag_eval".
 *         -h            Show this help message.
 */
bool parse_parameters(int argc, char *argv[], string &path_input_file, string &path_folder_output, string &name_library, vector<string> &headers)
{
	bool file_input_setup(false);
	bool folder_output_setup(false);
	bool name_file_output_setup(false);

	/* Singular option case: Help info */
	if (argc == 2)
	{
		string arg_h (argv[1]);
		if (arg_h.compare("-h") == 0)
		{
			show_help_information();
			exit(0);
		}
		else
		{
			return false;
		}
	}

	/* Multiples options case */
	int i(1);
	while (i < argc)
	{
		if (argc > i + 1)
		{
			string arg_i (argv[i++]);
			string value_arg_i(argv[i++]);

			if ((arg_i.compare("-f") == 0) && (!file_input_setup) && (check_file_exist(value_arg_i)))
			{
				file_input_setup = true;
				path_input_file = value_arg_i;
			}
			else if ((arg_i.compare("-fo") == 0) && (!folder_output_setup))
			{
				folder_output_setup = true;
				path_folder_output = value_arg_i;
			}
			else if ((arg_i.compare("-o") == 0) && (!name_file_output_setup) && (check_name(value_arg_i)))
			{
				name_file_output_setup = true;
				name_library = value_arg_i;
			}
			else if ((arg_i.compare("-i") == 0) && (check_file_exist(value_arg_i)))
			{
				headers.push_back(value_arg_i);
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
	return true;
}
Ejemplo n.º 18
0
/****************************************************************************
 Open a file with a share mode.
****************************************************************************/
files_struct *open_fake_file_shared1(enum FAKE_FILE_TYPE fake_file_type, connection_struct *conn,char *fname,
                                     SMB_STRUCT_STAT *psbuf,
                                     uint32 desired_access,
                                     int share_mode,int ofun, uint32 new_dos_attr, int oplock_request,
                                     int *Access,int *action)
{
    extern struct current_user current_user;
    int flags=0;
    files_struct *fsp = NULL;

    if (fake_file_type == 0) {
        return open_file_shared1(conn,fname,psbuf,desired_access,
                                 share_mode,ofun,new_dos_attr,
                                 oplock_request,Access,action);
    }

    /* access check */
    if (current_user.uid != 0) {
        DEBUG(1,("access_denied to service[%s] file[%s] user[%s]\n",
                 lp_servicename(SNUM(conn)),fname,conn->user));
        errno = EACCES;
        return NULL;
    }

    fsp = file_new(conn);
    if(!fsp)
        return NULL;

    DEBUG(5,("open_fake_file_shared1: fname = %s, FID = %d, share_mode = %x, ofun = %x, oplock request = %d\n",
             fname, fsp->fnum, share_mode, ofun, oplock_request ));

    if (!check_name(fname,conn)) {
        file_free(fsp);
        return NULL;
    }

    fsp->fd = -1;
    fsp->mode = psbuf->st_mode;
    fsp->inode = psbuf->st_ino;
    fsp->dev = psbuf->st_dev;
    fsp->vuid = current_user.vuid;
    fsp->size = psbuf->st_size;
    fsp->pos = -1;
    fsp->can_lock = True;
    fsp->can_read = ((flags & O_WRONLY)==0);
    fsp->can_write = ((flags & (O_WRONLY|O_RDWR))!=0);
    fsp->share_mode = 0;
    fsp->desired_access = desired_access;
    fsp->print_file = False;
    fsp->modified = False;
    fsp->oplock_type = NO_OPLOCK;
    fsp->sent_oplock_break = NO_BREAK_SENT;
    fsp->is_directory = False;
    fsp->is_stat = False;
    fsp->directory_delete_on_close = False;
    fsp->conn = conn;
    string_set(&fsp->fsp_name,fname);
    fsp->wcp = NULL; /* Write cache pointer. */

    fsp->fake_file_handle = init_fake_file_handle(fake_file_type);

    if (fsp->fake_file_handle==NULL) {
        file_free(fsp);
        return NULL;
    }

    conn->num_files_open++;
    return fsp;
}
Ejemplo n.º 19
0
BOOL sbbs_t::newuser()
{
	char	c,str[512];
	char 	tmp[512];
	uint	i;
	long	kmode;
	bool	usa;

	bputs(text[StartingNewUserRegistration]);
	getnodedat(cfg.node_num,&thisnode,0);
	if(thisnode.misc&NODE_LOCK) {
		bputs(text[NodeLocked]);
		logline(LOG_WARNING,"N!","New user locked node logon attempt");
		hangup();
		return(FALSE); 
	}

	if(cfg.sys_misc&SM_CLOSED) {
		bputs(text[NoNewUsers]);
		hangup();
		return(FALSE); 
	}
	getnodedat(cfg.node_num,&thisnode,1);
	thisnode.status=NODE_NEWUSER;
	thisnode.connection=node_connection;
	putnodedat(cfg.node_num,&thisnode);
	memset(&useron,0,sizeof(user_t));	  /* Initialize user info to null */
	if(cfg.new_pass[0] && online==ON_REMOTE) {
		c=0;
		while(++c<4) {
			bputs(text[NewUserPasswordPrompt]);
			getstr(str,40,K_UPPER);
			if(!strcmp(str,cfg.new_pass))
				break;
			SAFEPRINTF(tmp,"NUP Attempted: '%s'",str);
			logline(LOG_NOTICE,"N!",tmp); 
		}
		if(c==4) {
			SAFEPRINTF(str,"%snupguess.msg",cfg.text_dir);
			if(fexist(str))
				printfile(str,P_NOABORT);
			hangup();
			return(FALSE); 
		} 
	}

	/* Sets defaults per sysop config */
	useron.misc|=(cfg.new_misc&~(DELETED|INACTIVE|QUIET|NETMAIL));
	useron.qwk=QWK_DEFAULT;
	useron.firston=useron.laston=useron.pwmod=time32(NULL);
	if(cfg.new_expire) {
		now=time(NULL);
		useron.expire=(time32_t)(now+((long)cfg.new_expire*24L*60L*60L)); 
	} else
		useron.expire=0;
	useron.sex=' ';
	useron.prot=cfg.new_prot;
	SAFECOPY(useron.comp,client_name);	/* hostname or CID name */
	SAFECOPY(useron.note,cid);			/* IP address or CID number */
	if((i=userdatdupe(0,U_NOTE,LEN_NOTE,cid, /* del */true))!=0) {	/* Duplicate IP address */
		SAFEPRINTF2(useron.comment,"Warning: same IP address as user #%d %s"
			,i,username(&cfg,i,str));
		logline(LOG_NOTICE,"N!",useron.comment); 
	}

	SAFECOPY(useron.alias,"New");     /* just for status line */
	SAFECOPY(useron.modem,connection);
	if(!lastuser(&cfg)) {	/* Automatic sysop access for first user */
		bprintf("Creating sysop account... System password required.\r\n");
		if(!chksyspass())
			return(FALSE); 
		useron.level=99;
		useron.exempt=useron.flags1=useron.flags2=0xffffffffUL;
		useron.flags3=useron.flags4=0xffffffffUL;
		useron.rest=0L; 
	} else {
		useron.level=cfg.new_level;
		useron.flags1=cfg.new_flags1;
		useron.flags2=cfg.new_flags2;
		useron.flags3=cfg.new_flags3;
		useron.flags4=cfg.new_flags4;
		useron.rest=cfg.new_rest;
		useron.exempt=cfg.new_exempt; 
	}

	useron.cdt=cfg.new_cdt;
	useron.min=cfg.new_min;
	useron.freecdt=cfg.level_freecdtperday[useron.level];

	if(cfg.total_fcomps)
		SAFECOPY(useron.tmpext,cfg.fcomp[0]->ext);
	else
		SAFECOPY(useron.tmpext,"ZIP");

	useron.shell=cfg.new_shell;

	useron.alias[0]=0;

	kmode=(cfg.uq&UQ_NOEXASC)|K_EDIT|K_AUTODEL;
	if(!(cfg.uq&UQ_NOUPRLWR))
		kmode|=K_UPRLWR;

	while(online) {

		if(autoterm || (text[AutoTerminalQ][0] && yesno(text[AutoTerminalQ]))) {
			useron.misc|=AUTOTERM;
			useron.misc|=autoterm; 
		} else
			useron.misc&=~AUTOTERM;

		if(!(useron.misc&AUTOTERM)) {
			if(text[AnsiTerminalQ][0] && yesno(text[AnsiTerminalQ]))
				useron.misc|=ANSI; 
			else
				useron.misc&=~ANSI;
		}

		if(useron.misc&ANSI) {
			useron.rows=0;	/* Auto-rows */
			if(!(cfg.uq&UQ_COLORTERM) || useron.misc&(RIP|WIP|HTML) || text[ColorTerminalQ][0]==0 || yesno(text[ColorTerminalQ]))
				useron.misc|=COLOR; 
			else
				useron.misc&=~COLOR;
		}
		else
			useron.rows=24;
		if(text[ExAsciiTerminalQ][0] && !yesno(text[ExAsciiTerminalQ]))
			useron.misc|=NO_EXASCII;
		else
			useron.misc&=~NO_EXASCII;

		if(rlogin_name[0])
			SAFECOPY(useron.alias,rlogin_name);

		while(online) {
			if(cfg.uq&UQ_ALIASES)
				bputs(text[EnterYourAlias]);
			else
				bputs(text[EnterYourRealName]);
			getstr(useron.alias,LEN_ALIAS,kmode);
			truncsp(useron.alias);
			if (!check_name(&cfg,useron.alias)
				|| (!(cfg.uq&UQ_ALIASES) && !strchr(useron.alias,' '))) {
				bputs(text[YouCantUseThatName]);
				if(text[ContinueQ][0] && !yesno(text[ContinueQ]))
					return(FALSE);
				continue;
			}
			break; 
		}
		if(!online) return(FALSE);
		if((cfg.uq&UQ_ALIASES) && (cfg.uq&UQ_REALNAME)) {
			while(online) {
				bputs(text[EnterYourRealName]);
				getstr(useron.name,LEN_NAME,kmode);
				if (!check_name(&cfg,useron.name)
					|| !strchr(useron.name,' ')
					|| ((cfg.uq&UQ_DUPREAL)
						&& userdatdupe(useron.number,U_NAME,LEN_NAME,useron.name)))
					bputs(text[YouCantUseThatName]);
				else
					break; 
				if(text[ContinueQ][0] && !yesno(text[ContinueQ]))
					return(FALSE);
			} 
		}
		else if(cfg.uq&UQ_COMPANY) {
				bputs(text[EnterYourCompany]);
				getstr(useron.name,LEN_NAME,(cfg.uq&UQ_NOEXASC)|K_EDIT|K_AUTODEL); 
		}
		if(!useron.name[0])
			SAFECOPY(useron.name,useron.alias);
		if(!online) return(FALSE);
		if(!useron.handle[0])
			SAFECOPY(useron.handle,useron.alias);
		while((cfg.uq&UQ_HANDLE) && online) {
			bputs(text[EnterYourHandle]);
			if(!getstr(useron.handle,LEN_HANDLE
				,K_LINE|K_EDIT|K_AUTODEL|(cfg.uq&UQ_NOEXASC))
				|| strchr(useron.handle,0xff)
				|| ((cfg.uq&UQ_DUPHAND)
					&& userdatdupe(0,U_HANDLE,LEN_HANDLE,useron.handle))
				|| trashcan(useron.handle,"name"))
				bputs(text[YouCantUseThatName]);
			else
				break; 
			if(text[ContinueQ][0] && !yesno(text[ContinueQ]))
				return(FALSE);
		}
		if(!online) return(FALSE);
		if(cfg.uq&UQ_ADDRESS)
			while(online) { 	   /* Get address and zip code */
				bputs(text[EnterYourAddress]);
				if(getstr(useron.address,LEN_ADDRESS,kmode))
					break; 
			}
		if(!online) return(FALSE);
		while((cfg.uq&UQ_LOCATION) && online) {
			bputs(text[EnterYourCityState]);
			if(getstr(useron.location,LEN_LOCATION,kmode)
				&& ((cfg.uq&UQ_NOCOMMAS) || strchr(useron.location,',')))
				break;
			bputs(text[CommaInLocationRequired]);
			useron.location[0]=0; 
		}
		if(cfg.uq&UQ_ADDRESS)
			while(online) {
				bputs(text[EnterYourZipCode]);
				if(getstr(useron.zipcode,LEN_ZIPCODE
					,K_UPPER|(cfg.uq&UQ_NOEXASC)|K_EDIT|K_AUTODEL))
					break; 
			}
		if(!online) return(FALSE);
		if(cfg.uq&UQ_PHONE) {
			if(text[CallingFromNorthAmericaQ][0])
				usa=yesno(text[CallingFromNorthAmericaQ]);
			else
				usa=false;
			while(online && text[EnterYourPhoneNumber][0]) {
				bputs(text[EnterYourPhoneNumber]);
				if(!usa) {
					if(getstr(useron.phone,LEN_PHONE
						,K_UPPER|K_LINE|(cfg.uq&UQ_NOEXASC)|K_EDIT|K_AUTODEL)<5)
						continue; 
				}
				else {
					if(gettmplt(useron.phone,cfg.sys_phonefmt
						,K_LINE|(cfg.uq&UQ_NOEXASC)|K_EDIT)<strlen(cfg.sys_phonefmt))
						continue; 
				}
				if(!trashcan(useron.phone,"phone"))
					break; 
			} 
		}
		if(!online) return(FALSE);
		if(cfg.uq&UQ_SEX) {
			bputs(text[EnterYourSex]);
			useron.sex=(char)getkeys("MF",0); 
		}
		while((cfg.uq&UQ_BIRTH) && online) {
			bprintf(text[EnterYourBirthday]
				,cfg.sys_misc&SM_EURODATE ? "DD/MM/YY" : "MM/DD/YY");
			if(gettmplt(useron.birth,"nn/nn/nn",K_EDIT)==8 && getage(&cfg,useron.birth))
				break; 
		}
		if(!online) return(FALSE);
		while(!(cfg.uq&UQ_NONETMAIL) && online) {
			bputs(text[EnterNetMailAddress]);
			if(getstr(useron.netmail,LEN_NETMAIL,K_EDIT|K_AUTODEL|K_LINE)
				&& !trashcan(useron.netmail,"email"))
				break;
		}
		if(useron.netmail[0] && cfg.sys_misc&SM_FWDTONET && text[ForwardMailQ][0] && yesno(text[ForwardMailQ]))
			useron.misc|=NETMAIL;
		else 
			useron.misc&=~NETMAIL;
		if(text[UserInfoCorrectQ][0]==0 || yesno(text[UserInfoCorrectQ]))
			break; 
	}
	if(!online) return(FALSE);
	SAFEPRINTF(str,"New user: %s",useron.alias);
	logline("N",str);
	if(!online) return(FALSE);
	CLS;
	SAFEPRINTF(str,"%ssbbs.msg",cfg.text_dir);
	printfile(str,P_NOABORT);
	if(lncntr)
		pause();
	CLS;
	SAFEPRINTF(str,"%ssystem.msg",cfg.text_dir);
	printfile(str,P_NOABORT);
	if(lncntr)
		pause();
	CLS;
	SAFEPRINTF(str,"%snewuser.msg",cfg.text_dir);
	printfile(str,P_NOABORT);
	if(lncntr)
		pause();
	CLS;
	answertime=time(NULL);		/* could take 10 minutes to get this far */

	/* Default editor (moved here, after terminal type setup Jan-2003) */
	for(i=0;i<cfg.total_xedits;i++)
		if(!stricmp(cfg.xedit[i]->code,cfg.new_xedit) && chk_ar(cfg.xedit[i]->ar,&useron,&client))
			break;
	if(i<cfg.total_xedits)
		useron.xedit=i+1;

	if(cfg.total_xedits && (cfg.uq&UQ_XEDIT) && text[UseExternalEditorQ][0]) {
		if(yesno(text[UseExternalEditorQ])) {
			for(i=0;i<cfg.total_xedits;i++)
				uselect(1,i,text[ExternalEditorHeading],cfg.xedit[i]->name,cfg.xedit[i]->ar);
			if((int)(i=uselect(0,useron.xedit ? useron.xedit-1 : 0,0,0,0))>=0)
				useron.xedit=i+1; 
		} else
			useron.xedit=0;
	}

	if(cfg.total_shells>1 && (cfg.uq&UQ_CMDSHELL)) {
		for(i=0;i<cfg.total_shells;i++)
			uselect(1,i,text[CommandShellHeading],cfg.shell[i]->name,cfg.shell[i]->ar);
		if((int)(i=uselect(0,useron.shell,0,0,0))>=0)
			useron.shell=i; 
	}

	if(rlogin_pass[0] && chkpass(rlogin_pass,&useron,true)) {
		CRLF;
		SAFECOPY(useron.pass, rlogin_pass);
		strupr(useron.pass);	/* passwords are case insensitive, but assumed (in some places) to be uppercase in the user database */
	}
	else {
		c=0;
		while(c<LEN_PASS) { 				/* Create random password */
			useron.pass[c]=sbbs_random(43)+'0';
			if(isalnum(useron.pass[c]))
				c++; 
		}
		useron.pass[c]=0;

		bprintf(text[YourPasswordIs],useron.pass);

		if(cfg.sys_misc&SM_PWEDIT && text[NewPasswordQ][0] && yesno(text[NewPasswordQ]))
			while(online) {
				bputs(text[NewPassword]);
				getstr(str,LEN_PASS,K_UPPER|K_LINE);
				truncsp(str);
				if(chkpass(str,&useron,true)) {
					SAFECOPY(useron.pass,str);
					CRLF;
					bprintf(text[YourPasswordIs],useron.pass);
					break; 
				}
				CRLF; 
			}

		c=0;
		while(online) {
			bprintf(text[NewUserPasswordVerify]);
			console|=CON_R_ECHOX;
			str[0]=0;
			getstr(str,LEN_PASS*2,K_UPPER);
			console&=~(CON_R_ECHOX|CON_L_ECHOX);
			if(!strcmp(str,useron.pass)) break;
			if(cfg.sys_misc&SM_ECHO_PW) 
				SAFEPRINTF3(tmp,"%s FAILED Password verification: '%s' instead of '%s'"
					,useron.alias
					,str
					,useron.pass);
			else
				SAFEPRINTF(tmp,"%s FAILED Password verification"
					,useron.alias);
			logline(LOG_NOTICE,nulstr,tmp);
			if(++c==4) {
				logline(LOG_NOTICE,"N!","Couldn't figure out password.");
				hangup(); 
			}
			bputs(text[IncorrectPassword]);
			bprintf(text[YourPasswordIs],useron.pass); 
		}
	}

	if(!online) return(FALSE);
	if(cfg.new_magic[0]) {
		bputs(text[MagicWordPrompt]);
		str[0]=0;
		getstr(str,50,K_UPPER);
		if(strcmp(str,cfg.new_magic)) {
			bputs(text[FailedMagicWord]);
			SAFEPRINTF2(tmp,"%s failed magic word: '%s'",useron.alias,str);
			logline("N!",tmp);
			hangup(); 
		}
		if(!online) return(FALSE); 
	}

	bputs(text[CheckingSlots]);

	if((i=newuserdat(&cfg,&useron))!=0) {
		SAFEPRINTF(str,"user record #%u",useron.number);
		errormsg(WHERE,ERR_CREATE,str,i);
		hangup();
		return(FALSE); 
	}
	SAFEPRINTF2(str,"Created user record #%u: %s",useron.number,useron.alias);
	logline(nulstr,str);
	if(cfg.new_sif[0]) {
		SAFEPRINTF2(str,"%suser/%4.4u.dat",cfg.data_dir,useron.number);
		create_sif_dat(cfg.new_sif,str); 
	}
	if(!(cfg.uq&UQ_NODEF))
		maindflts(&useron);

	delallmail(useron.number, MAIL_ANY);

	if(useron.number!=1 && cfg.node_valuser) {
		SAFEPRINTF(str,"%sfeedback.msg",cfg.text_dir);
		CLS;
		printfile(str,P_NOABORT);
		safe_snprintf(str,sizeof(str),text[NewUserFeedbackHdr]
			,nulstr,getage(&cfg,useron.birth),useron.sex,useron.birth
			,useron.name,useron.phone,useron.comp,useron.modem);
		email(cfg.node_valuser,str,"New User Validation",WM_EMAIL|WM_SUBJ_RO|WM_FORCEFWD);
		if(!useron.fbacks && !useron.emails) {
			if(online) {						/* didn't hang up */
				bprintf(text[NoFeedbackWarning],username(&cfg,cfg.node_valuser,tmp));
				email(cfg.node_valuser,str,"New User Validation",WM_EMAIL|WM_SUBJ_RO|WM_FORCEFWD);
				} /* give 'em a 2nd try */
			if(!useron.fbacks && !useron.emails) {
        		bprintf(text[NoFeedbackWarning],username(&cfg,cfg.node_valuser,tmp));
				logline(LOG_NOTICE,"N!","Aborted feedback");
				hangup();
				putuserrec(&cfg,useron.number,U_COMMENT,60,"Didn't leave feedback");
				putuserrec(&cfg,useron.number,U_MISC,8
					,ultoa(useron.misc|DELETED,tmp,16));
				putusername(&cfg,useron.number,nulstr);
				return(FALSE); 
			} 
		} 
	}

	answertime=starttime=time(NULL);	  /* set answertime to now */

#ifdef JAVASCRIPT
	js_create_user_objects();
#endif

	if(cfg.newuser_mod[0])
		exec_bin(cfg.newuser_mod,&main_csi);
	user_event(EVENT_NEWUSER);
	getuserdat(&cfg,&useron);	// In case event(s) modified user data
	logline("N+","Successful new user logon");
	sys_status|=SS_NEWUSER;

	return(TRUE);
}
Ejemplo n.º 20
0
int
cifs_atomic_open(struct inode *inode, struct dentry *direntry,
		 struct file *file, unsigned oflags, umode_t mode,
		 int *opened)
{
	int rc;
	unsigned int xid;
	struct tcon_link *tlink;
	struct cifs_tcon *tcon;
	__u16 fileHandle;
	__u32 oplock;
	struct cifsFileInfo *pfile_info;

	/* Posix open is only called (at lookup time) for file create now.  For
	 * opens (rather than creates), because we do not know if it is a file
	 * or directory yet, and current Samba no longer allows us to do posix
	 * open on dirs, we could end up wasting an open call on what turns out
	 * to be a dir. For file opens, we wait to call posix open till
	 * cifs_open.  It could be added to atomic_open in the future but the
	 * performance tradeoff of the extra network request when EISDIR or
	 * EACCES is returned would have to be weighed against the 50% reduction
	 * in network traffic in the other paths.
	 */
	if (!(oflags & O_CREAT)) {
		struct dentry *res = cifs_lookup(inode, direntry, 0);
		if (IS_ERR(res))
			return PTR_ERR(res);

		return finish_no_open(file, res);
	}

	rc = check_name(direntry);
	if (rc)
		return rc;

	xid = get_xid();

	cFYI(1, "parent inode = 0x%p name is: %s and dentry = 0x%p",
	     inode, direntry->d_name.name, direntry);

	tlink = cifs_sb_tlink(CIFS_SB(inode->i_sb));
	if (IS_ERR(tlink))
		goto out_free_xid;

	tcon = tlink_tcon(tlink);

	rc = cifs_do_create(inode, direntry, xid, tlink, oflags, mode,
			    &oplock, &fileHandle, opened);

	if (rc)
		goto out;

	rc = finish_open(file, direntry, generic_file_open, opened);
	if (rc) {
		CIFSSMBClose(xid, tcon, fileHandle);
		goto out;
	}

	pfile_info = cifs_new_fileinfo(fileHandle, file, tlink, oplock);
	if (pfile_info == NULL) {
		CIFSSMBClose(xid, tcon, fileHandle);
		rc = -ENOMEM;
	}

out:
	cifs_put_tlink(tlink);
out_free_xid:
	free_xid(xid);
	return rc;
}
bool load_instance(Data* data_p, std::string const& file_p)
{
  LOG(INFO) << "Loading Instance inside the data structure : " << file_p;
  // VLOG(2) << "Found cookies in DEBUG";
  

  VLOG(1) << "Openning the file";
  std::ifstream file_stream_l(file_p);
  // get length of file:
  file_stream_l.seekg (0, file_stream_l.end);
  int length = file_stream_l.tellg();
  file_stream_l.seekg (0, file_stream_l.beg);
  VLOG(1) << "The length of file is : " << length;


  VLOG(1) << "Reading the file";
  char * buffer = new char [length];
  file_stream_l.read (buffer,length);
  if (file_stream_l)
    VLOG(1) << "All characters read successfully.";
  else
    LOG(FATAL) << "Error : only " << file_stream_l.gcount() << " could be read";
  file_stream_l.close();


  VLOG(1) << "Parsing the file";
  rapidxml::xml_document<> doc;    // character type defaults to char
  doc.parse<0>(buffer);    // 0 means default parse flags


  VLOG(1) << "Extracting Data";

  rapidxml::xml_node<> *root = doc.first_node(); // Node IRP_R_C_I

  /** Extraction of the tree ! */

  // Unit 
  rapidxml::xml_node<> *child_l = root->first_node();
  check_name(child_l,"unit");
  data_p->unit(std::stoi(child_l->value()));
  VLOG(1) << "Unit = " << data_p->unit();

  // Horizon
  child_l = child_l->next_sibling();
  check_name(child_l,"horizon");
  data_p->horizon(std::stoi(child_l->value()));
  VLOG(1) << "Horizon = " << data_p->horizon();

  // Time Matrices
  child_l = child_l->next_sibling();
  check_name(child_l,"timeMatrices");
  int size_time_matrices = load_time_matrices(data_p, child_l);
  VLOG(1) <<  "Time Matrix loaded of size = " << size_time_matrices;

  // Drivers
  child_l = child_l->next_sibling();
  check_name(child_l,"drivers");
  int num_drivers = load_drivers(data_p, child_l);
  VLOG(1) <<  "Vector of driverd loaded of size = " << num_drivers;

  // Trailers
  child_l = child_l->next_sibling();
  check_name(child_l,"trailers");
  int num_trailers = load_trailers(data_p, child_l);
  VLOG(1) <<  "Vector of trailers loaded of size = " << num_trailers;

  // Bases
  child_l = child_l->next_sibling();
  check_name(child_l,"bases");
  data_p->bases_index(std::stoi(child_l->first_node()->value()));
  VLOG(1) << "bases = " << data_p->bases_index();

  // Sources
  child_l = child_l->next_sibling();
  check_name(child_l,"sources");
  int num_sources = load_sources(data_p, child_l);
  VLOG(1) <<  "Vector of sources loaded of size = " << num_sources;

  // Customers
  child_l = child_l->next_sibling();
  check_name(child_l,"customers");
  int num_customers = load_customers(data_p, child_l);
  VLOG(1) <<  "Vector of customers loaded of size = " << num_customers;

  // Time Matrices
  child_l = child_l->next_sibling();
  check_name(child_l,"distMatrices");
  int size_dist_matrices = load_dist_matrices(data_p, child_l);
  VLOG(1) <<  "Dist Matrix loaded of size = " << size_dist_matrices;

  // Clearing memory space
  delete[] buffer;
  return true;
}
Ejemplo n.º 22
0
Archivo: edit.c Proyecto: jff/mathspad
static void handle_filename(void *data, Char *name)
{
    EDITINFO *einf = (EDITINFO *) data;

    if (name) {
	FILE *f;
	int i;
	int check_found = check_name(einf, name);

	if (!(f = fopen((char*)UstrtoFilename(name),"rb"))) {
	    message2(MP_CLICKREMARK, translate("Unable to open file "), name);
	    free(name);
	    failure=MP_True;
	    return;
	}
	i = test_file(f);
	set_wait_cursor(einf->win_id);
	switch (i) {
	case BINDOC:
	    message(MP_MESSAGE, translate("Loading ascii file."));
	    read_file(f,BINARYFILE);
	    unset_file();
	    load_editwindow(einf->info);
	    break;
	case OLDDOC:
	    i = edit_fnr;
	    edit_fnr = 0;
	    load_notation_filenames(f);
	    old_load_editwindow(einf->info,f);
	    edit_fnr = i;
	    if (!state_open) clear_file_ref();
	    break;
	case NEWDOC:
	    i = edit_fnr;
	    edit_fnr = 0;
	    read_file(f,DOCUMENTFILE);
	    unset_file();
	    load_editwindow(einf->info);
	    edit_fnr = i;
	    break;
	default: break;
	}
	fclose(f);
	cleanup_nodestack();
	cleanup_filestack();
	cleanup_stencilstack();
	einf->saved = MP_True;
	einf->auto_saved = MP_True;
	einf->view_mode = check_found;
	set_name(einf, name);
	set_output_name(einf);
	name = NULL;
	remove_wait_cursor();
	if (check_found)
	    message(MP_CLICKREMARK, translate("The document is already loaded.\n"
		    "This copy has been loaded in view mode\n"
		    "in order to ensure that only one\n"
		    "backup is made."));
	return;
    }
    free(name);
}
Ejemplo n.º 23
0
static int check_dir_block(ext2_filsys fs,
			   struct ext2_db_entry2 *db,
			   void *priv_data)
{
 	struct dx_dir_info	*dx_dir;
#ifdef ENABLE_HTREE
	struct dx_dirblock_info	*dx_db = 0;
#endif /* ENABLE_HTREE */
	struct ext2_dir_entry 	*dirent, *prev;
	ext2_dirhash_t		hash;
	unsigned int		offset = 0;
	int			dir_modified = 0;
	int			dot_state;
	unsigned int		rec_len;
	blk64_t			block_nr = db->blk;
	ext2_ino_t 		ino = db->ino;
	ext2_ino_t 		subdir_parent;
	__u16			links;
	struct check_dir_struct	*cd;
	char 			*buf;
	e2fsck_t		ctx;
	int			problem;
	struct ext2_dx_root_info *root;
	struct ext2_dx_countlimit *limit;
	static dict_t de_dict;
	struct problem_context	pctx;
	int	dups_found = 0;
	int	ret;
	int	dx_csum_size = 0, de_csum_size = 0;
	int	failed_csum = 0;
	int	is_leaf = 1;

	cd = (struct check_dir_struct *) priv_data;
	buf = cd->buf;
	ctx = cd->ctx;

	if (ctx->flags & E2F_FLAG_SIGNAL_MASK || ctx->flags & E2F_FLAG_RESTART)
		return DIRENT_ABORT;

	if (ctx->progress && (ctx->progress)(ctx, 2, cd->count++, cd->max))
		return DIRENT_ABORT;

	if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
				       EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
		dx_csum_size = sizeof(struct ext2_dx_tail);
		de_csum_size = sizeof(struct ext2_dir_entry_tail);
	}

	/*
	 * Make sure the inode is still in use (could have been
	 * deleted in the duplicate/bad blocks pass.
	 */
	if (!(ext2fs_test_inode_bitmap2(ctx->inode_used_map, ino)))
		return 0;

	cd->pctx.ino = ino;
	cd->pctx.blk = block_nr;
	cd->pctx.blkcount = db->blockcnt;
	cd->pctx.ino2 = 0;
	cd->pctx.dirent = 0;
	cd->pctx.num = 0;

	if (db->blk == 0) {
		if (allocate_dir_block(ctx, db, buf, &cd->pctx))
			return 0;
		block_nr = db->blk;
	}

	if (db->blockcnt)
		dot_state = 2;
	else
		dot_state = 0;

	if (ctx->dirs_to_hash &&
	    ext2fs_u32_list_test(ctx->dirs_to_hash, ino))
		dups_found++;

#if 0
	printf("In process_dir_block block %lu, #%d, inode %lu\n", block_nr,
	       db->blockcnt, ino);
#endif

	ehandler_operation(_("reading directory block"));
	cd->pctx.errcode = ext2fs_read_dir_block4(fs, block_nr, buf, 0, ino);
	ehandler_operation(0);
	if (cd->pctx.errcode == EXT2_ET_DIR_CORRUPTED)
		cd->pctx.errcode = 0; /* We'll handle this ourselves */
	else if (cd->pctx.errcode == EXT2_ET_DIR_CSUM_INVALID) {
		cd->pctx.errcode = 0; /* We'll handle this ourselves */
		failed_csum = 1;
	}
	if (cd->pctx.errcode) {
		char *buf2;
		if (!fix_problem(ctx, PR_2_READ_DIRBLOCK, &cd->pctx)) {
			ctx->flags |= E2F_FLAG_ABORT;
			return DIRENT_ABORT;
		}
		ext2fs_new_dir_block(fs, db->blockcnt == 0 ? ino : 0,
				     EXT2_ROOT_INO, &buf2);
		memcpy(buf, buf2, fs->blocksize);
		ext2fs_free_mem(&buf2);
	}
#ifdef ENABLE_HTREE
	dx_dir = e2fsck_get_dx_dir_info(ctx, ino);
	if (dx_dir && dx_dir->numblocks) {
		if (db->blockcnt >= dx_dir->numblocks) {
			if (fix_problem(ctx, PR_2_UNEXPECTED_HTREE_BLOCK,
					&pctx)) {
				clear_htree(ctx, ino);
				dx_dir->numblocks = 0;
				dx_db = 0;
				goto out_htree;
			}
			fatal_error(ctx, _("Can not continue."));
		}
		dx_db = &dx_dir->dx_block[db->blockcnt];
		dx_db->type = DX_DIRBLOCK_LEAF;
		dx_db->phys = block_nr;
		dx_db->min_hash = ~0;
		dx_db->max_hash = 0;

		dirent = (struct ext2_dir_entry *) buf;
		(void) ext2fs_get_rec_len(fs, dirent, &rec_len);
		limit = (struct ext2_dx_countlimit *) (buf+8);
		if (db->blockcnt == 0) {
			root = (struct ext2_dx_root_info *) (buf + 24);
			dx_db->type = DX_DIRBLOCK_ROOT;
			dx_db->flags |= DX_FLAG_FIRST | DX_FLAG_LAST;
			if ((root->reserved_zero ||
			     root->info_length < 8 ||
			     root->indirect_levels > 1) &&
			    fix_problem(ctx, PR_2_HTREE_BAD_ROOT, &cd->pctx)) {
				clear_htree(ctx, ino);
				dx_dir->numblocks = 0;
				dx_db = 0;
			}
			dx_dir->hashversion = root->hash_version;
			if ((dx_dir->hashversion <= EXT2_HASH_TEA) &&
			    (fs->super->s_flags & EXT2_FLAGS_UNSIGNED_HASH))
				dx_dir->hashversion += 3;
			dx_dir->depth = root->indirect_levels + 1;
		} else if ((dirent->inode == 0) &&
			   (rec_len == fs->blocksize) &&
			   (dirent->name_len == 0) &&
			   (ext2fs_le16_to_cpu(limit->limit) ==
			    ((fs->blocksize - (8 + dx_csum_size)) /
			     sizeof(struct ext2_dx_entry))))
			dx_db->type = DX_DIRBLOCK_NODE;
		is_leaf = 0;
	}
out_htree:
#endif /* ENABLE_HTREE */

	/* Verify checksum. */
	if (is_leaf && de_csum_size) {
		/* No space for csum?  Rebuild dirs in pass 3A. */
		if (!ext2fs_dirent_has_tail(fs, (struct ext2_dir_entry *)buf)) {
			de_csum_size = 0;
			if (e2fsck_dir_will_be_rehashed(ctx, ino))
				goto skip_checksum;
			if (!fix_problem(cd->ctx, PR_2_LEAF_NODE_MISSING_CSUM,
					 &cd->pctx))
				goto skip_checksum;
			e2fsck_rehash_dir_later(ctx, ino);
			goto skip_checksum;
		}
		if (failed_csum) {
			char *buf2;
			if (!fix_problem(cd->ctx, PR_2_LEAF_NODE_CSUM_INVALID,
					 &cd->pctx))
				goto skip_checksum;
			ext2fs_new_dir_block(fs,
					     db->blockcnt == 0 ? ino : 0,
					     EXT2_ROOT_INO, &buf2);
			memcpy(buf, buf2, fs->blocksize);
			ext2fs_free_mem(&buf2);
			dir_modified++;
			failed_csum = 0;
		}
	}
	/* htree nodes don't use fake dirents to store checksums */
	if (!is_leaf)
		de_csum_size = 0;

skip_checksum:
	dict_init(&de_dict, DICTCOUNT_T_MAX, dict_de_cmp);
	prev = 0;
	do {
		int group;
		ext2_ino_t first_unused_inode;

		problem = 0;
		dirent = (struct ext2_dir_entry *) (buf + offset);
		(void) ext2fs_get_rec_len(fs, dirent, &rec_len);
		cd->pctx.dirent = dirent;
		cd->pctx.num = offset;
		if (((offset + rec_len) > fs->blocksize) ||
		    (rec_len < 12) ||
		    ((rec_len % 4) != 0) ||
		    (((dirent->name_len & (unsigned) 0xFF)+8) > rec_len)) {
			if (fix_problem(ctx, PR_2_DIR_CORRUPTED, &cd->pctx)) {
				salvage_directory(fs, dirent, prev, &offset);
				dir_modified++;
				continue;
			} else
				goto abort_free_dict;
		}

		if (dot_state == 0) {
			if (check_dot(ctx, dirent, ino, &cd->pctx))
				dir_modified++;
		} else if (dot_state == 1) {
			ret = check_dotdot(ctx, dirent, ino, &cd->pctx);
			if (ret < 0)
				goto abort_free_dict;
			if (ret)
				dir_modified++;
		} else if (dirent->inode == ino) {
			problem = PR_2_LINK_DOT;
			if (fix_problem(ctx, PR_2_LINK_DOT, &cd->pctx)) {
				dirent->inode = 0;
				dir_modified++;
				goto next;
			}
		}
		if (!dirent->inode)
			goto next;

		/*
		 * Make sure the inode listed is a legal one.
		 */
		if (((dirent->inode != EXT2_ROOT_INO) &&
		     (dirent->inode < EXT2_FIRST_INODE(fs->super))) ||
		    (dirent->inode > fs->super->s_inodes_count)) {
			problem = PR_2_BAD_INO;
		} else if (ctx->inode_bb_map &&
			   (ext2fs_test_inode_bitmap2(ctx->inode_bb_map,
						     dirent->inode))) {
			/*
			 * If the inode is in a bad block, offer to
			 * clear it.
			 */
			problem = PR_2_BB_INODE;
		} else if ((dot_state > 1) &&
			   ((dirent->name_len & 0xFF) == 1) &&
			   (dirent->name[0] == '.')) {
			/*
			 * If there's a '.' entry in anything other
			 * than the first directory entry, it's a
			 * duplicate entry that should be removed.
			 */
			problem = PR_2_DUP_DOT;
		} else if ((dot_state > 1) &&
			   ((dirent->name_len & 0xFF) == 2) &&
			   (dirent->name[0] == '.') &&
			   (dirent->name[1] == '.')) {
			/*
			 * If there's a '..' entry in anything other
			 * than the second directory entry, it's a
			 * duplicate entry that should be removed.
			 */
			problem = PR_2_DUP_DOT_DOT;
		} else if ((dot_state > 1) &&
			   (dirent->inode == EXT2_ROOT_INO)) {
			/*
			 * Don't allow links to the root directory.
			 * We check this specially to make sure we
			 * catch this error case even if the root
			 * directory hasn't been created yet.
			 */
			problem = PR_2_LINK_ROOT;
		} else if ((dot_state > 1) &&
			   (dirent->name_len & 0xFF) == 0) {
			/*
			 * Don't allow zero-length directory names.
			 */
			problem = PR_2_NULL_NAME;
		}

		if (problem) {
			if (fix_problem(ctx, problem, &cd->pctx)) {
				dirent->inode = 0;
				dir_modified++;
				goto next;
			} else {
				ext2fs_unmark_valid(fs);
				if (problem == PR_2_BAD_INO)
					goto next;
			}
		}

		/*
		 * If the inode was marked as having bad fields in
		 * pass1, process it and offer to fix/clear it.
		 * (We wait until now so that we can display the
		 * pathname to the user.)
		 */
		if (ctx->inode_bad_map &&
		    ext2fs_test_inode_bitmap2(ctx->inode_bad_map,
					     dirent->inode)) {
			if (e2fsck_process_bad_inode(ctx, ino,
						     dirent->inode,
						     buf + fs->blocksize)) {
				dirent->inode = 0;
				dir_modified++;
				goto next;
			}
			if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
				return DIRENT_ABORT;
		}

		group = ext2fs_group_of_ino(fs, dirent->inode);
		first_unused_inode = group * fs->super->s_inodes_per_group +
					1 + fs->super->s_inodes_per_group -
					ext2fs_bg_itable_unused(fs, group);
		cd->pctx.group = group;

		/*
		 * Check if the inode was missed out because
		 * _INODE_UNINIT flag was set or bg_itable_unused was
		 * incorrect.  If so, clear the _INODE_UNINIT flag and
		 * restart e2fsck.  In the future it would be nice if
		 * we could call a function in pass1.c that checks the
		 * newly visible inodes.
		 */
		if (ext2fs_bg_flags_test(fs, group, EXT2_BG_INODE_UNINIT)) {
			pctx.num = dirent->inode;
			if (fix_problem(ctx, PR_2_INOREF_BG_INO_UNINIT,
					&cd->pctx)){
				ext2fs_bg_flags_clear(fs, group,
						      EXT2_BG_INODE_UNINIT);
				ext2fs_mark_super_dirty(fs);
				ctx->flags |= E2F_FLAG_RESTART_LATER;
			} else {
				ext2fs_unmark_valid(fs);
				if (problem == PR_2_BAD_INO)
					goto next;
			}
		} else if (dirent->inode >= first_unused_inode) {
			pctx.num = dirent->inode;
			if (fix_problem(ctx, PR_2_INOREF_IN_UNUSED, &cd->pctx)){
				ext2fs_bg_itable_unused_set(fs, group, 0);
				ext2fs_mark_super_dirty(fs);
				ctx->flags |= E2F_FLAG_RESTART_LATER;
			} else {
				ext2fs_unmark_valid(fs);
				if (problem == PR_2_BAD_INO)
					goto next;
			}
		}

		/* 
		 * Offer to clear unused inodes; if we are going to be
		 * restarting the scan due to bg_itable_unused being
		 * wrong, then don't clear any inodes to avoid zapping
		 * inodes that were skipped during pass1 due to an
		 * incorrect bg_itable_unused; we'll get any real
		 * problems after we restart.
		 */
		if (!(ctx->flags & E2F_FLAG_RESTART_LATER) &&
		    !(ext2fs_test_inode_bitmap2(ctx->inode_used_map,
						dirent->inode)))
			problem = PR_2_UNUSED_INODE;

		if (problem) {
			if (fix_problem(ctx, problem, &cd->pctx)) {
				dirent->inode = 0;
				dir_modified++;
				goto next;
			} else {
				ext2fs_unmark_valid(fs);
				if (problem == PR_2_BAD_INO)
					goto next;
			}
		}

		if (check_name(ctx, dirent, ino, &cd->pctx))
			dir_modified++;

		if (check_filetype(ctx, dirent, ino, &cd->pctx))
			dir_modified++;

#ifdef ENABLE_HTREE
		if (dx_db) {
			ext2fs_dirhash(dx_dir->hashversion, dirent->name,
				       (dirent->name_len & 0xFF),
				       fs->super->s_hash_seed, &hash, 0);
			if (hash < dx_db->min_hash)
				dx_db->min_hash = hash;
			if (hash > dx_db->max_hash)
				dx_db->max_hash = hash;
		}
#endif

		/*
		 * If this is a directory, then mark its parent in its
		 * dir_info structure.  If the parent field is already
		 * filled in, then this directory has more than one
		 * hard link.  We assume the first link is correct,
		 * and ask the user if he/she wants to clear this one.
		 */
		if ((dot_state > 1) &&
		    (ext2fs_test_inode_bitmap2(ctx->inode_dir_map,
					      dirent->inode))) {
			if (e2fsck_dir_info_get_parent(ctx, dirent->inode,
						       &subdir_parent)) {
				cd->pctx.ino = dirent->inode;
				fix_problem(ctx, PR_2_NO_DIRINFO, &cd->pctx);
				goto abort_free_dict;
			}
			if (subdir_parent) {
				cd->pctx.ino2 = subdir_parent;
				if (fix_problem(ctx, PR_2_LINK_DIR,
						&cd->pctx)) {
					dirent->inode = 0;
					dir_modified++;
					goto next;
				}
				cd->pctx.ino2 = 0;
			} else {
				(void) e2fsck_dir_info_set_parent(ctx,
						  dirent->inode, ino);
			}
		}

		if (dups_found) {
			;
		} else if (dict_lookup(&de_dict, dirent)) {
			clear_problem_context(&pctx);
			pctx.ino = ino;
			pctx.dirent = dirent;
			fix_problem(ctx, PR_2_REPORT_DUP_DIRENT, &pctx);
			e2fsck_rehash_dir_later(ctx, ino);
			dups_found++;
		} else
			dict_alloc_insert(&de_dict, dirent, dirent);

		ext2fs_icount_increment(ctx->inode_count, dirent->inode,
					&links);
		if (links > 1)
			ctx->fs_links_count++;
		ctx->fs_total_count++;
	next:
		prev = dirent;
		if (dir_modified)
			(void) ext2fs_get_rec_len(fs, dirent, &rec_len);
		offset += rec_len;
		dot_state++;
	} while (offset < fs->blocksize - de_csum_size);
#if 0
	printf("\n");
#endif
#ifdef ENABLE_HTREE
	if (dx_db) {
#ifdef DX_DEBUG
		printf("db_block %d, type %d, min_hash 0x%0x, max_hash 0x%0x\n",
		       db->blockcnt, dx_db->type,
		       dx_db->min_hash, dx_db->max_hash);
#endif
		cd->pctx.dir = cd->pctx.ino;
		if ((dx_db->type == DX_DIRBLOCK_ROOT) ||
		    (dx_db->type == DX_DIRBLOCK_NODE))
			parse_int_node(fs, db, cd, dx_dir, buf, failed_csum);
	}
#endif /* ENABLE_HTREE */

	if (offset != fs->blocksize - de_csum_size) {
		cd->pctx.num = rec_len - (fs->blocksize - de_csum_size) +
			       offset;
		if (fix_problem(ctx, PR_2_FINAL_RECLEN, &cd->pctx)) {
			dirent->rec_len = cd->pctx.num;
			dir_modified++;
		}
	}
	if (dir_modified) {
		/* leaf block with no tail?  Rehash dirs later. */
		if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
				EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
		    is_leaf &&
		    !ext2fs_dirent_has_tail(fs, (struct ext2_dir_entry *)buf))
			e2fsck_rehash_dir_later(ctx, ino);

write_and_fix:
		if (e2fsck_dir_will_be_rehashed(ctx, ino))
			ctx->fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
		cd->pctx.errcode = ext2fs_write_dir_block4(fs, block_nr, buf,
							   0, ino);
		if (e2fsck_dir_will_be_rehashed(ctx, ino))
			ctx->fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
		if (cd->pctx.errcode) {
			if (!fix_problem(ctx, PR_2_WRITE_DIRBLOCK,
					 &cd->pctx))
				goto abort_free_dict;
		}
		ext2fs_mark_changed(fs);
	} else if (is_leaf && failed_csum && !dir_modified) {
		/*
		 * If a leaf node that fails csum makes it this far without
		 * alteration, ask the user if the checksum should be fixed.
		 */
		if (fix_problem(ctx, PR_2_LEAF_NODE_ONLY_CSUM_INVALID,
				&cd->pctx))
			goto write_and_fix;
	}
	dict_free_nodes(&de_dict);
	return 0;
abort_free_dict:
	ctx->flags |= E2F_FLAG_ABORT;
	dict_free_nodes(&de_dict);
	return DIRENT_ABORT;
}
int main(int argc, char **argv){
    if (argc < 2) return 0;
    return check_name(&argv[1]);
}
Ejemplo n.º 25
0
/* check handling of comments
 */
void
test_comments (void)
{
  gchar **names;
  gsize len;
  GError *error = NULL;
  gchar *comment;

  const gchar *data = 
    "# top comment\n"
    "# top comment, continued\n"
    "[group1]\n"
    "key1 = value1\n"
    "# key comment\n"
    "# key comment, continued\n"
    "key2 = value2\n"
    "# line end check\r\n"
    "key3 = value3\n"
    "key4 = value4\n"
    "# group comment\n"
    "# group comment, continued\n"
    "[group2]\n";

  const gchar *top_comment= " top comment\n top comment, continued\n";
  const gchar *group_comment= " group comment\n group comment, continued\n";
  const gchar *key_comment= " key comment\n key comment, continued\n";
  
  cut_assert (g_key_file_load_from_data (keyfile, data, -1, 0, NULL));

  check_string_value (keyfile, "group1", "key1", "value1");
  check_string_value (keyfile, "group1", "key2", "value2");
  check_string_value (keyfile, "group1", "key3", "value3");
  check_string_value (keyfile, "group1", "key4", "value4");

  names = g_key_file_get_keys (keyfile, "group1", &len, &error);
  check_no_error (error);

  check_length ("keys", g_strv_length (names), len, 4);
  check_name ("key", names[0], "key1", 0);
  check_name ("key", names[1], "key2", 1);
  check_name ("key", names[2], "key3", 2);
  check_name ("key", names[3], "key4", 3);

  g_strfreev (names);

  g_key_file_free (keyfile);

  keyfile = g_key_file_new ();
  cut_assert (g_key_file_load_from_data (keyfile, data, -1, G_KEY_FILE_KEEP_COMMENTS, NULL));

  names = g_key_file_get_keys (keyfile, "group1", &len, &error);
  check_no_error (error);

  check_length ("keys", g_strv_length (names), len, 4);
  check_name ("key", names[0], "key1", 0);
  check_name ("key", names[1], "key2", 1);
  check_name ("key", names[2], "key3", 2);
  check_name ("key", names[3], "key4", 3);

  g_strfreev (names);

  comment = g_key_file_get_comment (keyfile, NULL, NULL, &error);
  check_no_error (error);
  check_name ("top comment", comment, top_comment, 0);
  g_free (comment);

  comment = g_key_file_get_comment (keyfile, "group1", "key2", &error);
  check_no_error (error);
  check_name ("key comment", comment, key_comment, 0);
  g_free (comment);

  comment = g_key_file_get_comment (keyfile, "group2", NULL, &error);
  check_no_error (error);
  check_name ("group comment", comment, group_comment, 0);
  g_free (comment);

  comment = g_key_file_get_comment (keyfile, "group3", NULL, &error);
  check_error (&error, 
	       G_KEY_FILE_ERROR,
	       G_KEY_FILE_ERROR_GROUP_NOT_FOUND);
  cut_assert_null (comment);
}
Ejemplo n.º 26
0
int nss_check_user(const char *full_name)
{
	return check_name(full_name, cmd_checkuser);
}
Ejemplo n.º 27
0
struct dentry *
cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
	    unsigned int flags)
{
	unsigned int xid;
	int rc = 0; /* to get around spurious gcc warning, set to zero here */
	struct cifs_sb_info *cifs_sb;
	struct tcon_link *tlink;
	struct cifs_tcon *pTcon;
	struct inode *newInode = NULL;
	char *full_path = NULL;

	xid = get_xid();

	cifs_dbg(FYI, "parent inode = 0x%p name is: %s and dentry = 0x%p\n",
		 parent_dir_inode, direntry->d_name.name, direntry);

	/* check whether path exists */

	cifs_sb = CIFS_SB(parent_dir_inode->i_sb);
	tlink = cifs_sb_tlink(cifs_sb);
	if (IS_ERR(tlink)) {
		free_xid(xid);
		return (struct dentry *)tlink;
	}
	pTcon = tlink_tcon(tlink);

	rc = check_name(direntry);
	if (rc)
		goto lookup_out;

	/* can not grab the rename sem here since it would
	deadlock in the cases (beginning of sys_rename itself)
	in which we already have the sb rename sem */
	full_path = build_path_from_dentry(direntry);
	if (full_path == NULL) {
		rc = -ENOMEM;
		goto lookup_out;
	}

	if (direntry->d_inode != NULL) {
		cifs_dbg(FYI, "non-NULL inode in lookup\n");
	} else {
		cifs_dbg(FYI, "NULL inode in lookup\n");
	}
	cifs_dbg(FYI, "Full path: %s inode = 0x%p\n",
		 full_path, direntry->d_inode);

	if (pTcon->unix_ext) {
		rc = cifs_get_inode_info_unix(&newInode, full_path,
					      parent_dir_inode->i_sb, xid);
	} else {
		rc = cifs_get_inode_info(&newInode, full_path, NULL,
				parent_dir_inode->i_sb, xid, NULL);
	}

	if ((rc == 0) && (newInode != NULL)) {
		d_add(direntry, newInode);
		/* since paths are not looked up by component - the parent
		   directories are presumed to be good here */
		renew_parental_timestamps(direntry);

	} else if (rc == -ENOENT) {
		rc = 0;
		direntry->d_time = jiffies;
		d_add(direntry, NULL);
	/*	if it was once a directory (but how can we tell?) we could do
		shrink_dcache_parent(direntry); */
	} else if (rc != -EACCES) {
		cifs_dbg(VFS, "Unexpected lookup error %d\n", rc);
		/* We special case check for Access Denied - since that
		is a common return code */
	}

lookup_out:
	kfree(full_path);
	cifs_put_tlink(tlink);
	free_xid(xid);
	return ERR_PTR(rc);
}
Ejemplo n.º 28
0
void SDFFSEset::check() {
  SDFFparser* parser=emanager->get_parser();
  channelManager* cmanager=parser->get_cmanager();
  if (check_name(parser, cmanager) ) {
  }
};