Open System Services System Calls Reference Manual (G06.29+, H06.08+, J06.03+)

acl(5) OSS System Calls Reference Manual
* If you run this program twice on the same file, it will report
* an error in aclsort() as you are trying to add a second group ACL entry
* for the same group id. aclsort() points to the ACL entry in error.
*/
#include <stdlib.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <acl.h>
#include <errno.h>
#define READPERM 4
#define CALCCLASS 1
typedef struct acl acl_t;
void printAcl( char *header, acl_t *aclEnt, int count )
{
int i;
printf("%s\n",header);
for (i= 0; i < count; i++) {
printf("acl entry %d ", i);
printf("\ta_type = %d ", aclEnt[i].a_type );
printf("\ta_id = %d ", aclEnt[i].a_id );
printf("\ta_perm = %o\n", aclEnt[i].a_perm );
}
}
main( int argc, char *argv[])
{
acl_t *aclEnt = 0; /* pointer to ACL buffer */
char *pathname = 0; /* pointer to pathanme */
int prevCount, newCount; /* counts of ACL entries */
int groupId; /* group ID number for new ACL entry */
int error; /* error variable */
pathname = argv[1]; /* get ptr to pathname command argument */
groupId = atoi(argv[2]); /* get groupId command argument value */
printf("Input pathname = %s, input groupId = %d\n", pathname, groupId);
/* find out how many ACL entries in the existing ACL on the object */
if (( prevCount = acl(pathname, ACL_CNT, NACLENTRIES, aclEnt)) == -1 ) {
printf("acl(ACL_CNT) error= %d, text = %s\n", errno, strerror(errno));
return 1;
}
printf("Number of ACL entries = %d\n", prevCount);
/* Allocate space, reserving 1 extra ACL entry for the new GROUP entry */
newCount = prevCount + 1;
if (( aclEnt = (acl_t *) malloc( newCount * sizeof(acl_t))) ==0){
printf("malloc error= %d, text = %s\n", errno, strerror(errno));
return 1;
}
/* Acquire the existing ACL on the object */
if ((prevCount = acl(pathname, ACL_GET, prevCount, aclEnt)) == -1 ) {
printf("acl(ACL_GET) error= %d, text = %s\n", errno, strerror(errno));
free(aclEnt);
1214 Hewlett-Packard Company 527186-023