summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerge Hallyn <serge@hallyn.com>2023-10-04 10:38:48 -0500
committerSerge Hallyn <serge@hallyn.com>2023-10-20 18:46:23 -0500
commitfa68441bc4be8edeaad8d104344e987b31ed44e6 (patch)
tree33924d961624ca839cc75f91829aaf14f95043bd
parentd73f480ddc47acfa7bb71587c703f741e46f1033 (diff)
Improve the login.defs unknown item error message
Closes #746 Only print the 'unknown item' message to syslog if we are actually parsing a login.defs. Prefix it with "shadow:" to make it clear in syslog where it came from. Also add the source filename to the console message. I'm not quite clear on the econf API, so not sure whether in that path we will end up actually having the path, or printing ''. Signed-off-by: Serge Hallyn <serge@hallyn.com>
-rw-r--r--lib/getdef.c9
-rw-r--r--lib/getdef.h2
-rw-r--r--src/groupadd.c2
-rw-r--r--src/useradd.c2
4 files changed, 8 insertions, 7 deletions
diff --git a/lib/getdef.c b/lib/getdef.c
index f4f8734f..977660c2 100644
--- a/lib/getdef.c
+++ b/lib/getdef.c
@@ -363,7 +363,7 @@ unsigned long getdef_ulong (const char *item, unsigned long dflt)
* (also used when loading the initial defaults)
*/
-int putdef_str (const char *name, const char *value)
+int putdef_str (const char *name, const char *value, const char *srcfile)
{
struct itemdef *d;
char *cp;
@@ -378,6 +378,8 @@ int putdef_str (const char *name, const char *value)
*/
d = def_find (name);
if (NULL == d) {
+ if (NULL != srcfile)
+ SYSLOG ((LOG_CRIT, "shadow: unknown configuration item '%s' in '%s'", name, srcfile));
return -1;
}
@@ -431,7 +433,6 @@ static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *name)
fprintf (shadow_logfd,
_("configuration error - unknown item '%s' (notify administrator)\n"),
name);
- SYSLOG ((LOG_CRIT, "unknown configuration item `%s'", name));
out:
return NULL;
@@ -512,7 +513,7 @@ static void def_load (void)
* The error was already reported to the user and to
* syslog. The tools will just use their default values.
*/
- (void)putdef_str (keys[i], value);
+ (void)putdef_str (keys[i], value, econf_getPath(defs_file));
free(value);
}
@@ -585,7 +586,7 @@ static void def_load (void)
* The error was already reported to the user and to
* syslog. The tools will just use their default values.
*/
- (void)putdef_str (name, value);
+ (void)putdef_str (name, value, def_fname);
}
if (ferror (fp) != 0) {
diff --git a/lib/getdef.h b/lib/getdef.h
index 2bd3fc5f..f55e28b7 100644
--- a/lib/getdef.h
+++ b/lib/getdef.h
@@ -16,7 +16,7 @@ extern int getdef_num (const char *, int);
extern unsigned long getdef_ulong (const char *, unsigned long);
extern unsigned int getdef_unum (const char *, unsigned int);
extern /*@observer@*/ /*@null@*/const char *getdef_str (const char *);
-extern int putdef_str (const char *, const char *);
+extern int putdef_str (const char *, const char *, const char *);
extern void setdef_config_file (const char* file);
/* default UMASK value if not specified in /etc/login.defs */
diff --git a/src/groupadd.c b/src/groupadd.c
index d2421845..0a59509a 100644
--- a/src/groupadd.c
+++ b/src/groupadd.c
@@ -429,7 +429,7 @@ static void process_flags (int argc, char **argv)
}
/* terminate name, point to value */
*cp++ = '\0';
- if (putdef_str (optarg, cp) < 0) {
+ if (putdef_str (optarg, cp, NULL) < 0) {
exit (E_BAD_ARG);
}
break;
diff --git a/src/useradd.c b/src/useradd.c
index 2d859725..9c00d646 100644
--- a/src/useradd.c
+++ b/src/useradd.c
@@ -1399,7 +1399,7 @@ static void process_flags (int argc, char **argv)
/* terminate name, point to value */
*cp = '\0';
cp++;
- if (putdef_str (optarg, cp) < 0) {
+ if (putdef_str (optarg, cp, NULL) < 0) {
exit (E_BAD_ARG);
}
break;