Esempio n. 1
0
int acl_read2(maildir_aclt_list *l,
	      struct maildir_info *minfo,
	      char **owner)
{
	int rc;
	char *p;

	if (minfo->mailbox_type == MAILBOXTYPE_OLDSHARED)
	{
		/* Legacy shared., punt. */

		maildir_aclt_list_init(l);
		if (maildir_aclt_list_add(l, "anyone",
					  ACL_LOOKUP ACL_READ
					  ACL_SEEN ACL_WRITE
					  ACL_INSERT
					  ACL_DELETEMSGS ACL_EXPUNGE, NULL) < 0
		    || (*owner=strdup("vendor=courier.internal")) == NULL)
		{
			maildir_aclt_list_destroy(l);
			return -1;
		}
		return 0;
	}

	if (minfo->homedir == NULL || minfo->maildir == NULL)
		return -1;

	p=maildir_name2dir(".", minfo->maildir);

	if (!p)
		return -1;

	rc=maildir_acl_read(l, minfo->homedir,
			    strncmp(p, "./", 2) == 0 ? p+2:p);
	free(p);
	if (owner && rc == 0)
	{
		*owner=minfo->owner;
		minfo->owner=NULL;
	}
	return rc;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	const char *cmd;
	const char *maildir;
	const char *folder;

	if (argc < 3)
		usage();

	cmd=argv[1];

	if (strcmp(cmd, resetcmd) &&
	    strcmp(cmd, listcmd) &&
	    strcmp(cmd, setcmd) &&
	    strcmp(cmd, deletecmd) &&
	    strcmp(cmd, computecmd))
		usage();

	maildir=argv[2];

	if (strcmp(cmd, resetcmd) == 0)
	{
		if (maildir_acl_reset(maildir))
		{
			perror(maildir);
			exit(1);
		}
		exit(0);
	}

	if (argc < 4)
		usage();

	folder=argv[3];

	if (strcmp(folder, INBOX) &&
	    strncmp(folder, INBOX ".", sizeof(INBOX ".")-1))
	{
		errno=EINVAL;
		perror(folder);
		exit(1);
	}
	folder += sizeof(INBOX)-1;

	if (!*folder)
		folder=".";

	if (strcmp(cmd, listcmd) == 0)
	{
		maildir_aclt_list l;

		if (maildir_acl_read(&l, maildir, folder) ||
		    maildir_aclt_list_enum(&l, acl_list, NULL))
		{
			perror(maildir);
			exit(1);
		}

		maildir_aclt_list_destroy(&l);
		exit(0);
	}

	if (strcmp(cmd, setcmd) == 0)
	{
		maildir_aclt_list l;
		maildir_aclt a;

		const char *identifier;
		const char *rights;
		const char *err_failedrights;

		if (argc < 6)
			usage();

		identifier=argv[4];
		rights=argv[5];

		if (maildir_acl_read(&l, maildir, folder))
		{
			perror(maildir);
			exit(1);
		}

		if (*rights == '+')
		{
			if (maildir_aclt_init(&a, NULL,
					      maildir_aclt_list_find(&l,
								     identifier
								     )) ||
			    maildir_aclt_add(&a, rights+1, NULL))
			{
				perror(argv[0]);
				exit(1);
			}
		} else if (*rights == '-')
		{
			if (maildir_aclt_init(&a, NULL,
					      maildir_aclt_list_find(&l,
								     identifier
								     )) ||
			    maildir_aclt_del(&a, rights+1, NULL))
			{
				perror(argv[0]);
				exit(1);
			}
		}
		else if (maildir_aclt_init(&a, rights, NULL))
		{
			perror(argv[0]);
			exit (1);
		}

		if (maildir_aclt_list_add(&l, identifier, NULL, &a))
		{
			perror(argv[0]);
			exit(1);
		}

		if (maildir_acl_write(&l, maildir, folder, "owner",
				      &err_failedrights))
		{
			if (err_failedrights)
			{
				fprintf(stderr,
					"Trying to set invalid access"
					" rights for %s\n",
					err_failedrights);
			}
			else perror(maildir);
			exit(1);
		}
	}

	if (strcmp(cmd, deletecmd) == 0)
	{
		maildir_aclt_list l;
		const char *identifier;
		const char *err_failedrights;

		if (argc < 5)
			usage();

		identifier=argv[4];

		if (maildir_acl_read(&l, maildir, folder))
		{
			perror(maildir);
			exit(1);
		}

		if (maildir_aclt_list_del(&l, identifier))
		{
			perror(maildir);
			exit(1);
		}

		if (maildir_acl_write(&l, maildir, folder, "owner",
				      &err_failedrights))
		{
			if (err_failedrights)
			{
				fprintf(stderr,
					"Trying to set invalid access"
					" rights for %s\n",
					err_failedrights);
			}
			else perror(maildir);
			exit(1);
		}
	}

	if (strcmp(cmd, computecmd) == 0)
	{
		maildir_aclt_list l;
		maildir_aclt a;

		struct computeinfo ci;

		ci.argc=argc;
		ci.argv=argv;

		if (argc < 5)
			usage();

		if (maildir_acl_read(&l, maildir, folder))
		{
			perror(maildir);
			exit(1);
		}

		if (maildir_acl_compute(&a, &l, isme, &ci))
		{
			perror(maildir);
			exit(1);
		}

		printf("%s\n", maildir_aclt_ascstr(&a));
	}

	return (0);
}