Exemple #1
0
static void
usage_check(struct windows_acl_info *w)
{
	if (w->path == NULL)
		errx(EX_USAGE, "no path specified");

	if (!WA_OP_CHECK(w->flags, ~WA_OP_SET) &&
		w->dacl == NULL && w->facl == NULL)
		errx(EX_USAGE, "nothing to do");

	if (w->flags & WA_REMOVE) {
		if (w->index < 0)
			errx(EX_USAGE, "remove specified without index");

	} else if (WA_OP_CHECK(w->flags, ~WA_OP_SET) &&
		w->dacl == NULL && w->facl == NULL && !(w->flags & WA_RESET)) {
		errx(EX_USAGE, "no entries specified and not resetting");
	}
}
Exemple #2
0
int
main(int argc, char **argv)
{
	int ch;
	struct windows_acl_info *w;

	if (argc < 2)
		usage(argv[0]);

	w = new_windows_acl_info();
	w->flags = (WA_FILES|WA_DIRECTORIES);

	while ((ch = getopt(argc, argv, "a:o:g:e:O:G:p:i:fdrvx")) != -1) {
		switch (ch) {
			case 'a': {
				int action = get_action(optarg);
				if (action == WA_NULL)
					errx(EX_USAGE, "invalid action");
				if (WA_OP_CHECK(w->flags, action))
					errx(EX_USAGE, "only one action can be specified");
				w->flags |= action;
				break;
			}

			case 'o':
				setarg(&w->owner_entry, optarg);
				break;

			case 'g':
				setarg(&w->group_entry, optarg);
				break;

			case 'e':
				setarg(&w->everyone_entry, optarg);
				break;

			case 'O': {
				struct passwd *p = getpwnam(optarg);
				if (p == NULL)
					errx(EX_OSERR, "getpwnam() failed");
				w->uid = p->pw_uid;
				break;
			}

			case 'G': {
				struct group *g = getgrnam(optarg);
				if (g == NULL)
					errx(EX_OSERR, "getgrnam() failed");
				w->gid = g->gr_gid;
				break;
			}

			case 'p':
				setarg(&w->path, optarg);
				break;

			case 'i':
				w->index = strtol(optarg, NULL, 10);
				break;

			case 'f':
				w->flags &= ~WA_DIRECTORIES;
				break;

			case 'd':
				w->flags &= ~WA_FILES;
				break;

			case 'r':
				w->flags |= WA_RECURSIVE;
				break;

			case 'v':
				w->flags |= WA_VERBOSE;
				break;

			case 'x':
				w->flags |= WA_DOSATTRIB;
				break;

			case '?':
			default:
				usage(argv[0]);
		}
	}

	make_acls(w);
	usage_check(w);
	set_windows_acls(w);

	free_windows_acl_info(w);
	return (0);
}