]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1179] error messages for -u/--user and -i when built w/o droproot
authorDave Hart <hart@ntp.org>
Fri, 8 May 2009 01:23:43 +0000 (01:23 +0000)
committerDave Hart <hart@ntp.org>
Fri, 8 May 2009 01:23:43 +0000 (01:23 +0000)
bk: 4a03899fSOOjPWKnKNA9DIxAIircXg

ChangeLog
ntpd/cmd_args.c

index ec51d67add7ba0502d405dca7b545daa010a3a58..96fb32a077dd107d412646db17448ce0a2cc0af0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 ---
 
 * [Bug 784] Make --enable-linuxcaps the default when available
+* [Bug 1179] error messages for -u/--user and -i lacking droproot
 * Updated JJY reference clock driver from Takao abe
 * Log a message and exit before trying to use FD_SET with a descriptor
   larger than FD_SETSIZE, which will corrupt memory beyond the fd_set
index 760bcede58498ffed61da59b69aa049f365d4715..7843bc317162e431fa72d63a6b6bd1f168a18406 100644 (file)
@@ -87,6 +87,16 @@ getCmdOpts(
                        droproot = 1;
                        chrootdir = OPT_ARG( JAILDIR );
 #else
+                       fprintf(stderr, 
+                               "command line -i option (jaildir) is not supported by this binary"
+# ifndef SYS_WINNT
+                               ",\n" "can not drop root privileges.  See configure options\n"
+                               "--enable-clockctl and --enable-linuxcaps.\n");
+# else
+                               ".\n");
+# endif
+                       msyslog(LOG_ERR, 
+                               "command line -i option (jaildir) is not supported by this binary.");
                        errflg++;
 #endif
        }
@@ -118,8 +128,8 @@ getCmdOpts(
                stats_config(STATS_STATSDIR, OPT_ARG( STATSDIR ));
 
        if (HAVE_OPT( TRUSTEDKEY )) {
-               int           ct = STACKCT_OPT(  TRUSTEDKEY );
-               const char**  pp = STACKLST_OPT( TRUSTEDKEY );
+               int             ct = STACKCT_OPT(  TRUSTEDKEY );
+               const char**    pp = STACKLST_OPT( TRUSTEDKEY );
 
                do  {
                        u_long tkey;
@@ -141,23 +151,29 @@ getCmdOpts(
                char *ntp_optarg = OPT_ARG( USER );
 
                droproot = 1;
-               user = malloc(strlen(ntp_optarg) + 1);
-               if (user == NULL) {
-                       errflg++;
-               } else {
-                       (void)strncpy(user, ntp_optarg, strlen(ntp_optarg) + 1);
-                       group = rindex(user, ':');
-                       if (group)
-                               *group++ = '\0'; /* get rid of the ':' */
-               }
+               user = emalloc(strlen(ntp_optarg) + 1);
+               (void)strncpy(user, ntp_optarg, strlen(ntp_optarg) + 1);
+               group = rindex(user, ':');
+               if (group)
+                       *group++ = '\0'; /* get rid of the ':' */
 #else
+               fprintf(stderr, 
+                       "command line -u/--user option is not supported by this binary"
+# ifndef SYS_WINNT
+                       ",\n" "can not drop root privileges.  See configure options\n"
+                       "--enable-clockctl and --enable-linuxcaps.\n");
+# else
+                       ".\n");
+# endif
+               msyslog(LOG_ERR, 
+                       "command line -u/--user option is not supported by this binary.");
                errflg++;
 #endif
        }
 
        if (HAVE_OPT( VAR )) {
-               int           ct = STACKCT_OPT(  VAR );
-               const char**  pp = STACKLST_OPT( VAR );
+               int             ct = STACKCT_OPT(  VAR );
+               const char**    pp = STACKLST_OPT( VAR );
 
                do  {
                        const char* my_ntp_optarg = *pp++;
@@ -168,8 +184,8 @@ getCmdOpts(
        }
 
        if (HAVE_OPT( DVAR )) {
-               int           ct = STACKCT_OPT(  DVAR );
-               const char**  pp = STACKLST_OPT( DVAR );
+               int             ct = STACKCT_OPT(  DVAR );
+               const char**    pp = STACKLST_OPT( DVAR );
 
                do  {
                        const char* my_ntp_optarg = *pp++;
@@ -188,9 +204,12 @@ getCmdOpts(
                if (val >= 0)
                        interface_interval = val;
                else {
-                       msyslog(LOG_ERR,
-                               "command line interface update interval %ld must be greater or equal to 0",
-                                     val);
+                       fprintf(stderr, 
+                               "command line interface update interval %ld must not be negative\n",
+                               val);
+                       msyslog(LOG_ERR, 
+                               "command line interface update interval %ld must not be negative",
+                               val);
                        errflg++;
                }
        }
@@ -225,7 +244,8 @@ getCmdOpts(
 #endif /* SIM */
 
        if (errflg || argc) {
-               printf("argc is <%d>\n", argc);
+               if (argc)
+                       fprintf(stderr, "argc after processing is <%d>\n", argc);
                optionUsage(myOptions, 2);
        }
        return;