Skip to content

Instantly share code, notes, and snippets.

@clee
Created June 11, 2011 22:24
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clee/1021032 to your computer and use it in GitHub Desktop.
Save clee/1021032 to your computer and use it in GitHub Desktop.
copy ACL from source to target
/*
cpacl.c: copy solaris ACLs from one file to another
author: Chris Lee <clee@mg8.org>
license: WTFPL <http://sam.zoy.org/wtfpl/COPYING>
make: cc -o cpacl cpacl.c -lsec -lc
*/
#include <sys/acl.h>
#include <stdio.h>
int main(int argc, char **argv) {
acl_t *aclp;
int i = 0, r = 0;
if (argc < 3) {
fprintf(stderr, "%s: error: invalid arguments\n\tusage: %s <source> <target> [target2, target3, ...]\n", argv[0], argv[0]);
return 2;
}
if (0 != acl_get(argv[1], 0, &aclp)) {
perror("Couldn't read ACL from source file");
return 3;
}
for (i = 2; i < argc; i++) {
if (0 == acl_set(argv[i], aclp)) {
continue;
}
char *message = malloc(32 + strlen(argv[i]) * sizeof(char));
snprintf(message, 32 + strlen(argv[i]), "Couldn't write ACL to target (%s)", argv[i]);
perror(message);
return 4;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment