Exemplo n.º 1
0
Arquivo: achown.c Projeto: jskDr/mc
static void
apply_advanced_chowns (struct stat *sf)
{
    vfs_path_t *vpath;
    char *lc_fname;
    gid_t a_gid = sf->st_gid;
    uid_t a_uid = sf->st_uid;

    lc_fname = current_panel->dir.list[current_file].fname;
    vpath = vfs_path_from_str (lc_fname);
    need_update = end_chown = TRUE;
    if (mc_chmod (vpath, get_mode ()) == -1)
        message (D_ERROR, MSG_ERROR, _("Cannot chmod \"%s\"\n%s"),
                 lc_fname, unix_error_string (errno));
    /* call mc_chown only, if mc_chmod didn't fail */
    else if (mc_chown (vpath, (ch_flags[9] == '+') ? sf->st_uid : (uid_t) (-1),
                       (ch_flags[10] == '+') ? sf->st_gid : (gid_t) (-1)) == -1)
        message (D_ERROR, MSG_ERROR, _("Cannot chown \"%s\"\n%s"),
                 lc_fname, unix_error_string (errno));
    do_file_mark (current_panel, current_file, 0);
    vfs_path_free (vpath);

    do
    {
        lc_fname = next_file ();
        vpath = vfs_path_from_str (lc_fname);

        if (mc_stat (vpath, sf) != 0)
        {
            vfs_path_free (vpath);
            break;
        }

        ch_cmode = sf->st_mode;

        if (mc_chmod (vpath, get_mode ()) == -1)
            message (D_ERROR, MSG_ERROR, _("Cannot chmod \"%s\"\n%s"),
                     lc_fname, unix_error_string (errno));
        /* call mc_chown only, if mc_chmod didn't fail */
        else if (mc_chown (vpath, (ch_flags[9] == '+') ? a_uid : (uid_t) (-1),
                           (ch_flags[10] == '+') ? a_gid : (gid_t) (-1)) == -1)
            message (D_ERROR, MSG_ERROR, _("Cannot chown \"%s\"\n%s"),
                     lc_fname, unix_error_string (errno));

        do_file_mark (current_panel, current_file, 0);
        vfs_path_free (vpath);
    }
    while (current_panel->marked != 0);
}
Exemplo n.º 2
0
static void
do_chown (uid_t u, gid_t g)
{
    if (mc_chown (current_panel->dir.list[current_file].fname, u, g) == -1)
        message (D_ERROR, MSG_ERROR, _("Cannot chown \"%s\"\n%s"),
                 current_panel->dir.list[current_file].fname, unix_error_string (errno));

    do_file_mark (current_panel, current_file, 0);
}
Exemplo n.º 3
0
Arquivo: chown.c Projeto: LubkaB/mc
static void
do_chown (uid_t u, gid_t g)
{
    vfs_path_t *vpath;

    vpath = vfs_path_from_str (current_panel->dir.list[current_file].fname);
    if (mc_chown (vpath, u, g) == -1)
        message (D_ERROR, MSG_ERROR, _("Cannot chown \"%s\"\n%s"),
                 current_panel->dir.list[current_file].fname, unix_error_string (errno));

    vfs_path_free (vpath);
    do_file_mark (current_panel, current_file, 0);
}
Exemplo n.º 4
0
static void apply_advanced_chowns (struct stat *sf)
{
    char *fname;
    gid_t a_gid = sf->st_gid;
    uid_t a_uid = sf->st_uid;

    fname = current_panel->dir.list[current_file].fname;
    need_update = end_chown = 1;
    if (mc_chmod (fname, get_mode ()) == -1)
	message (D_ERROR, MSG_ERROR, _(" Cannot chmod \"%s\" \n %s "),
		 fname, unix_error_string (errno));
    /* call mc_chown only, if mc_chmod didn't fail */
    else if (mc_chown (fname, (ch_flags[9] == '+') ? sf->st_uid : (uid_t) -1,
		       (ch_flags[10] == '+') ? sf->st_gid : (gid_t) -1) == -1)
	message (D_ERROR, MSG_ERROR, _(" Cannot chown \"%s\" \n %s "),
		 fname, unix_error_string (errno));
    do_file_mark (current_panel, current_file, 0);

    do {
	fname = next_file ();

	if (mc_stat (fname, sf) != 0)
	    break;
	ch_cmode = sf->st_mode;
	if (mc_chmod (fname, get_mode ()) == -1)
	    message (D_ERROR, MSG_ERROR, _(" Cannot chmod \"%s\" \n %s "),
		     fname, unix_error_string (errno));
	/* call mc_chown only, if mc_chmod didn't fail */
	else if (mc_chown (fname, (ch_flags[9] == '+') ? a_uid : (uid_t) -1,
	                   (ch_flags[10] == '+') ? a_gid : (gid_t) -1) == -1)
	    message (D_ERROR, MSG_ERROR, _(" Cannot chown \"%s\" \n %s "),
		     fname, unix_error_string (errno));

	do_file_mark (current_panel, current_file, 0);
    } while (current_panel->marked);
}
Exemplo n.º 5
0
Arquivo: chown.c Projeto: LubkaB/mc
void
chown_cmd (void)
{
    char *fname;
    struct stat sf_stat;
    uid_t new_user;
    gid_t new_group;
    char buffer[BUF_TINY];

    chown_i18n ();

    do
    {                           /* do while any files remaining */
        vfs_path_t *vpath;
        WDialog *ch_dlg;

        ch_dlg = init_chown ();
        new_user = new_group = -1;

        if (current_panel->marked)
            fname = next_file ();       /* next marked file */
        else
            fname = selection (current_panel)->fname;   /* single file */

        vpath = vfs_path_from_str (fname);
        if (mc_stat (vpath, &sf_stat) != 0)
        {                       /* get status of file */
            dlg_destroy (ch_dlg);
            vfs_path_free (vpath);
            break;
        }
        vfs_path_free (vpath);

        /* select in listboxes */
        listbox_select_entry (l_user, listbox_search_text (l_user, get_owner (sf_stat.st_uid)));
        listbox_select_entry (l_group, listbox_search_text (l_group, get_group (sf_stat.st_gid)));

        chown_label (0, str_trunc (fname, GW - 4));
        chown_label (1, str_trunc (get_owner (sf_stat.st_uid), GW - 4));
        chown_label (2, str_trunc (get_group (sf_stat.st_gid), GW - 4));
        size_trunc_len (buffer, GW - 4, sf_stat.st_size, 0, panels_options.kilobyte_si);
        chown_label (3, buffer);
        chown_label (4, string_perm (sf_stat.st_mode));

        switch (dlg_run (ch_dlg))
        {
        case B_CANCEL:
            end_chown = 1;
            break;

        case B_SETUSR:
            {
                struct passwd *user;
                char *text;

                listbox_get_current (l_user, &text, NULL);
                user = getpwnam (text);
                if (user)
                {
                    new_user = user->pw_uid;
                    apply_chowns (new_user, new_group);
                }
                break;
            }

        case B_SETGRP:
            {
                struct group *grp;
                char *text;

                listbox_get_current (l_group, &text, NULL);
                grp = getgrnam (text);
                if (grp)
                {
                    new_group = grp->gr_gid;
                    apply_chowns (new_user, new_group);
                }
                break;
            }

        case B_SETALL:
        case B_ENTER:
            {
                struct group *grp;
                struct passwd *user;
                char *text;

                listbox_get_current (l_group, &text, NULL);
                grp = getgrnam (text);
                if (grp)
                    new_group = grp->gr_gid;
                listbox_get_current (l_user, &text, NULL);
                user = getpwnam (text);
                if (user)
                    new_user = user->pw_uid;
                if (ch_dlg->ret_value == B_ENTER)
                {
                    vfs_path_t *fname_vpath;

                    fname_vpath = vfs_path_from_str (fname);
                    need_update = 1;
                    if (mc_chown (fname_vpath, new_user, new_group) == -1)
                        message (D_ERROR, MSG_ERROR, _("Cannot chown \"%s\"\n%s"),
                                 fname, unix_error_string (errno));
                    vfs_path_free (fname_vpath);
                }
                else
                    apply_chowns (new_user, new_group);
                break;
            }
        }                       /* switch */

        if (current_panel->marked && ch_dlg->ret_value != B_CANCEL)
        {
            do_file_mark (current_panel, current_file, 0);
            need_update = 1;
        }

        dlg_destroy (ch_dlg);
    }
    while (current_panel->marked && !end_chown);

    chown_done ();
}
Exemplo n.º 6
0
Arquivo: achown.c Projeto: jskDr/mc
void
chown_advanced_cmd (void)
{
    /* Number of files at startup */
    int files_on_begin;

    files_on_begin = MAX (1, current_panel->marked);

    do
    {                           /* do while any files remaining */
        int file_idx;
        char buffer[BUF_MEDIUM];
        vfs_path_t *vpath;
        int result;

        init_chown_advanced ();

        if (current_panel->marked)
            fname = next_file ();       /* next marked file */
        else
            fname = selection (current_panel)->fname;   /* single file */
        vpath = vfs_path_from_str (fname);

        if (mc_stat (vpath, sf_stat) != 0)
        {                       /* get status of file */
            dlg_destroy (ch_dlg);
            vfs_path_free (vpath);
            break;
        }

        ch_cmode = sf_stat->st_mode;

        file_idx = files_on_begin == 1 ? 1 : (files_on_begin - current_panel->marked + 1);
        g_snprintf (buffer, sizeof (buffer), "%s (%d/%d)",
                    str_fit_to_term (fname, WIDGET (ch_dlg)->cols - 20, J_LEFT_FIT),
                    file_idx, files_on_begin);
        label_set_text (l_filename, buffer);
        chown_refresh ();
        update_ownership ();

        result = dlg_run (ch_dlg);

        switch (result)
        {
        case B_CANCEL:
            end_chown = TRUE;
            break;

        case B_ENTER:
            need_update = TRUE;
            if (mc_chmod (vpath, get_mode ()) == -1)
                message (D_ERROR, MSG_ERROR, _("Cannot chmod \"%s\"\n%s"),
                         fname, unix_error_string (errno));
            /* call mc_chown only, if mc_chmod didn't fail */
            else if (mc_chown
                     (vpath, (ch_flags[9] == '+') ? sf_stat->st_uid : (uid_t) (-1),
                      (ch_flags[10] == '+') ? sf_stat->st_gid : (gid_t) (-1)) == -1)
                message (D_ERROR, MSG_ERROR, _("Cannot chown \"%s\"\n%s"), fname,
                         unix_error_string (errno));
            break;

        case B_SETALL:
            apply_advanced_chowns (sf_stat);
            break;

        case B_SKIP:
        default:
            break;
        }

        if (current_panel->marked && result != B_CANCEL)
        {
            do_file_mark (current_panel, current_file, 0);
            need_update = TRUE;
        }
        dlg_destroy (ch_dlg);
        vfs_path_free (vpath);
    }
    while (current_panel->marked && !end_chown);

    chown_advanced_done ();
}
Exemplo n.º 7
0
void
chown_cmd (void)
{
    char *fname;
    struct stat sf_stat;
    WLEntry *fe;
    Dlg_head *ch_dlg;
    uid_t new_user;
    gid_t new_group;
    char  buffer [BUF_TINY];

    do {			/* do while any files remaining */
	ch_dlg = init_chown ();
	new_user = new_group = -1;

	if (current_panel->marked)
	    fname = next_file ();	        /* next marked file */
	else
	    fname = selection (current_panel)->fname;	        /* single file */
	
	if (mc_stat (fname, &sf_stat) != 0) {	/* get status of file */
	    destroy_dlg (ch_dlg);
	    break;
	}
	
	/* select in listboxes */
	fe = listbox_search_text (l_user, get_owner(sf_stat.st_uid));
	if (fe)
	    listbox_select_entry (l_user, fe);
    
	fe = listbox_search_text (l_group, get_group(sf_stat.st_gid));
	if (fe)
	    listbox_select_entry (l_group, fe);

        chown_label (0, name_trunc (fname, 15));
        chown_label (1, name_trunc (get_owner (sf_stat.st_uid), 15));
	chown_label (2, name_trunc (get_group (sf_stat.st_gid), 15));
	size_trunc_len (buffer, 15, sf_stat.st_size, 0);
	chown_label (3, buffer);
	chown_label (4, string_perm (sf_stat.st_mode));

	run_dlg (ch_dlg);
    
	switch (ch_dlg->ret_value) {
	case B_CANCEL:
	    end_chown = 1;
	    break;
	    
	case B_SETUSR:
	{
	    struct passwd *user;

	    user = getpwnam (l_user->current->text);
	    if (user){
		new_user = user->pw_uid;
		apply_chowns (new_user, new_group);
	    }
	    break;
	}   
	case B_SETGRP:
	{
	    struct group *grp;

	    grp = getgrnam (l_group->current->text);
	    if (grp){
		new_group = grp->gr_gid;
		apply_chowns (new_user, new_group);
	    }
	    break;
	}
	case B_SETALL:
	case B_ENTER:
	{
	    struct group *grp;
	    struct passwd *user;
	    
	    grp = getgrnam (l_group->current->text);
	    if (grp)
		new_group = grp->gr_gid;
	    user = getpwnam (l_user->current->text);
	    if (user)
		new_user = user->pw_uid;
	    if (ch_dlg->ret_value==B_ENTER) {
		need_update = 1;
		if (mc_chown (fname, new_user, new_group) == -1)
		    message (1, MSG_ERROR, _(" Cannot chown \"%s\" \n %s "),
	 		 fname, unix_error_string (errno));
	    } else
		apply_chowns (new_user, new_group);
	    break;
	}
	}
	
	if (current_panel->marked && ch_dlg->ret_value != B_CANCEL){
	    do_file_mark (current_panel, current_file, 0);
	    need_update = 1;
	}
	destroy_dlg (ch_dlg);
    } while (current_panel->marked && !end_chown);
    
    chown_done ();
}
void
chown_cmd (void)
{
    char *fname;
    struct stat sf_stat;
    WLEntry *fe;
    uid_t new_user;
    gid_t new_group;
    char  buffer [15];

#if 0
    /* Please no */
    if (!vfs_current_is_local ()) {
	if (vfs_current_is_extfs ()) {
	    message (1, _(" Oops... "),
		     _(" I can't run the Chown command on an extfs "));
	    return;
	} else if (vfs_current_is_tarfs ()) {
	    message (1, _(" Oops... "),
		     _(" I can't run the Chown command on a tarfs "));
	    return;
	}
    }
#endif

    do {			/* do while any files remaining */
	init_chown ();
	new_user = new_group = -1;

	if (cpanel->marked)
	    fname = next_file ();	        /* next marked file */
	else
	    fname = selection (cpanel)->fname;	        /* single file */
	
	if (!stat_file (fname, &sf_stat)){	/* get status of file */
	    destroy_dlg (ch_dlg);
	    break;
	}
	
	/* select in listboxes */
	fe = listbox_search_text (l_user, get_owner(sf_stat.st_uid));
	if (fe)
	    listbox_select_entry (l_user, fe);
    
	fe = listbox_search_text (l_group, get_group(sf_stat.st_gid));
	if (fe)
	    listbox_select_entry (l_group, fe);

        chown_label (0, name_trunc (fname, 15));
        chown_label (1, name_trunc (get_owner (sf_stat.st_uid), 15));
	chown_label (2, name_trunc (get_group (sf_stat.st_gid), 15));
        sprintf (buffer, "%d", c_fsize);
	chown_label (3, buffer);
	chown_label (4, string_perm (sf_stat.st_mode));

	run_dlg (ch_dlg);
    
	switch (ch_dlg->ret_value) {
	case B_CANCEL:
	    end_chown = 1;
	    break;
	    
	case B_SETUSR:
	{
	    struct passwd *user;

	    user = getpwnam (l_user->current->text);
	    if (user){
		new_user = user->pw_uid;
		apply_chowns (new_user, new_group);
	    }
	    break;
	}   
	case B_SETGRP:
	{
	    struct group *grp;

	    grp = getgrnam (l_group->current->text);
	    if (grp){
		new_group = grp->gr_gid;
		apply_chowns (new_user, new_group);
	    }
	    break;
	}
	case B_SETALL:
	case B_ENTER:
	{
	    struct group *grp;
	    struct passwd *user;
	    
	    grp = getgrnam (l_group->current->text);
	    if (grp)
		new_group = grp->gr_gid;
	    user = getpwnam (l_user->current->text);
	    if (user)
		new_user = user->pw_uid;
	    if (ch_dlg->ret_value==B_ENTER) {
		need_update = 1;
		if (mc_chown (fname, new_user, new_group) == -1)
		    message (1, MSG_ERROR, _(" Couldn't chown \"%s\" \n %s "),
	 		 fname, unix_error_string (errno));
	    } else
		apply_chowns (new_user, new_group);
	    break;
	}
	}
	
	if (cpanel->marked && ch_dlg->ret_value != B_CANCEL){
	    do_file_mark (cpanel, current_file, 0);
	    need_update = 1;
	}
	destroy_dlg (ch_dlg);
    } while (cpanel->marked && !end_chown);
    
    chown_done ();
}
Exemplo n.º 9
0
void
chown_advanced_cmd (void)
{

    files_on_begin = current_panel->marked;

    do {			/* do while any files remaining */
	init_chown_advanced ();

	if (current_panel->marked)
	    fname = next_file ();	/* next marked file */
	else
	    fname = selection (current_panel)->fname;	/* single file */

	if (mc_stat (fname, sf_stat) != 0) {	/* get status of file */
	    destroy_dlg (ch_dlg);
	    break;
	}
	ch_cmode = sf_stat->st_mode;

	chown_refresh ();
	
	update_ownership ();

	/* game can begin */
	run_dlg (ch_dlg);

	switch (ch_dlg->ret_value) {
	case B_CANCEL:
	    end_chown = 1;
	    break;

	case B_ENTER:
	    need_update = 1;
	    if (mc_chmod (fname, get_mode ()) == -1)
		message (D_ERROR, MSG_ERROR, _(" Cannot chmod \"%s\" \n %s "),
			 fname, unix_error_string (errno));
	    /* call mc_chown only, if mc_chmod didn't fail */
	    else if (mc_chown (fname, (ch_flags[9] == '+') ? sf_stat->st_uid : (uid_t) -1,
	                       (ch_flags[10] == '+') ? sf_stat->st_gid : (gid_t) -1) == -1)
		message (D_ERROR, MSG_ERROR, _(" Cannot chown \"%s\" \n %s "),
			 fname, unix_error_string (errno));
	    break;
	case B_SETALL:
	    apply_advanced_chowns (sf_stat);
	    break;

	case B_SKIP:
	    break;

	}

	if (current_panel->marked && ch_dlg->ret_value != B_CANCEL) {
	    do_file_mark (current_panel, current_file, 0);
	    need_update = 1;
	}
	destroy_dlg (ch_dlg);
    } while (current_panel->marked && !end_chown);

    chown_advanced_done ();
}