From 877057b67adcd9ed15e34bc1cf39281dc08f64cc Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Thu, 4 Feb 2021 22:26:41 +0100 Subject: [PATCH] lib: have a lib_privs for ... lib privs Logging code might want to raise privs for file operations. Signed-off-by: David Lamparter --- lib/privs.c | 6 ++++++ lib/privs.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/lib/privs.c b/lib/privs.c index 1bb5d059c8..5ca3c0d886 100644 --- a/lib/privs.c +++ b/lib/privs.c @@ -587,6 +587,8 @@ void zprivs_preinit(struct zebra_privs_t *zprivs) } } +struct zebra_privs_t *lib_privs; + void zprivs_init(struct zebra_privs_t *zprivs) { gid_t groups[NGROUPS_MAX] = {}; @@ -598,6 +600,8 @@ void zprivs_init(struct zebra_privs_t *zprivs) || zprivs->cap_num_i)) return; + lib_privs = zprivs; + if (zprivs->user) { ngroups = array_size(groups); if (getgrouplist(zprivs->user, zprivs_state.zgid, groups, @@ -701,6 +705,8 @@ void zprivs_terminate(struct zebra_privs_t *zprivs) { struct zebra_privs_refs_t *refs; + lib_privs = NULL; + if (!zprivs) { fprintf(stderr, "%s: no privs struct given, terminating", __func__); diff --git a/lib/privs.h b/lib/privs.h index 18ba8e8888..2dcdbe2e6c 100644 --- a/lib/privs.h +++ b/lib/privs.h @@ -100,6 +100,8 @@ struct zprivs_ids_t { gid_t gid_vty; /* vty gid */ }; +extern struct zebra_privs_t *lib_privs; + /* initialise zebra privileges */ extern void zprivs_preinit(struct zebra_privs_t *zprivs); extern void zprivs_init(struct zebra_privs_t *zprivs); -- 2.39.5