]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: motd(): Report errors instead of exiting from library code
authorAlejandro Colomar <alx@kernel.org>
Fri, 15 Nov 2024 22:55:18 +0000 (23:55 +0100)
committerSerge Hallyn <serge@hallyn.com>
Sat, 8 Feb 2025 05:22:10 +0000 (23:22 -0600)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/motd.c
lib/prototypes.h
src/login.c

index bed9efae2b0edc80fa522e8b61dff879be28441c..a2efc4ea149dbd67982bbf7900dfd7d4eef3aef2 100644 (file)
@@ -17,7 +17,6 @@
 #include "defines.h"
 #include "getdef.h"
 #include "prototypes.h"
-#include "string/strdup/xstrdup.h"
 
 
 /*
@@ -27,7 +26,7 @@
  * it to the user's terminal at login time.  The MOTD_FILE configuration
  * option is a colon-delimited list of filenames.
  */
-void
+int
 motd(void)
 {
        FILE *fp;
@@ -37,11 +36,12 @@ motd(void)
        int c;
 
        motdfile = getdef_str ("MOTD_FILE");
-       if (NULL == motdfile) {
-               return;
-       }
+       if (NULL == motdfile)
+               return 0;
 
-       motdlist = xstrdup (motdfile);
+       motdlist = strdup(motdfile);
+       if (motdlist == NULL)
+               return -1;
 
        mb = motdlist;
        while (NULL != (motdfile = strsep(&mb, ":"))) {
@@ -57,4 +57,5 @@ motd(void)
        fflush (stdout);
 
        free (motdlist);
+       return 0;
 }
index f85c14663db1332afb063db325dcfa3bc55cfc14..79bd0fdd684aaf20baa520d1fd63be9abc233a0c 100644 (file)
@@ -222,7 +222,7 @@ extern void login_prompt (char *, int);
 extern void mailcheck (void);
 
 /* motd.c */
-extern void motd (void);
+extern int motd(void);
 
 /* myname.c */
 extern /*@null@*//*@only@*/struct passwd *get_my_pwent (void);
index 349df16d8e83d0b0fef5ae1ac1a820590f6f2cf0..2866b1523ccd40af75af04dbd47901497c5a5d45 100644 (file)
@@ -21,6 +21,7 @@
 #include <pwd.h>
 #include <signal.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <assert.h>
@@ -1175,7 +1176,9 @@ int main (int argc, char **argv)
                 * this
                 */
 #ifndef USE_PAM
-               motd ();        /* print the message of the day */
+               if (motd() == -1)
+                       exit(EXIT_FAILURE);
+
                if (   getdef_bool ("FAILLOG_ENAB")
                    && (0 != faillog.fail_cnt)) {
                        failprint (&faillog);