lib: have a lib_privs for ... lib privs

Logging code might want to raise privs for file operations.

Signed-off-by: David Lamparter <equinox@diac24.net>
This commit is contained in:
David Lamparter 2021-02-04 22:26:41 +01:00
parent 6e3253b979
commit 877057b67a
2 changed files with 8 additions and 0 deletions

View File

@ -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__);

View File

@ -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);