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
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.
12 /* Copyright 2015, Richard Lowe. */
23 #include <sys/procset.h>
24 #include <sys/syscall.h>
25 #include <sys/secflags.h>
27 extern int __psecflagsset(procset_t
*, psecflagwhich_t
, secflagdelta_t
*);
30 psecflags(idtype_t idtype
, id_t id
, psecflagwhich_t which
,
31 secflagdelta_t
*delta
)
35 setprocset(&procset
, POP_AND
, idtype
, id
, P_ALL
, 0);
37 return (__psecflagsset(&procset
, which
, delta
));
41 secflags_parse(const secflagset_t
*defaults
, const char *flags
,
46 boolean_t current
= B_FALSE
;
48 /* Guarantee a clean base */
49 bzero(ret
, sizeof (*ret
));
51 if ((ss
= s
= strdup(flags
)) == NULL
)
52 return (-1); /* errno set for us */
55 while ((flag
= strsep(&s
, ",")) != NULL
) {
57 boolean_t del
= B_FALSE
;
59 if (strcasecmp(flag
, "default") == 0) {
60 if (defaults
!= NULL
) {
61 secflags_union(&ret
->psd_add
, defaults
);
68 } else if (strcasecmp(flag
, "all") == 0) {
69 secflags_fullset(&ret
->psd_add
);
71 } else if (strcasecmp(flag
, "none") == 0) {
72 secflags_fullset(&ret
->psd_rem
);
74 } else if (strcasecmp(flag
, "current") == 0) {
79 if ((flag
[0] == '-') || (flag
[0] == '!')) {
82 } else if (flag
[0] == '+') {
86 if ((secflag_by_name(flag
, &sf
)) != B_TRUE
) {
93 secflag_set(&(ret
->psd_rem
), sf
);
95 secflag_set(&(ret
->psd_add
), sf
);
99 * If we're not using the current flags, this is strict assignment.
103 secflags_copy(&ret
->psd_assign
, &ret
->psd_add
);
104 secflags_difference(&ret
->psd_assign
, &ret
->psd_rem
);
105 ret
->psd_ass_active
= B_TRUE
;
106 secflags_zero(&ret
->psd_add
);
107 secflags_zero(&ret
->psd_rem
);