Created
June 11, 2011 22:24
copy ACL from source to target
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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