예제 #1
0
파일: chmod.c 프로젝트: serjepatoff/vifm
TEST(reset_executable_bits_from_files_only, IF(not_osx))
{
	FILE *f;

	int perms[13]        = { 1, 1, 0, 0,  1, 1, 0, 0,  1, 1, 0, 0,  1 };
	int adv_perms[3]     = { 1, 1, 1 };
	int origin_perms[13] = { 1, 1, 1, 0,  1, 1, 1, 0,  1, 1, 1, 0,  1 };

	assert_success(os_mkdir(SANDBOX_PATH "/dir", 0777));

	assert_non_null(f = fopen(SANDBOX_PATH "/dir/file", "w"));
	fclose(f);
	assert_success(chmod(SANDBOX_PATH "/dir/file", 0777));

	if(get_perms(SANDBOX_PATH "/dir") != 0777 ||
			get_perms(SANDBOX_PATH "/dir/file") != 0777)
	{
		assert_success(unlink(SANDBOX_PATH "/dir/file"));
		assert_success(rmdir(SANDBOX_PATH "/dir"));
		return;
	}

	strcpy(lwin.curr_dir, SANDBOX_PATH);
	alloc_file_list(&lwin, "dir");
	set_perm_string(&lwin, perms, origin_perms, adv_perms);
	free_file_list(&lwin);

	assert_int_equal(perms_to_mode(perms), get_perms(SANDBOX_PATH "/dir/file"));
	assert_int_equal(0777, get_perms(SANDBOX_PATH "/dir"));

	assert_success(unlink(SANDBOX_PATH "/dir/file"));
	assert_success(rmdir(SANDBOX_PATH "/dir"));
}
예제 #2
0
파일: chmod.c 프로젝트: serjepatoff/vifm
static void
set_file_perms(const int perms[13])
{
	FILE *f;

	int origin_perms[13] = { 1, 1, 1, 0,  1, 1, 1, 0,  1, 1, 1, 0,  0 };
	int adv_perms[3]     = { 0, 0, 0 };

	assert_non_null(f = fopen(SANDBOX_PATH "/file", "w"));
	fclose(f);
	assert_success(chmod(SANDBOX_PATH "/file", 0777));

	if(get_perms(SANDBOX_PATH "/file") != 0777)
	{
		assert_success(unlink(SANDBOX_PATH "/file"));
		return;
	}

	strcpy(lwin.curr_dir, SANDBOX_PATH);
	alloc_file_list(&lwin, "file");
	set_perm_string(&lwin, perms, origin_perms, adv_perms);
	free_file_list(&lwin);

	assert_int_equal(perms_to_mode(perms), get_perms(SANDBOX_PATH "/file"));

	assert_success(unlink(SANDBOX_PATH "/file"));
}
예제 #3
0
   int excecute_lp()                                                          
{     
      int count,i;  
      struct direct **files;  
      struct stat statbuf;  
      char datestring[256];  
      struct passwd pwent;  
      struct passwd *pwentp;  
      struct group grp;  
      struct group *grpt;  
      struct tm time;  
      char buf[1024];  
  
      if(!getcwd(pathname, sizeof(pathname)))  
         die("Error getting pathnamen");  
  
      count = scandir(pathname, &files, file_selecto, alphasort);  
  
      if(count > 0)  
           {  
               printf("total %d\n",count);  
  
                  for (i=0; i<count; ++i)  
                   {  
                     if (stat(files[i]->d_name, &statbuf) == 0)  
                         {  
                                                                                            /* Print out type, permissions, and number of links. */  
                            printf("%10.10s", get_perms(statbuf.st_mode));                      /* File mode (type, perms) */       
                            printf(" %d", statbuf.st_nlink);                                     /* Number of links */
  
                            if (!getpwuid_r(statbuf.st_uid, &pwent, buf, sizeof(buf), &pwentp))  
                                printf(" %s", pwent.pw_name);  
                            else  
                                printf(" %d", statbuf.st_uid);                                       /* User ID of the file's owner */
  
                            if (!getgrgid_r (statbuf.st_gid, &grp, buf, sizeof(buf), &grpt))  
                                printf(" %s", grp.gr_name);  
                            else  
                                printf(" %d", statbuf.st_gid);                                       /* Group ID of the file's group */  
  
                                                                                                 /* Print size of file. */  
                            printf(" %5d", (int)statbuf.st_size);  
                                                                                  
                            localtime_r(&statbuf.st_mtime, &time);                               /* Time of last data modification */
                                                                                                 /* Get localized date string. */  
                            strftime(datestring, sizeof(datestring), "%F %T", &time);  
  
                            printf(" %s %s\n", datestring, files[i]->d_name);  
                         }  
  
                                      free (files[i]);  
                    }  
  
                                      free(files);  
           }                                                                                               
                                      exit(0);
}
예제 #4
0
    void main() {
        long ans = 0;

        // int A, B, C;
        // tie(A, B, C) = get_perms(1. / 12, 1. / 13, 1. / sqrt(14));
        // print("m = {}\n", m);
        // print("T = {}\n", count(A, B, C));

        for (int a = 9; a <= n; ++a) {
            for (int b = a + 1; b <= n; ++b) {
                for (int c = b + 1; c <= n; ++c) {
                    int A, B, C;
                    tie(A, B, C) = get_perms(1. / a, 1. / b, 1. / sqrt(c));
                    ans += count(A, B, C);
                    if (m > mx_top) {
                        mx_top = m;
                        print("max m = {}\n", mx_top);
                    }
                }
            }
        }
        print("ans = {}, TIME = {}\n", ans, TIME);
    }
