paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Zebra privileges. |
| 3 | * |
| 4 | * Copyright (C) 2003 Paul Jakma. |
Brian Bennett | 5cd0e5c | 2015-02-17 23:24:15 +0000 | [diff] [blame] | 5 | * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 6 | * |
| 7 | * This file is part of GNU Zebra. |
| 8 | * |
| 9 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2, or (at your option) any |
| 12 | * later version. |
| 13 | * |
| 14 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 21 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 22 | * 02111-1307, USA. |
| 23 | */ |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 24 | #include <zebra.h> |
| 25 | #include "log.h" |
| 26 | #include "privs.h" |
| 27 | #include "memory.h" |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 28 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 29 | #ifdef HAVE_CAPABILITIES |
| 30 | /* sort out some generic internal types for: |
| 31 | * |
| 32 | * privilege values (cap_value_t, priv_t) -> pvalue_t |
| 33 | * privilege set (..., priv_set_t) -> pset_t |
| 34 | * privilege working storage (cap_t, ...) -> pstorage_t |
| 35 | * |
| 36 | * values we think of as numeric (they're ints really, but we dont know) |
| 37 | * sets are mostly opaque, to hold a set of privileges, related in some way. |
| 38 | * storage binds together a set of sets we're interested in. |
| 39 | * (in reality: cap_value_t and priv_t are ints) |
| 40 | */ |
| 41 | #ifdef HAVE_LCAPS |
| 42 | /* Linux doesn't have a 'set' type: a set of related privileges */ |
| 43 | struct _pset { |
| 44 | int num; |
| 45 | cap_value_t *caps; |
| 46 | }; |
| 47 | typedef cap_value_t pvalue_t; |
| 48 | typedef struct _pset pset_t; |
| 49 | typedef cap_t pstorage_t; |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 50 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 51 | #elif defined (HAVE_SOLARIS_CAPABILITIES) |
| 52 | typedef priv_t pvalue_t; |
| 53 | typedef priv_set_t pset_t; |
| 54 | typedef priv_set_t *pstorage_t; |
| 55 | #else /* neither LCAPS nor SOLARIS_CAPABILITIES */ |
| 56 | #error "HAVE_CAPABILITIES defined, but neither LCAPS nor Solaris Capabilties!" |
| 57 | #endif /* HAVE_LCAPS */ |
| 58 | #endif /* HAVE_CAPABILITIES */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 59 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 60 | /* the default NULL state we report is RAISED, but could be LOWERED if |
| 61 | * zprivs_terminate is called and the NULL handler is installed. |
| 62 | */ |
| 63 | static zebra_privs_current_t zprivs_null_state = ZPRIVS_RAISED; |
| 64 | |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 65 | /* internal privileges state */ |
| 66 | static struct _zprivs_t |
| 67 | { |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 68 | #ifdef HAVE_CAPABILITIES |
| 69 | pstorage_t caps; /* working storage */ |
| 70 | pset_t *syscaps_p; /* system-type requested permitted caps */ |
| 71 | pset_t *syscaps_i; /* system-type requested inheritable caps */ |
| 72 | #endif /* HAVE_CAPABILITIES */ |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 73 | uid_t zuid, /* uid to run as */ |
| 74 | zsuid; /* saved uid */ |
| 75 | gid_t zgid; /* gid to run as */ |
hasso | ba3a0bc | 2003-06-04 17:41:54 +0000 | [diff] [blame] | 76 | gid_t vtygrp; /* gid for vty sockets */ |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 77 | } zprivs_state; |
| 78 | |
| 79 | /* externally exported but not directly accessed functions */ |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 80 | #ifdef HAVE_CAPABILITIES |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 81 | int zprivs_change_caps (zebra_privs_ops_t); |
| 82 | zebra_privs_current_t zprivs_state_caps (void); |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 83 | #endif /* HAVE_CAPABILITIES */ |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 84 | int zprivs_change_uid (zebra_privs_ops_t); |
| 85 | zebra_privs_current_t zprivs_state_uid (void); |
| 86 | int zprivs_change_null (zebra_privs_ops_t); |
| 87 | zebra_privs_current_t zprivs_state_null (void); |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 88 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 89 | #ifdef HAVE_CAPABILITIES |
| 90 | /* internal capability API */ |
| 91 | static pset_t *zcaps2sys (zebra_capabilities_t *, int); |
| 92 | static void zprivs_caps_init (struct zebra_privs_t *); |
| 93 | static void zprivs_caps_terminate (void); |
| 94 | |
| 95 | /* Map of Quagga abstract capabilities to system capabilities */ |
| 96 | static struct |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 97 | { |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 98 | int num; |
| 99 | pvalue_t *system_caps; |
| 100 | } cap_map [ZCAP_MAX] = |
| 101 | { |
| 102 | #ifdef HAVE_LCAPS /* Quagga -> Linux capabilities mappings */ |
| 103 | [ZCAP_SETID] = { 2, (pvalue_t []) { CAP_SETGID, |
| 104 | CAP_SETUID }, }, |
| 105 | [ZCAP_BIND] = { 2, (pvalue_t []) { CAP_NET_BIND_SERVICE, |
| 106 | CAP_NET_BROADCAST }, }, |
| 107 | [ZCAP_NET_ADMIN] = { 1, (pvalue_t []) { CAP_NET_ADMIN }, }, |
| 108 | [ZCAP_NET_RAW] = { 1, (pvalue_t []) { CAP_NET_RAW }, }, |
| 109 | [ZCAP_CHROOT] = { 1, (pvalue_t []) { CAP_SYS_CHROOT, }, }, |
| 110 | [ZCAP_NICE] = { 1, (pvalue_t []) { CAP_SYS_NICE }, }, |
| 111 | [ZCAP_PTRACE] = { 1, (pvalue_t []) { CAP_SYS_PTRACE }, }, |
| 112 | [ZCAP_DAC_OVERRIDE] = { 1, (pvalue_t []) { CAP_DAC_OVERRIDE }, }, |
| 113 | [ZCAP_READ_SEARCH] = { 1, (pvalue_t []) { CAP_DAC_READ_SEARCH }, }, |
| 114 | [ZCAP_SYS_ADMIN] = { 1, (pvalue_t []) { CAP_SYS_ADMIN }, }, |
| 115 | [ZCAP_FOWNER] = { 1, (pvalue_t []) { CAP_FOWNER }, }, |
| 116 | #elif defined(HAVE_SOLARIS_CAPABILITIES) /* HAVE_LCAPS */ |
| 117 | /* Quagga -> Solaris privilege mappings */ |
| 118 | [ZCAP_SETID] = { 1, (pvalue_t []) { PRIV_PROC_SETID }, }, |
| 119 | [ZCAP_BIND] = { 1, (pvalue_t []) { PRIV_NET_PRIVADDR }, }, |
Paul Jakma | 6b148fa | 2007-09-18 18:07:18 +0000 | [diff] [blame] | 120 | /* IP_CONFIG is a subset of NET_CONFIG and is allowed in zones */ |
| 121 | #ifdef PRIV_SYS_IP_CONFIG |
| 122 | [ZCAP_NET_ADMIN] = { 1, (pvalue_t []) { PRIV_SYS_IP_CONFIG }, }, |
| 123 | #else |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 124 | [ZCAP_NET_ADMIN] = { 1, (pvalue_t []) { PRIV_SYS_NET_CONFIG }, }, |
Paul Jakma | 6b148fa | 2007-09-18 18:07:18 +0000 | [diff] [blame] | 125 | #endif |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 126 | [ZCAP_NET_RAW] = { 2, (pvalue_t []) { PRIV_NET_RAWACCESS, |
| 127 | PRIV_NET_ICMPACCESS }, }, |
| 128 | [ZCAP_CHROOT] = { 1, (pvalue_t []) { PRIV_PROC_CHROOT }, }, |
| 129 | [ZCAP_NICE] = { 1, (pvalue_t []) { PRIV_PROC_PRIOCNTL }, }, |
| 130 | [ZCAP_PTRACE] = { 1, (pvalue_t []) { PRIV_PROC_SESSION }, }, |
| 131 | [ZCAP_DAC_OVERRIDE] = { 2, (pvalue_t []) { PRIV_FILE_DAC_EXECUTE, |
| 132 | PRIV_FILE_DAC_READ, |
| 133 | PRIV_FILE_DAC_SEARCH, |
| 134 | PRIV_FILE_DAC_WRITE, |
| 135 | PRIV_FILE_DAC_SEARCH }, }, |
| 136 | [ZCAP_READ_SEARCH] = { 2, (pvalue_t []) { PRIV_FILE_DAC_SEARCH, |
| 137 | PRIV_FILE_DAC_READ }, }, |
| 138 | [ZCAP_SYS_ADMIN] = { 1, (pvalue_t []) { PRIV_SYS_ADMIN }, }, |
| 139 | [ZCAP_FOWNER] = { 1, (pvalue_t []) { PRIV_FILE_OWNER }, }, |
| 140 | #endif /* HAVE_SOLARIS_CAPABILITIES */ |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 141 | }; |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 142 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 143 | #ifdef HAVE_LCAPS |
| 144 | /* Linux forms of capabilities methods */ |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 145 | /* convert zebras privileges to system capabilities */ |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 146 | static pset_t * |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 147 | zcaps2sys (zebra_capabilities_t *zcaps, int num) |
| 148 | { |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 149 | pset_t *syscaps; |
| 150 | int i, j = 0, count = 0; |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 151 | |
| 152 | if (!num) |
| 153 | return NULL; |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 154 | |
| 155 | /* first count up how many system caps we have */ |
| 156 | for (i= 0; i < num; i++) |
| 157 | count += cap_map[zcaps[i]].num; |
| 158 | |
| 159 | if ( (syscaps = XCALLOC (MTYPE_PRIVS, (sizeof(pset_t) * num))) == NULL) |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 160 | { |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 161 | fprintf (stderr, "%s: could not allocate syscaps!", __func__); |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 162 | return NULL; |
| 163 | } |
| 164 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 165 | syscaps->caps = XCALLOC (MTYPE_PRIVS, (sizeof (pvalue_t) * count)); |
| 166 | |
| 167 | if (!syscaps->caps) |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 168 | { |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 169 | fprintf (stderr, "%s: could not XCALLOC caps!", __func__); |
| 170 | return NULL; |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 171 | } |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 172 | |
| 173 | /* copy the capabilities over */ |
| 174 | count = 0; |
| 175 | for (i=0; i < num; i++) |
| 176 | for (j = 0; j < cap_map[zcaps[i]].num; j++) |
| 177 | syscaps->caps[count++] = cap_map[zcaps[i]].system_caps[j]; |
| 178 | |
| 179 | /* iterations above should be exact same as previous count, obviously.. */ |
| 180 | syscaps->num = count; |
| 181 | |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 182 | return syscaps; |
| 183 | } |
| 184 | |
| 185 | /* set or clear the effective capabilities to/from permitted */ |
| 186 | int |
| 187 | zprivs_change_caps (zebra_privs_ops_t op) |
| 188 | { |
| 189 | cap_flag_value_t cflag; |
| 190 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 191 | /* should be no possibility of being called without valid caps */ |
| 192 | assert (zprivs_state.syscaps_p && zprivs_state.caps); |
| 193 | if (! (zprivs_state.syscaps_p && zprivs_state.caps)) |
| 194 | exit (1); |
| 195 | |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 196 | if (op == ZPRIVS_RAISE) |
| 197 | cflag = CAP_SET; |
| 198 | else if (op == ZPRIVS_LOWER) |
| 199 | cflag = CAP_CLEAR; |
| 200 | else |
| 201 | return -1; |
| 202 | |
| 203 | if ( !cap_set_flag (zprivs_state.caps, CAP_EFFECTIVE, |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 204 | zprivs_state.syscaps_p->num, |
| 205 | zprivs_state.syscaps_p->caps, |
| 206 | cflag)) |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 207 | return cap_set_proc (zprivs_state.caps); |
| 208 | return -1; |
| 209 | } |
| 210 | |
| 211 | zebra_privs_current_t |
| 212 | zprivs_state_caps (void) |
| 213 | { |
| 214 | int i; |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 215 | cap_flag_value_t val; |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 216 | |
| 217 | /* should be no possibility of being called without valid caps */ |
| 218 | assert (zprivs_state.syscaps_p && zprivs_state.caps); |
| 219 | if (! (zprivs_state.syscaps_p && zprivs_state.caps)) |
| 220 | exit (1); |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 221 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 222 | for (i=0; i < zprivs_state.syscaps_p->num; i++) |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 223 | { |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 224 | if ( cap_get_flag (zprivs_state.caps, zprivs_state.syscaps_p->caps[i], |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 225 | CAP_EFFECTIVE, &val) ) |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 226 | { |
| 227 | zlog_warn ("zprivs_state_caps: could not cap_get_flag, %s", |
| 228 | safe_strerror (errno) ); |
| 229 | return ZPRIVS_UNKNOWN; |
| 230 | } |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 231 | if (val == CAP_SET) |
paul | 33b7294 | 2003-05-20 02:22:42 +0000 | [diff] [blame] | 232 | return ZPRIVS_RAISED; |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 233 | } |
| 234 | return ZPRIVS_LOWERED; |
| 235 | } |
| 236 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 237 | static void |
| 238 | zprivs_caps_init (struct zebra_privs_t *zprivs) |
| 239 | { |
| 240 | zprivs_state.syscaps_p = zcaps2sys (zprivs->caps_p, zprivs->cap_num_p); |
| 241 | zprivs_state.syscaps_i = zcaps2sys (zprivs->caps_i, zprivs->cap_num_i); |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 242 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 243 | /* Tell kernel we want caps maintained across uid changes */ |
| 244 | if ( prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) == -1 ) |
| 245 | { |
| 246 | fprintf (stderr, "privs_init: could not set PR_SET_KEEPCAPS, %s\n", |
| 247 | safe_strerror (errno) ); |
| 248 | exit(1); |
| 249 | } |
| 250 | |
| 251 | if ( !zprivs_state.syscaps_p ) |
| 252 | { |
| 253 | fprintf (stderr, "privs_init: capabilities enabled, " |
| 254 | "but no capabilities supplied\n"); |
| 255 | } |
| 256 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 257 | /* we have caps, we have no need to ever change back the original user */ |
| 258 | if (zprivs_state.zuid) |
| 259 | { |
| 260 | if ( setreuid (zprivs_state.zuid, zprivs_state.zuid) ) |
| 261 | { |
| 262 | fprintf (stderr, "zprivs_init (cap): could not setreuid, %s\n", |
| 263 | safe_strerror (errno)); |
| 264 | exit (1); |
| 265 | } |
| 266 | } |
| 267 | |
Paul Jakma | 924f9d3 | 2006-03-30 13:25:52 +0000 | [diff] [blame] | 268 | if ( !(zprivs_state.caps = cap_init()) ) |
| 269 | { |
| 270 | fprintf (stderr, "privs_init: failed to cap_init, %s\n", |
| 271 | safe_strerror (errno)); |
| 272 | exit (1); |
| 273 | } |
| 274 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 275 | if ( cap_clear (zprivs_state.caps) ) |
| 276 | { |
| 277 | fprintf (stderr, "privs_init: failed to cap_clear, %s\n", |
| 278 | safe_strerror (errno)); |
| 279 | exit (1); |
| 280 | } |
| 281 | |
| 282 | /* set permitted caps */ |
| 283 | cap_set_flag(zprivs_state.caps, CAP_PERMITTED, |
| 284 | zprivs_state.syscaps_p->num, |
| 285 | zprivs_state.syscaps_p->caps, |
| 286 | CAP_SET); |
| 287 | |
| 288 | /* set inheritable caps, if any */ |
| 289 | if (zprivs_state.syscaps_i && zprivs_state.syscaps_i->num) |
| 290 | { |
| 291 | cap_set_flag(zprivs_state.caps, CAP_INHERITABLE, |
| 292 | zprivs_state.syscaps_i->num, |
| 293 | zprivs_state.syscaps_i->caps, |
| 294 | CAP_SET); |
| 295 | } |
| 296 | |
| 297 | /* apply caps. CAP_EFFECTIVE is cleared. we'll raise the caps as |
| 298 | * and when, and only when, they are needed. |
| 299 | */ |
| 300 | if ( cap_set_proc (zprivs_state.caps) ) |
| 301 | { |
| 302 | fprintf (stderr, "privs_init: initial cap_set_proc failed\n"); |
| 303 | exit (1); |
| 304 | } |
| 305 | |
| 306 | /* set methods for the caller to use */ |
| 307 | zprivs->change = zprivs_change_caps; |
| 308 | zprivs->current_state = zprivs_state_caps; |
| 309 | } |
| 310 | |
| 311 | static void |
| 312 | zprivs_caps_terminate (void) |
| 313 | { |
| 314 | /* clear all capabilities */ |
| 315 | if (zprivs_state.caps) |
| 316 | cap_clear (zprivs_state.caps); |
| 317 | |
| 318 | /* and boom, capabilities are gone forever */ |
| 319 | if ( cap_set_proc (zprivs_state.caps) ) |
| 320 | { |
| 321 | fprintf (stderr, "privs_terminate: cap_set_proc failed, %s", |
| 322 | safe_strerror (errno) ); |
| 323 | exit (1); |
| 324 | } |
| 325 | |
| 326 | /* free up private state */ |
| 327 | if (zprivs_state.syscaps_p->num) |
| 328 | { |
| 329 | XFREE (MTYPE_PRIVS, zprivs_state.syscaps_p->caps); |
| 330 | XFREE (MTYPE_PRIVS, zprivs_state.syscaps_p); |
| 331 | } |
| 332 | |
| 333 | if (zprivs_state.syscaps_i && zprivs_state.syscaps_i->num) |
| 334 | { |
| 335 | XFREE (MTYPE_PRIVS, zprivs_state.syscaps_i->caps); |
| 336 | XFREE (MTYPE_PRIVS, zprivs_state.syscaps_i); |
| 337 | } |
| 338 | |
| 339 | cap_free (zprivs_state.caps); |
| 340 | } |
| 341 | #elif defined (HAVE_SOLARIS_CAPABILITIES) /* !HAVE_LCAPS */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 342 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 343 | /* Solaris specific capability/privilege methods |
| 344 | * |
| 345 | * Resources: |
| 346 | * - the 'privileges' man page |
| 347 | * - http://cvs.opensolaris.org |
| 348 | * - http://blogs.sun.com/roller/page/gbrunett?entry=privilege_enabling_set_id_programs1 |
| 349 | */ |
| 350 | |
Brian Bennett | 5cd0e5c | 2015-02-17 23:24:15 +0000 | [diff] [blame] | 351 | static pset_t * |
| 352 | zprivs_caps_minimal () |
| 353 | { |
| 354 | pset_t *minimal; |
| 355 | |
| 356 | if ((minimal = priv_str_to_set("basic", ",", NULL)) == NULL) |
| 357 | { |
| 358 | fprintf (stderr, "%s: couldn't get basic set!\n", __func__); |
| 359 | exit (1); |
| 360 | } |
| 361 | |
| 362 | /* create a minimal privilege set from the basic set */ |
| 363 | (void) priv_delset(minimal, PRIV_PROC_EXEC); |
| 364 | (void) priv_delset(minimal, PRIV_PROC_INFO); |
| 365 | (void) priv_delset(minimal, PRIV_PROC_SESSION); |
| 366 | (void) priv_delset(minimal, PRIV_FILE_LINK_ANY); |
| 367 | |
| 368 | return minimal; |
| 369 | } |
| 370 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 371 | /* convert zebras privileges to system capabilities */ |
| 372 | static pset_t * |
| 373 | zcaps2sys (zebra_capabilities_t *zcaps, int num) |
| 374 | { |
| 375 | pset_t *syscaps; |
paul | 6e0f1b9 | 2005-11-24 12:47:17 +0000 | [diff] [blame] | 376 | int i, j = 0; |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 377 | |
| 378 | if ((syscaps = priv_allocset()) == NULL) |
| 379 | { |
| 380 | fprintf (stderr, "%s: could not allocate syscaps!\n", __func__); |
| 381 | exit (1); |
| 382 | } |
| 383 | |
| 384 | priv_emptyset (syscaps); |
| 385 | |
| 386 | for (i=0; i < num; i++) |
| 387 | for (j = 0; j < cap_map[zcaps[i]].num; j++) |
| 388 | priv_addset (syscaps, cap_map[zcaps[i]].system_caps[j]); |
| 389 | |
| 390 | return syscaps; |
| 391 | } |
| 392 | |
| 393 | /* callback exported to users to RAISE and LOWER effective privileges |
| 394 | * from nothing to the given permitted set and back down |
| 395 | */ |
| 396 | int |
| 397 | zprivs_change_caps (zebra_privs_ops_t op) |
| 398 | { |
Brian Bennett | 5cd0e5c | 2015-02-17 23:24:15 +0000 | [diff] [blame] | 399 | pset_t *privset; |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 400 | |
| 401 | /* should be no possibility of being called without valid caps */ |
| 402 | assert (zprivs_state.syscaps_p); |
| 403 | if (!zprivs_state.syscaps_p) |
| 404 | { |
Brian Bennett | 5cd0e5c | 2015-02-17 23:24:15 +0000 | [diff] [blame] | 405 | fprintf (stderr, "%s: Eek, missing privileged caps!", __func__); |
| 406 | exit (1); |
| 407 | } |
| 408 | |
| 409 | assert (zprivs_state.caps); |
| 410 | if (!zprivs_state.caps) |
| 411 | { |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 412 | fprintf (stderr, "%s: Eek, missing caps!", __func__); |
| 413 | exit (1); |
| 414 | } |
Brian Bennett | 5cd0e5c | 2015-02-17 23:24:15 +0000 | [diff] [blame] | 415 | |
| 416 | /* to raise: copy original permitted as our working effective set |
| 417 | * to lower: copy regular effective set stored in zprivs_state.caps |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 418 | */ |
| 419 | if (op == ZPRIVS_RAISE) |
Brian Bennett | 5cd0e5c | 2015-02-17 23:24:15 +0000 | [diff] [blame] | 420 | privset = zprivs_state.syscaps_p; |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 421 | else if (op == ZPRIVS_LOWER) |
Brian Bennett | 5cd0e5c | 2015-02-17 23:24:15 +0000 | [diff] [blame] | 422 | privset = zprivs_state.caps; |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 423 | else |
| 424 | return -1; |
| 425 | |
Brian Bennett | 5cd0e5c | 2015-02-17 23:24:15 +0000 | [diff] [blame] | 426 | if (setppriv (PRIV_SET, PRIV_EFFECTIVE, privset) != 0) |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 427 | return -1; |
| 428 | |
| 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | /* Retrieve current privilege state, is it RAISED or LOWERED? */ |
| 433 | zebra_privs_current_t |
| 434 | zprivs_state_caps (void) |
| 435 | { |
| 436 | zebra_privs_current_t result; |
| 437 | pset_t *effective; |
| 438 | |
| 439 | if ( (effective = priv_allocset()) == NULL) |
| 440 | { |
paul | 6e0f1b9 | 2005-11-24 12:47:17 +0000 | [diff] [blame] | 441 | fprintf (stderr, "%s: failed to get priv_allocset! %s\n", __func__, |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 442 | safe_strerror (errno)); |
| 443 | return ZPRIVS_UNKNOWN; |
| 444 | } |
| 445 | |
| 446 | if (getppriv (PRIV_EFFECTIVE, effective)) |
| 447 | { |
paul | 6e0f1b9 | 2005-11-24 12:47:17 +0000 | [diff] [blame] | 448 | fprintf (stderr, "%s: failed to get state! %s\n", __func__, |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 449 | safe_strerror (errno)); |
| 450 | result = ZPRIVS_UNKNOWN; |
| 451 | } |
| 452 | else |
| 453 | { |
Brian Bennett | 5cd0e5c | 2015-02-17 23:24:15 +0000 | [diff] [blame] | 454 | if (priv_isequalset (effective, zprivs_state.syscaps_p)) |
| 455 | result = ZPRIVS_RAISED; |
| 456 | else if (priv_isequalset (effective, zprivs_state.caps)) |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 457 | result = ZPRIVS_LOWERED; |
| 458 | else |
Brian Bennett | 5cd0e5c | 2015-02-17 23:24:15 +0000 | [diff] [blame] | 459 | result = ZPRIVS_UNKNOWN; |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Brian Bennett | 5cd0e5c | 2015-02-17 23:24:15 +0000 | [diff] [blame] | 462 | priv_freeset (effective); |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 463 | return result; |
| 464 | } |
| 465 | |
| 466 | static void |
| 467 | zprivs_caps_init (struct zebra_privs_t *zprivs) |
| 468 | { |
| 469 | pset_t *basic; |
Brian Bennett | 5cd0e5c | 2015-02-17 23:24:15 +0000 | [diff] [blame] | 470 | pset_t *minimal; |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 471 | |
| 472 | /* the specified sets */ |
| 473 | zprivs_state.syscaps_p = zcaps2sys (zprivs->caps_p, zprivs->cap_num_p); |
| 474 | zprivs_state.syscaps_i = zcaps2sys (zprivs->caps_i, zprivs->cap_num_i); |
| 475 | |
| 476 | /* nonsensical to have gotten here but not have capabilities */ |
| 477 | if (!zprivs_state.syscaps_p) |
| 478 | { |
| 479 | fprintf (stderr, "%s: capabilities enabled, " |
| 480 | "but no valid capabilities supplied\n", |
| 481 | __func__); |
| 482 | } |
| 483 | |
| 484 | /* We retain the basic set in our permitted set, as Linux has no |
| 485 | * equivalent. The basic set on Linux hence is implicit, always |
| 486 | * there. |
| 487 | */ |
| 488 | if ((basic = priv_str_to_set("basic", ",", NULL)) == NULL) |
| 489 | { |
| 490 | fprintf (stderr, "%s: couldn't get basic set!\n", __func__); |
| 491 | exit (1); |
| 492 | } |
| 493 | |
| 494 | /* Add the basic set to the permitted set */ |
| 495 | priv_union (basic, zprivs_state.syscaps_p); |
| 496 | priv_freeset (basic); |
| 497 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 498 | /* Hey kernel, we know about privileges! |
| 499 | * this isn't strictly required, use of setppriv should have same effect |
| 500 | */ |
| 501 | if (setpflags (PRIV_AWARE, 1)) |
| 502 | { |
| 503 | fprintf (stderr, "%s: error setting PRIV_AWARE!, %s\n", __func__, |
| 504 | safe_strerror (errno) ); |
| 505 | exit (1); |
| 506 | } |
| 507 | |
| 508 | /* need either valid or empty sets for both p and i.. */ |
| 509 | assert (zprivs_state.syscaps_i && zprivs_state.syscaps_p); |
| 510 | |
Paul Jakma | 924f9d3 | 2006-03-30 13:25:52 +0000 | [diff] [blame] | 511 | /* we have caps, we have no need to ever change back the original user |
| 512 | * change real, effective and saved to the specified user. |
| 513 | */ |
| 514 | if (zprivs_state.zuid) |
| 515 | { |
| 516 | if ( setreuid (zprivs_state.zuid, zprivs_state.zuid) ) |
| 517 | { |
| 518 | fprintf (stderr, "%s: could not setreuid, %s\n", |
| 519 | __func__, safe_strerror (errno)); |
| 520 | exit (1); |
| 521 | } |
| 522 | } |
| 523 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 524 | /* set the permitted set */ |
| 525 | if (setppriv (PRIV_SET, PRIV_PERMITTED, zprivs_state.syscaps_p)) |
| 526 | { |
| 527 | fprintf (stderr, "%s: error setting permitted set!, %s\n", __func__, |
| 528 | safe_strerror (errno) ); |
| 529 | exit (1); |
| 530 | } |
| 531 | |
| 532 | /* set the inheritable set */ |
| 533 | if (setppriv (PRIV_SET, PRIV_INHERITABLE, zprivs_state.syscaps_i)) |
| 534 | { |
| 535 | fprintf (stderr, "%s: error setting inheritable set!, %s\n", __func__, |
| 536 | safe_strerror (errno) ); |
| 537 | exit (1); |
| 538 | } |
| 539 | |
Brian Bennett | 5cd0e5c | 2015-02-17 23:24:15 +0000 | [diff] [blame] | 540 | /* we need a minimal basic set for 'effective', potentially for inheritable too */ |
| 541 | minimal = zprivs_caps_minimal(); |
| 542 | |
| 543 | /* now set the effective set with a subset of basic privileges */ |
| 544 | if (setppriv (PRIV_SET, PRIV_EFFECTIVE, minimal)) |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 545 | { |
| 546 | fprintf (stderr, "%s: error setting effective set!, %s\n", __func__, |
| 547 | safe_strerror (errno) ); |
| 548 | exit (1); |
| 549 | } |
| 550 | |
Brian Bennett | 5cd0e5c | 2015-02-17 23:24:15 +0000 | [diff] [blame] | 551 | /* we'll use the minimal set as our working-storage privset */ |
| 552 | zprivs_state.caps = minimal; |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 553 | |
| 554 | /* set methods for the caller to use */ |
| 555 | zprivs->change = zprivs_change_caps; |
| 556 | zprivs->current_state = zprivs_state_caps; |
| 557 | } |
| 558 | |
| 559 | static void |
| 560 | zprivs_caps_terminate (void) |
| 561 | { |
| 562 | assert (zprivs_state.caps); |
| 563 | |
Brian Bennett | 5cd0e5c | 2015-02-17 23:24:15 +0000 | [diff] [blame] | 564 | /* clear all capabilities by using working-storage privset */ |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 565 | setppriv (PRIV_SET, PRIV_EFFECTIVE, zprivs_state.caps); |
| 566 | setppriv (PRIV_SET, PRIV_PERMITTED, zprivs_state.caps); |
| 567 | setppriv (PRIV_SET, PRIV_INHERITABLE, zprivs_state.caps); |
| 568 | |
| 569 | /* free up private state */ |
| 570 | if (zprivs_state.syscaps_p) |
| 571 | priv_freeset (zprivs_state.syscaps_p); |
| 572 | if (zprivs_state.syscaps_i) |
| 573 | priv_freeset (zprivs_state.syscaps_i); |
| 574 | |
| 575 | priv_freeset (zprivs_state.caps); |
| 576 | } |
| 577 | #else /* !HAVE_LCAPS && ! HAVE_SOLARIS_CAPABILITIES */ |
| 578 | #error "Neither Solaris nor Linux capabilities, dazed and confused..." |
| 579 | #endif /* HAVE_LCAPS */ |
| 580 | #endif /* HAVE_CAPABILITIES */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 581 | |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 582 | int |
| 583 | zprivs_change_uid (zebra_privs_ops_t op) |
| 584 | { |
paul | 28efaa3 | 2003-05-20 03:49:43 +0000 | [diff] [blame] | 585 | |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 586 | if (op == ZPRIVS_RAISE) |
| 587 | return seteuid (zprivs_state.zsuid); |
| 588 | else if (op == ZPRIVS_LOWER) |
| 589 | return seteuid (zprivs_state.zuid); |
| 590 | else |
| 591 | return -1; |
| 592 | } |
| 593 | |
| 594 | zebra_privs_current_t |
| 595 | zprivs_state_uid (void) |
| 596 | { |
| 597 | return ( (zprivs_state.zuid == geteuid()) ? ZPRIVS_LOWERED : ZPRIVS_RAISED); |
| 598 | } |
| 599 | |
| 600 | int |
| 601 | zprivs_change_null (zebra_privs_ops_t op) |
| 602 | { |
| 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | zebra_privs_current_t |
| 607 | zprivs_state_null (void) |
| 608 | { |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 609 | return zprivs_null_state; |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 610 | } |
| 611 | |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 612 | void |
| 613 | zprivs_init(struct zebra_privs_t *zprivs) |
| 614 | { |
| 615 | struct passwd *pwentry = NULL; |
| 616 | struct group *grentry = NULL; |
| 617 | |
hasso | ba3a0bc | 2003-06-04 17:41:54 +0000 | [diff] [blame] | 618 | if (!zprivs) |
| 619 | { |
paul | 58a9d81 | 2003-06-11 05:12:40 +0000 | [diff] [blame] | 620 | fprintf (stderr, "zprivs_init: called with NULL arg!\n"); |
hasso | ba3a0bc | 2003-06-04 17:41:54 +0000 | [diff] [blame] | 621 | exit (1); |
| 622 | } |
| 623 | |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 624 | /* NULL privs */ |
| 625 | if (! (zprivs->user || zprivs->group |
| 626 | || zprivs->cap_num_p || zprivs->cap_num_i) ) |
| 627 | { |
| 628 | zprivs->change = zprivs_change_null; |
| 629 | zprivs->current_state = zprivs_state_null; |
| 630 | return; |
| 631 | } |
| 632 | |
| 633 | if (zprivs->user) |
| 634 | { |
| 635 | if ( (pwentry = getpwnam (zprivs->user)) ) |
hasso | ba3a0bc | 2003-06-04 17:41:54 +0000 | [diff] [blame] | 636 | { |
| 637 | zprivs_state.zuid = pwentry->pw_uid; |
| 638 | } |
| 639 | else |
| 640 | { |
paul | 58a9d81 | 2003-06-11 05:12:40 +0000 | [diff] [blame] | 641 | /* cant use log.h here as it depends on vty */ |
| 642 | fprintf (stderr, "privs_init: could not lookup user %s\n", |
| 643 | zprivs->user); |
hasso | ba3a0bc | 2003-06-04 17:41:54 +0000 | [diff] [blame] | 644 | exit (1); |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | grentry = NULL; |
| 649 | |
| 650 | if (zprivs->vty_group) |
| 651 | /* Add the vty_group to the supplementary groups so it can be chowned to */ |
| 652 | { |
| 653 | if ( (grentry = getgrnam (zprivs->vty_group)) ) |
| 654 | { |
| 655 | zprivs_state.vtygrp = grentry->gr_gid; |
| 656 | if ( setgroups (1, &zprivs_state.vtygrp) ) |
| 657 | { |
paul | 58a9d81 | 2003-06-11 05:12:40 +0000 | [diff] [blame] | 658 | fprintf (stderr, "privs_init: could not setgroups, %s\n", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 659 | safe_strerror (errno) ); |
hasso | ba3a0bc | 2003-06-04 17:41:54 +0000 | [diff] [blame] | 660 | exit (1); |
| 661 | } |
| 662 | } |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 663 | else |
| 664 | { |
paul | 58a9d81 | 2003-06-11 05:12:40 +0000 | [diff] [blame] | 665 | fprintf (stderr, "privs_init: could not lookup vty group %s\n", |
| 666 | zprivs->vty_group); |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 667 | exit (1); |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | if (zprivs->group) |
| 672 | { |
hasso | ba3a0bc | 2003-06-04 17:41:54 +0000 | [diff] [blame] | 673 | if ( (grentry = getgrnam (zprivs->group)) ) |
| 674 | { |
| 675 | zprivs_state.zgid = grentry->gr_gid; |
| 676 | } |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 677 | else |
| 678 | { |
paul | 58a9d81 | 2003-06-11 05:12:40 +0000 | [diff] [blame] | 679 | fprintf (stderr, "privs_init: could not lookup group %s\n", |
| 680 | zprivs->group); |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 681 | exit (1); |
| 682 | } |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 683 | /* change group now, forever. uid we do later */ |
| 684 | if ( setregid (zprivs_state.zgid, zprivs_state.zgid) ) |
| 685 | { |
paul | 58a9d81 | 2003-06-11 05:12:40 +0000 | [diff] [blame] | 686 | fprintf (stderr, "zprivs_init: could not setregid, %s\n", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 687 | safe_strerror (errno) ); |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 688 | exit (1); |
| 689 | } |
| 690 | } |
| 691 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 692 | #ifdef HAVE_CAPABILITIES |
| 693 | zprivs_caps_init (zprivs); |
| 694 | #else /* !HAVE_CAPABILITIES */ |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 695 | /* we dont have caps. we'll need to maintain rid and saved uid |
| 696 | * and change euid back to saved uid (who we presume has all neccessary |
| 697 | * privileges) whenever we are asked to raise our privileges. |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 698 | * |
| 699 | * This is not worth that much security wise, but all we can do. |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 700 | */ |
| 701 | zprivs_state.zsuid = geteuid(); |
| 702 | if ( zprivs_state.zuid ) |
| 703 | { |
| 704 | if ( setreuid (-1, zprivs_state.zuid) ) |
| 705 | { |
paul | 58a9d81 | 2003-06-11 05:12:40 +0000 | [diff] [blame] | 706 | fprintf (stderr, "privs_init (uid): could not setreuid, %s\n", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 707 | safe_strerror (errno)); |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 708 | exit (1); |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | zprivs->change = zprivs_change_uid; |
| 713 | zprivs->current_state = zprivs_state_uid; |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 714 | #endif /* HAVE_CAPABILITIES */ |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | void |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 718 | zprivs_terminate (struct zebra_privs_t *zprivs) |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 719 | { |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 720 | if (!zprivs) |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 721 | { |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 722 | fprintf (stderr, "%s: no privs struct given, terminating", __func__); |
| 723 | exit (0); |
| 724 | } |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 725 | |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 726 | #ifdef HAVE_CAPABILITIES |
| 727 | zprivs_caps_terminate(); |
| 728 | #else /* !HAVE_CAPABILITIES */ |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 729 | if (zprivs_state.zuid) |
| 730 | { |
| 731 | if ( setreuid (zprivs_state.zuid, zprivs_state.zuid) ) |
| 732 | { |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 733 | fprintf (stderr, "privs_terminate: could not setreuid, %s", |
ajs | 6099b3b | 2004-11-20 02:06:59 +0000 | [diff] [blame] | 734 | safe_strerror (errno) ); |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 735 | exit (1); |
| 736 | } |
| 737 | } |
| 738 | #endif /* HAVE_LCAPS */ |
paul | ceacedb | 2005-09-29 14:39:32 +0000 | [diff] [blame] | 739 | |
| 740 | zprivs->change = zprivs_change_null; |
| 741 | zprivs->current_state = zprivs_state_null; |
| 742 | zprivs_null_state = ZPRIVS_LOWERED; |
paul | 0124582 | 2003-05-20 01:22:17 +0000 | [diff] [blame] | 743 | return; |
| 744 | } |
hasso | ba3a0bc | 2003-06-04 17:41:54 +0000 | [diff] [blame] | 745 | |
| 746 | void |
| 747 | zprivs_get_ids(struct zprivs_ids_t *ids) |
| 748 | { |
| 749 | |
| 750 | ids->uid_priv = getuid(); |
| 751 | (zprivs_state.zuid) ? (ids->uid_normal = zprivs_state.zuid) |
| 752 | : (ids->uid_normal = -1); |
| 753 | (zprivs_state.zgid) ? (ids->gid_normal = zprivs_state.zgid) |
| 754 | : (ids->gid_normal = -1); |
| 755 | (zprivs_state.vtygrp) ? (ids->gid_vty = zprivs_state.vtygrp) |
| 756 | : (ids->gid_vty = -1); |
| 757 | |
| 758 | return; |
| 759 | } |