libsubid: don't print error messages on stderr by default
Closes #325 Add a new subid_init() function which can be used to specify the stream on which error messages should be printed. (If you want to get fancy you can redirect that to memory :) If subid_init() is not called, use stderr. If NULL is passed, then /dev/null will be used. This patch also fixes up the 'Prog', which previously had to be defined by any program linking against libsubid. Now, by default in libsubid it will show (subid). Once subid_init() is called, it will use the first variable passed to subid_init(). Signed-off-by: Serge Hallyn <serge@hallyn.com>
This commit is contained in:
20
lib/nss.c
20
lib/nss.c
@ -56,7 +56,7 @@ void nss_init(char *nsswitch_path) {
|
||||
// subid: files
|
||||
nssfp = fopen(nsswitch_path, "r");
|
||||
if (!nssfp) {
|
||||
fprintf(stderr, "Failed opening %s: %m", nsswitch_path);
|
||||
fprintf(shadow_logfd, "Failed opening %s: %m", nsswitch_path);
|
||||
atomic_store(&nss_init_completed, true);
|
||||
return;
|
||||
}
|
||||
@ -82,16 +82,16 @@ void nss_init(char *nsswitch_path) {
|
||||
goto done;
|
||||
}
|
||||
if (strlen(token) > 50) {
|
||||
fprintf(stderr, "Subid NSS module name too long (longer than 50 characters): %s\n", token);
|
||||
fprintf(stderr, "Using files\n");
|
||||
fprintf(shadow_logfd, "Subid NSS module name too long (longer than 50 characters): %s\n", token);
|
||||
fprintf(shadow_logfd, "Using files\n");
|
||||
subid_nss = NULL;
|
||||
goto done;
|
||||
}
|
||||
snprintf(libname, 64, "libsubid_%s.so", token);
|
||||
h = dlopen(libname, RTLD_LAZY);
|
||||
if (!h) {
|
||||
fprintf(stderr, "Error opening %s: %s\n", libname, dlerror());
|
||||
fprintf(stderr, "Using files\n");
|
||||
fprintf(shadow_logfd, "Error opening %s: %s\n", libname, dlerror());
|
||||
fprintf(shadow_logfd, "Using files\n");
|
||||
subid_nss = NULL;
|
||||
goto done;
|
||||
}
|
||||
@ -102,7 +102,7 @@ void nss_init(char *nsswitch_path) {
|
||||
}
|
||||
subid_nss->has_range = dlsym(h, "shadow_subid_has_range");
|
||||
if (!subid_nss->has_range) {
|
||||
fprintf(stderr, "%s did not provide @has_range@\n", libname);
|
||||
fprintf(shadow_logfd, "%s did not provide @has_range@\n", libname);
|
||||
dlclose(h);
|
||||
free(subid_nss);
|
||||
subid_nss = NULL;
|
||||
@ -110,7 +110,7 @@ void nss_init(char *nsswitch_path) {
|
||||
}
|
||||
subid_nss->list_owner_ranges = dlsym(h, "shadow_subid_list_owner_ranges");
|
||||
if (!subid_nss->list_owner_ranges) {
|
||||
fprintf(stderr, "%s did not provide @list_owner_ranges@\n", libname);
|
||||
fprintf(shadow_logfd, "%s did not provide @list_owner_ranges@\n", libname);
|
||||
dlclose(h);
|
||||
free(subid_nss);
|
||||
subid_nss = NULL;
|
||||
@ -118,7 +118,7 @@ void nss_init(char *nsswitch_path) {
|
||||
}
|
||||
subid_nss->has_any_range = dlsym(h, "shadow_subid_has_any_range");
|
||||
if (!subid_nss->has_any_range) {
|
||||
fprintf(stderr, "%s did not provide @has_any_range@\n", libname);
|
||||
fprintf(shadow_logfd, "%s did not provide @has_any_range@\n", libname);
|
||||
dlclose(h);
|
||||
free(subid_nss);
|
||||
subid_nss = NULL;
|
||||
@ -126,7 +126,7 @@ void nss_init(char *nsswitch_path) {
|
||||
}
|
||||
subid_nss->find_subid_owners = dlsym(h, "shadow_subid_find_subid_owners");
|
||||
if (!subid_nss->find_subid_owners) {
|
||||
fprintf(stderr, "%s did not provide @find_subid_owners@\n", libname);
|
||||
fprintf(shadow_logfd, "%s did not provide @find_subid_owners@\n", libname);
|
||||
dlclose(h);
|
||||
free(subid_nss);
|
||||
subid_nss = NULL;
|
||||
@ -135,7 +135,7 @@ void nss_init(char *nsswitch_path) {
|
||||
subid_nss->handle = h;
|
||||
goto done;
|
||||
}
|
||||
fprintf(stderr, "No usable subid NSS module found, using files\n");
|
||||
fprintf(shadow_logfd, "No usable subid NSS module found, using files\n");
|
||||
// subid_nss has to be null here, but to ease reviews:
|
||||
free(subid_nss);
|
||||
subid_nss = NULL;
|
||||
|
Reference in New Issue
Block a user