예제 #5
0
int main(int argc, char **argv)
{
        char *end;
        struct identity_downcall_data *data = NULL;
        char procname[1024];
        unsigned long uid;
        int fd, rc = -EINVAL, size, maxgroups;

        progname = basename(argv[0]);
        if (argc != 3) {
                usage();
                goto out;
        }

        uid = strtoul(argv[2], &end, 0);
        if (*end) {
                errlog("%s: invalid uid '%s'\n", progname, argv[2]);
                goto out;
        }

        maxgroups = sysconf(_SC_NGROUPS_MAX);
        if (maxgroups > NGROUPS_MAX)
                maxgroups = NGROUPS_MAX;
	if (maxgroups == -1) {
		rc = -EINVAL;
		goto out;
	}

        size = offsetof(struct identity_downcall_data, idd_groups[maxgroups]);
        data = malloc(size);
        if (!data) {
                errlog("malloc identity downcall data(%d) failed!\n", size);
                rc = -ENOMEM;
                goto out;
        }

        memset(data, 0, size);
        data->idd_magic = IDENTITY_DOWNCALL_MAGIC;
        data->idd_uid = uid;
        /* get groups for uid */
        rc = get_groups_local(data, maxgroups);
        if (rc)
                goto downcall;

        size = offsetof(struct identity_downcall_data,
                        idd_groups[data->idd_ngroups]);
        /* read permission database */
        rc = get_perms(data);

downcall:
        if (getenv("L_GETIDENTITY_TEST")) {
                show_result(data);
                rc = 0;
                goto out;
        }

        snprintf(procname, sizeof(procname),
                 "/proc/fs/lustre/mdt/%s/identity_info", argv[1]);
        fd = open(procname, O_WRONLY);
        if (fd < 0) {
                errlog("can't open file %s: %s\n", procname, strerror(errno));
                rc = -1;
                goto out;
        }

        rc = write(fd, data, size);
        close(fd);
        if (rc != size) {
                errlog("partial write ret %d: %s\n", rc, strerror(errno));
                rc = -1;
        } else {
                rc = 0;
        }

out:
        if (data != NULL)
                free(data);
        return rc;
}
예제 #6
0
int main(int argc, char *argv[])
{
    char path[GPATH_MAX];
    int perms;			/* full mapset permissions */
    int group, other;		/* bool. want group/other permission */
    struct Option *group_opt, *other_opt;
    struct GModule *module;

    /* init the GRASS library */
    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("general"));
    G_add_keyword(_("map management"));
    G_add_keyword(_("permission"));
    module->label =
	_("Controls access to the current mapset for other users on the system.");
    module->description = _("If no option given, prints current status.");
    
    group_opt = G_define_option();
    group_opt->key = "group";
    group_opt->type = TYPE_STRING;
    group_opt->required = NO;
    group_opt->options = "grant,revoke";
    group_opt->description = _("Access for group");
    group_opt->guisection = _("Settings");

    other_opt = G_define_option();
    other_opt->key = "other";
    other_opt->type = TYPE_STRING;
    other_opt->required = NO;
    other_opt->options = "grant,revoke";
    other_opt->description = _("Access for others");
    other_opt->guisection = _("Settings");
    
    if (G_parser(argc, argv))
	exit(EXIT_FAILURE);

#ifdef __MINGW32__
    G_fatal_error(_("UNIX filesystem access controls are not supported by MS-Windows"));
#endif

    /* get the unix file name for the mapset directory */
    G_file_name(path, "", "", G_mapset());

    /* this part is until PERMANENT no longer holds DEFAULT_WIND and MYNAME */
    if (strcmp(G_mapset(), "PERMANENT") == 0)
	G_fatal_error(_("Access to the PERMANENT mapset must be open, nothing changed"));

    /* get the current permissions */
    if (get_perms(path, &perms, &group, &other) < 0)
	G_fatal_error(_("Unable to determine mapset permissions"));

    if (group_opt->answer) {
	if (group_opt->answer[0] == 'g')
	    group = 1;
	else
	    group = 0;
    }
    if (other_opt->answer) {
	if (other_opt->answer[0] == 'g')
	    other = 1;
	else
	    other = 0;
    }

    set_perms(path, perms, group, other);

    exit(EXIT_SUCCESS);
}