4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
38 psexp_create(psexp_t
*psexp
)
40 idtab_create(&psexp
->ps_euids
);
41 idtab_create(&psexp
->ps_ruids
);
42 idtab_create(&psexp
->ps_rgids
);
43 idtab_create(&psexp
->ps_ppids
);
44 idtab_create(&psexp
->ps_pgids
);
45 idtab_create(&psexp
->ps_sids
);
46 idtab_create(&psexp
->ps_ttys
);
47 idtab_create(&psexp
->ps_projids
);
48 idtab_create(&psexp
->ps_taskids
);
49 idtab_create(&psexp
->ps_zoneids
);
50 idtab_create(&psexp
->ps_ctids
);
56 psexp_destroy(psexp_t
*psexp
)
58 idtab_destroy(&psexp
->ps_euids
);
59 idtab_destroy(&psexp
->ps_ruids
);
60 idtab_destroy(&psexp
->ps_rgids
);
61 idtab_destroy(&psexp
->ps_ppids
);
62 idtab_destroy(&psexp
->ps_pgids
);
63 idtab_destroy(&psexp
->ps_sids
);
64 idtab_destroy(&psexp
->ps_ttys
);
65 idtab_destroy(&psexp
->ps_projids
);
66 idtab_destroy(&psexp
->ps_taskids
);
67 idtab_destroy(&psexp
->ps_zoneids
);
68 idtab_destroy(&psexp
->ps_ctids
);
71 regfree(&psexp
->ps_reg
);
75 psexp_compile(psexp_t
*psexp
)
81 idtab_sort(&psexp
->ps_euids
);
82 idtab_sort(&psexp
->ps_ruids
);
83 idtab_sort(&psexp
->ps_rgids
);
84 idtab_sort(&psexp
->ps_ppids
);
85 idtab_sort(&psexp
->ps_pgids
);
86 idtab_sort(&psexp
->ps_sids
);
87 idtab_sort(&psexp
->ps_ttys
);
88 idtab_sort(&psexp
->ps_projids
);
89 idtab_sort(&psexp
->ps_taskids
);
90 idtab_sort(&psexp
->ps_zoneids
);
91 idtab_sort(&psexp
->ps_ctids
);
93 if (psexp
->ps_pat
!= NULL
) {
94 if ((err
= regcomp(&psexp
->ps_reg
, psexp
->ps_pat
,
95 REG_EXTENDED
)) != 0) {
97 nbytes
= regerror(err
, &psexp
->ps_reg
, NULL
, 0);
98 buf
= alloca(nbytes
+ 1);
99 (void) regerror(err
, &psexp
->ps_reg
, buf
, nbytes
);
100 (void) strcat(buf
, "\n");
109 #define NOMATCH(__f1, __f2) \
110 psexp->__f1.id_data && !idtab_search(&psexp->__f1, psinfo->__f2)
113 psexp_match(psexp_t
*psexp
, psinfo_t
*psinfo
, int flags
)
118 if (NOMATCH(ps_euids
, pr_euid
))
120 if (NOMATCH(ps_ruids
, pr_uid
))
122 if (NOMATCH(ps_rgids
, pr_gid
))
124 if (NOMATCH(ps_ppids
, pr_ppid
))
126 if (NOMATCH(ps_pgids
, pr_pgid
))
128 if (NOMATCH(ps_sids
, pr_sid
))
130 if (NOMATCH(ps_ttys
, pr_ttydev
))
132 if (NOMATCH(ps_projids
, pr_projid
))
134 if (NOMATCH(ps_taskids
, pr_taskid
))
136 if (NOMATCH(ps_zoneids
, pr_zoneid
))
138 if (NOMATCH(ps_ctids
, pr_contract
))
141 if (psexp
->ps_pat
!= NULL
) {
142 s
= (flags
& PSEXP_PSARGS
) ?
143 psinfo
->pr_psargs
: psinfo
->pr_fname
;
145 if (regexec(&psexp
->ps_reg
, s
, 1, &pmatch
, 0) != 0)
148 if ((flags
& PSEXP_EXACT
) &&
149 (pmatch
.rm_so
!= 0 || s
[pmatch
.rm_eo
] != '\0'))