xref: /illumos-gate/usr/src/test/libsec-tests/cmd/acl_to_text.c (revision 9b9d39d2a32ff806d2431dbcc50968ef1e6d46b2)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2024 RackTop Systems, Inc.
14  */
15 
16 /*
17  * Test program for libsec:acl_totext
18  */
19 
20 #include <sys/types.h>
21 #include <sys/acl.h>
22 
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <errno.h>
28 #include <unistd.h>
29 
30 extern char *acl_strerror(int);
31 extern acl_t acl_canned;
32 
33 int
34 main(int argc, char **argv)
35 {
36 	acl_t	*aclp = &acl_canned;
37 	char	*str;
38 	char	*p;
39 	int flags = 0;
40 	int c;
41 
42 	while ((c = getopt(argc, argv, "cns")) != -1) {
43 		switch ((char)c) {
44 		case 'c':
45 			flags |= ACL_COMPACT_FMT;
46 			break;
47 		case 'n':
48 			flags |= ACL_NORESOLVE;
49 			break;
50 		case 's':
51 			flags |= ACL_SID_FMT;
52 			break;
53 
54 		case '?':
55 			fprintf(stderr, "usage: %s [-cns]\n", argv[0]);
56 			break;
57 		}
58 	}
59 
60 	str = acl_totext(aclp, flags);
61 	if (str == NULL) {
62 		fprintf(stderr, "acl_totext returned NULL\n");
63 		return (1);
64 	}
65 
66 	/*
67 	 * These are hard to read as one line, so let's
68 	 * convert all the commas to newlines.
69 	 */
70 	for (p = str; *p != '\0'; p++) {
71 		if (*p == ',')
72 			*p = '\n';
73 	}
74 
75 	printf("%s\n", str);
76 	free(str);
77 
78 	return (0);
79 }
80