HP-UX Reference (11i v2 04/09) - 3 Library Functions N-Z (vol 7)

s
strtoacl(3C) strtoacl(3C)
strtoaclpatt()
also sets values in global array aclentrystart[]
to point to the start of each pat-
tern entry it parsed in string , in some cases including leading or trailing whitespace. It only sets a
number of pointers equal to its return value plus one (never more than
NACLENTRIES + 1). The last
valid element points to the null character at the end of string. After calling
strtoaclpatt()
, an entry
pattern’s corresponding input string can be used by the caller for error reporting by (temporarily) putting
a null at the start of the next entry pattern in string .
ERRORS
If an error occurs,
strtoacl() and strtoaclpatt()
return a negative value and the content of
acl
is undefined (was probably altered). To help with error reporting in this case,
aclentrystart[0]
and
aclentrystart[1]
are set to point to the start of the current and next entries, respectively, being
parsed when the error occurred. If the current entry does not start with
(, aclentrystart[1]
points
to the next null character or comma at or after
aclentrystart[0]
. Otherwise, it points to the next
null, or to the character following the next
).
The following values are returned in case of error:
1 Syntax error: entry doesnt start with
( as expected in short form.
2 Syntax error: entry doesnt end with
) as expected in short form.
3 Syntax error: user name is not terminated by a dot.
4(
strtoacl() only) Syntax error: group name is not terminated by an operator in operator-
form input or a comma in short-form input.
5 Syntax error: user name is null.
6 Syntax error: group name is null.
7 Invalid user name (not found in
/etc/passwd file and not a valid number).
8 Invalid group name (not found in
/etc/group file and not a valid number).
9 Syntax error: invalid mode character, other than
0..7
, r, w, x, - (allowed in short form only),
* (allowed in patterns only), , (to end an entry in operator form), or ) (to end an entry in
short form). Or, 0..7 or * is followed by other mode characters.
10 The resulting ACL would have more than maxentries entries.
EXAMPLES
The following code fragment converts an ACL from a string to an array of entries using an fuid of 103 for
the file’s owner and fgid of 45 for the file’s group.
#include <acllib.h>
int nentries;
struct acl_entry acl [NACLENTRIES];
if ((nentries =
strtoacl (string, 0, NACLENTRIES, acl, 103, 45)) < 0)
error (...);
The following code gets the ACL, fuid, and fgid for file ../myfile, modifies the ACL using a descrip-
tion string, and changes the ACL on file ../myfile2 to be the new version.
#include <sys/types.h>
#include <sys/stat.h>
#include <acllib.h>
struct stat statbuf;
int nentries;
struct acl_entry acl [NACLENTRIES];
if (stat ("../myfile", & statbuf) < 0)
error (...);
if ((nentries = getacl ("../myfile", NACLENTRIES, acl)) < 0)
error (...);
if ((nentries = strtoacl (string, nentries, NACLENTRIES, acl,
statbuf.st_uid, statbuf.st_gid)) < 0)
{
Section 31028 Hewlett-Packard Company 3 HP-UX 11i Version 2: September 2004