shadow/libsubid/api.c
Serge Hallyn f93cf255d4 Update licensing info
Closes #238

Update all files to list SPDX license shortname.  Most files are
BSD 3 clause license.

The exceptions are:

serge@sl ~/src/shadow$ git grep SPDX-License | grep -v BSD-3-Clause
contrib/atudel:# SPDX-License-Identifier: BSD-4-Clause
lib/tcbfuncs.c: * SPDX-License-Identifier: 0BSD
libmisc/salt.c: * SPDX-License-Identifier: Unlicense
src/login_nopam.c: * SPDX-License-Identifier: Unlicense
src/nologin.c: * SPDX-License-Identifier: BSD-2-Clause
src/vipw.c: * SPDX-License-Identifier: GPL-2.0-or-later

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2021-12-23 19:36:50 -06:00

108 lines
2.3 KiB
C

/*
* SPDX-FileCopyrightText: 2020 Serge Hallyn
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <config.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <pwd.h>
#include <stdbool.h>
#include "subordinateio.h"
#include "idmapping.h"
#include "subid.h"
static const char *Prog = "(libsubid)";
static FILE *shadow_logfd;
bool libsubid_init(const char *progname, FILE * logfd)
{
if (progname) {
progname = strdup(progname);
if (progname)
Prog = progname;
else
return false;
}
if (logfd) {
shadow_logfd = logfd;
return true;
}
shadow_logfd = fopen("/dev/null", "w");
if (!shadow_logfd) {
shadow_logfd = stderr;
return false;
}
return true;
}
static
int get_subid_ranges(const char *owner, enum subid_type id_type, struct subid_range **ranges)
{
return list_owner_ranges(owner, id_type, ranges);
}
int get_subuid_ranges(const char *owner, struct subid_range **ranges)
{
return get_subid_ranges(owner, ID_TYPE_UID, ranges);
}
int get_subgid_ranges(const char *owner, struct subid_range **ranges)
{
return get_subid_ranges(owner, ID_TYPE_GID, ranges);
}
static
int get_subid_owner(unsigned long id, enum subid_type id_type, uid_t **owner)
{
return find_subid_owners(id, id_type, owner);
}
int get_subuid_owners(uid_t uid, uid_t **owner)
{
return get_subid_owner((unsigned long)uid, ID_TYPE_UID, owner);
}
int get_subgid_owners(gid_t gid, uid_t **owner)
{
return get_subid_owner((unsigned long)gid, ID_TYPE_GID, owner);
}
static
bool grant_subid_range(struct subordinate_range *range, bool reuse,
enum subid_type id_type)
{
return new_subid_range(range, id_type, reuse);
}
bool grant_subuid_range(struct subordinate_range *range, bool reuse)
{
return grant_subid_range(range, reuse, ID_TYPE_UID);
}
bool grant_subgid_range(struct subordinate_range *range, bool reuse)
{
return grant_subid_range(range, reuse, ID_TYPE_GID);
}
static
bool ungrant_subid_range(struct subordinate_range *range, enum subid_type id_type)
{
return release_subid_range(range, id_type);
}
bool ungrant_subuid_range(struct subordinate_range *range)
{
return ungrant_subid_range(range, ID_TYPE_UID);
}
bool ungrant_subgid_range(struct subordinate_range *range)
{
return ungrant_subid_range(range, ID_TYPE_GID);
}