summaryrefslogtreecommitdiff
path: root/libsubid
diff options
context:
space:
mode:
authorBalint Reczey <balint@balintreczey.hu>2022-08-24 00:06:41 +0200
committerBalint Reczey <balint@balintreczey.hu>2022-08-24 00:06:41 +0200
commit8ead740677d19e48690d4f144ab090b83d47059f (patch)
tree2ecb71fe46f797b222d6cd57605c67d6f3298560 /libsubid
parent675b462b64b213647d0f5c56b1e8440be5890c8a (diff)
downloadshadow-8ead740677d19e48690d4f144ab090b83d47059f.tar.gz
New upstream version 4.12.3+dfsg1upstream/4.12.3+dfsg1
Diffstat (limited to 'libsubid')
-rw-r--r--libsubid/api.c25
-rw-r--r--libsubid/subid.h16
-rw-r--r--libsubid/subid.h.in16
3 files changed, 57 insertions, 0 deletions
diff --git a/libsubid/api.c b/libsubid/api.c
index 0c8c451a..00da74f6 100644
--- a/libsubid/api.c
+++ b/libsubid/api.c
@@ -17,6 +17,31 @@
#include "subid.h"
#include "shadowlog.h"
+bool subid_init(const char *progname, FILE * logfd)
+{
+ FILE *shadow_logfd;
+ if (progname) {
+ progname = strdup(progname);
+ if (!progname)
+ return false;
+ log_set_progname(progname);
+ } else {
+ log_set_progname("(libsubid)");
+ }
+
+ if (logfd) {
+ log_set_logfd(logfd);
+ return true;
+ }
+ shadow_logfd = fopen("/dev/null", "w");
+ if (!shadow_logfd) {
+ log_set_logfd(stderr);
+ return false;
+ }
+ log_set_logfd(shadow_logfd);
+ return true;
+}
+
static
int get_subid_ranges(const char *owner, enum subid_type id_type, struct subid_range **ranges)
{
diff --git a/libsubid/subid.h b/libsubid/subid.h
index e8dbdecc..d13ee84a 100644
--- a/libsubid/subid.h
+++ b/libsubid/subid.h
@@ -40,6 +40,22 @@ extern "C" {
#endif
/*
+ * subid_init: initialize libsubid
+ *
+ * @progname: Name to display as program. If NULL, then "(libsubid)" will be
+ * shown in error messages.
+ * @logfd: Open file pointer to pass error messages to. If NULL, then
+ * /dev/null will be opened and messages will be sent there. The
+ * default if libsubid_init() is not called is stderr (2).
+ *
+ * This function does not need to be called. If not called, then the defaults
+ * will be used.
+ *
+ * Returns false if an error occurred.
+ */
+bool subid_init(const char *progname, FILE *logfd);
+
+/*
* subid_get_uid_ranges: return a list of UID ranges for a user
*
* @owner: username being queried
diff --git a/libsubid/subid.h.in b/libsubid/subid.h.in
index c8d9273f..79744eda 100644
--- a/libsubid/subid.h.in
+++ b/libsubid/subid.h.in
@@ -40,6 +40,22 @@ extern "C" {
#endif
/*
+ * subid_init: initialize libsubid
+ *
+ * @progname: Name to display as program. If NULL, then "(libsubid)" will be
+ * shown in error messages.
+ * @logfd: Open file pointer to pass error messages to. If NULL, then
+ * /dev/null will be opened and messages will be sent there. The
+ * default if libsubid_init() is not called is stderr (2).
+ *
+ * This function does not need to be called. If not called, then the defaults
+ * will be used.
+ *
+ * Returns false if an error occurred.
+ */
+bool subid_init(const char *progname, FILE *logfd);
+
+/*
* subid_get_uid_ranges: return a list of UID ranges for a user
*
* @owner: username being queried