Diff for /embedaddon/sudo/plugins/sudoers/defaults.c between versions 1.1 and 1.1.1.6

version 1.1, 2012/02/21 16:23:02 version 1.1.1.6, 2014/06/15 16:12:54
Line 1 Line 1
 /*  /*
 * Copyright (c) 1999-2005, 2007-2011 * Copyright (c) 1999-2005, 2007-2014
  *      Todd C. Miller <Todd.Miller@courtesan.com>   *      Todd C. Miller <Todd.Miller@courtesan.com>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
Line 22 Line 22
 #include <config.h>  #include <config.h>
   
 #include <sys/types.h>  #include <sys/types.h>
 #include <sys/param.h>  
 #include <stdio.h>  #include <stdio.h>
 #ifdef STDC_HEADERS  #ifdef STDC_HEADERS
 # include <stdlib.h>  # include <stdlib.h>
Line 91  static struct strmap priorities[] = { Line 90  static struct strmap priorities[] = {
 /*  /*
  * Local prototypes.   * Local prototypes.
  */   */
static int store_int(char *, struct sudo_defs_types *, int);static bool store_int(char *, struct sudo_defs_types *, int);
static int store_list(char *, struct sudo_defs_types *, int);static bool store_list(char *, struct sudo_defs_types *, int);
static int store_mode(char *, struct sudo_defs_types *, int);static bool store_mode(char *, struct sudo_defs_types *, int);
static int store_str(char *, struct sudo_defs_types *, int);static bool store_str(char *, struct sudo_defs_types *, int);
static int store_syslogfac(char *, struct sudo_defs_types *, int);static bool store_syslogfac(char *, struct sudo_defs_types *, int);
static int store_syslogpri(char *, struct sudo_defs_types *, int);static bool store_syslogpri(char *, struct sudo_defs_types *, int);
static int store_tuple(char *, struct sudo_defs_types *, int);static bool store_tuple(char *, struct sudo_defs_types *, int);
static int store_uint(char *, struct sudo_defs_types *, int);static bool store_uint(char *, struct sudo_defs_types *, int);
static int store_float(char *, struct sudo_defs_types *, int);static bool store_float(char *, struct sudo_defs_types *, int);
 static void list_op(char *, size_t, struct sudo_defs_types *, enum list_ops);  static void list_op(char *, size_t, struct sudo_defs_types *, enum list_ops);
 static const char *logfac2str(int);  static const char *logfac2str(int);
 static const char *logpri2str(int);  static const char *logpri2str(int);
Line 119  dump_defaults(void) Line 118  dump_defaults(void)
     struct list_member *item;      struct list_member *item;
     struct def_values *def;      struct def_values *def;
     char *desc;      char *desc;
       debug_decl(dump_defaults, SUDO_DEBUG_DEFAULTS)
   
     for (cur = sudo_defs_table; cur->name; cur++) {      for (cur = sudo_defs_table; cur->name; cur++) {
         if (cur->desc) {          if (cur->desc) {
Line 148  dump_defaults(void) Line 148  dump_defaults(void)
                         sudo_printf(SUDO_CONV_INFO_MSG, "\n");                          sudo_printf(SUDO_CONV_INFO_MSG, "\n");
                     }                      }
                     break;                      break;
                 case T_UINT:  
                 case T_INT:                  case T_INT:
                     sudo_printf(SUDO_CONV_INFO_MSG, desc, cur->sd_un.ival);                      sudo_printf(SUDO_CONV_INFO_MSG, desc, cur->sd_un.ival);
                     sudo_printf(SUDO_CONV_INFO_MSG, "\n");                      sudo_printf(SUDO_CONV_INFO_MSG, "\n");
                     break;                      break;
                   case T_UINT:
                       sudo_printf(SUDO_CONV_INFO_MSG, desc, cur->sd_un.uival);
                       sudo_printf(SUDO_CONV_INFO_MSG, "\n");
                       break;
                 case T_FLOAT:                  case T_FLOAT:
                     sudo_printf(SUDO_CONV_INFO_MSG, desc, cur->sd_un.fval);                      sudo_printf(SUDO_CONV_INFO_MSG, desc, cur->sd_un.fval);
                     sudo_printf(SUDO_CONV_INFO_MSG, "\n");                      sudo_printf(SUDO_CONV_INFO_MSG, "\n");
Line 162  dump_defaults(void) Line 165  dump_defaults(void)
                     sudo_printf(SUDO_CONV_INFO_MSG, "\n");                      sudo_printf(SUDO_CONV_INFO_MSG, "\n");
                     break;                      break;
                 case T_LIST:                  case T_LIST:
                    if (cur->sd_un.list) {                    if (!SLIST_EMPTY(&cur->sd_un.list)) {
                         sudo_printf(SUDO_CONV_INFO_MSG, "%s\n", desc);                          sudo_printf(SUDO_CONV_INFO_MSG, "%s\n", desc);
                        for (item = cur->sd_un.list; item; item = item->next) {                        SLIST_FOREACH(item, &cur->sd_un.list, entries) {
                             sudo_printf(SUDO_CONV_INFO_MSG,                              sudo_printf(SUDO_CONV_INFO_MSG,
                                 "\t%s\n", item->value);                                  "\t%s\n", item->value);
                         }                          }
Line 172  dump_defaults(void) Line 175  dump_defaults(void)
                     break;                      break;
                 case T_TUPLE:                  case T_TUPLE:
                     for (def = cur->values; def->sval; def++) {                      for (def = cur->values; def->sval; def++) {
                        if (cur->sd_un.ival == def->ival) {                        if (cur->sd_un.tuple == def->nval) {
                             sudo_printf(SUDO_CONV_INFO_MSG, desc, def->sval);                              sudo_printf(SUDO_CONV_INFO_MSG, desc, def->sval);
                             break;                              break;
                         }                          }
Line 182  dump_defaults(void) Line 185  dump_defaults(void)
             }              }
         }          }
     }      }
       debug_return;
 }  }
   
 /*  /*
Line 191  dump_defaults(void) Line 195  dump_defaults(void)
  * Eg. you may want to turn off logging to a file for some hosts.   * Eg. you may want to turn off logging to a file for some hosts.
  * This is only meaningful for variables that are *optional*.   * This is only meaningful for variables that are *optional*.
  */   */
intbool
 set_default(char *var, char *val, int op)  set_default(char *var, char *val, int op)
 {  {
     struct sudo_defs_types *cur;      struct sudo_defs_types *cur;
     int num;      int num;
       debug_decl(set_default, SUDO_DEBUG_DEFAULTS)
   
     for (cur = sudo_defs_table, num = 0; cur->name; cur++, num++) {      for (cur = sudo_defs_table, num = 0; cur->name; cur++, num++) {
         if (strcmp(var, cur->name) == 0)          if (strcmp(var, cur->name) == 0)
             break;              break;
     }      }
     if (!cur->name) {      if (!cur->name) {
        warningx(_("unknown defaults entry `%s'"), var);        warningx(U_("unknown defaults entry `%s'"), var);
        return FALSE;        debug_return_bool(false);
     }      }
   
     switch (cur->type & T_MASK) {      switch (cur->type & T_MASK) {
         case T_LOGFAC:          case T_LOGFAC:
             if (!store_syslogfac(val, cur, op)) {              if (!store_syslogfac(val, cur, op)) {
                 if (val)                  if (val)
                    warningx(_("value `%s' is invalid for option `%s'"),                    warningx(U_("value `%s' is invalid for option `%s'"),
                         val, var);                          val, var);
                 else                  else
                    warningx(_("no value specified for `%s'"), var);                    warningx(U_("no value specified for `%s'"), var);
                return FALSE;                debug_return_bool(false);
             }              }
             break;              break;
         case T_LOGPRI:          case T_LOGPRI:
             if (!store_syslogpri(val, cur, op)) {              if (!store_syslogpri(val, cur, op)) {
                 if (val)                  if (val)
                    warningx(_("value `%s' is invalid for option `%s'"),                    warningx(U_("value `%s' is invalid for option `%s'"),
                         val, var);                          val, var);
                 else                  else
                    warningx(_("no value specified for `%s'"), var);                    warningx(U_("no value specified for `%s'"), var);
                return FALSE;                debug_return_bool(false);
             }              }
             break;              break;
         case T_STR:          case T_STR:
             if (!val) {              if (!val) {
                 /* Check for bogus boolean usage or lack of a value. */                  /* Check for bogus boolean usage or lack of a value. */
                if (!ISSET(cur->type, T_BOOL) || op != FALSE) {                if (!ISSET(cur->type, T_BOOL) || op != false) {
                    warningx(_("no value specified for `%s'"), var);                    warningx(U_("no value specified for `%s'"), var);
                    return FALSE;                    debug_return_bool(false);
                 }                  }
             }              }
             if (ISSET(cur->type, T_PATH) && val && *val != '/') {              if (ISSET(cur->type, T_PATH) && val && *val != '/') {
                warningx(_("values for `%s' must start with a '/'"), var);                warningx(U_("values for `%s' must start with a '/'"), var);
                return FALSE;                debug_return_bool(false);
             }              }
             if (!store_str(val, cur, op)) {              if (!store_str(val, cur, op)) {
                warningx(_("value `%s' is invalid for option `%s'"), val, var);                warningx(U_("value `%s' is invalid for option `%s'"), val, var);
                return FALSE;                debug_return_bool(false);
             }              }
             break;              break;
         case T_INT:          case T_INT:
             if (!val) {              if (!val) {
                 /* Check for bogus boolean usage or lack of a value. */                  /* Check for bogus boolean usage or lack of a value. */
                if (!ISSET(cur->type, T_BOOL) || op != FALSE) {                if (!ISSET(cur->type, T_BOOL) || op != false) {
                    warningx(_("no value specified for `%s'"), var);                    warningx(U_("no value specified for `%s'"), var);
                    return FALSE;                    debug_return_bool(false);
                 }                  }
             }              }
             if (!store_int(val, cur, op)) {              if (!store_int(val, cur, op)) {
                warningx(_("value `%s' is invalid for option `%s'"), val, var);                warningx(U_("value `%s' is invalid for option `%s'"), val, var);
                return FALSE;                debug_return_bool(false);
             }              }
             break;              break;
         case T_UINT:          case T_UINT:
             if (!val) {              if (!val) {
                 /* Check for bogus boolean usage or lack of a value. */                  /* Check for bogus boolean usage or lack of a value. */
                if (!ISSET(cur->type, T_BOOL) || op != FALSE) {                if (!ISSET(cur->type, T_BOOL) || op != false) {
                    warningx(_("no value specified for `%s'"), var);                    warningx(U_("no value specified for `%s'"), var);
                    return FALSE;                    debug_return_bool(false);
                 }                  }
             }              }
             if (!store_uint(val, cur, op)) {              if (!store_uint(val, cur, op)) {
                warningx(_("value `%s' is invalid for option `%s'"), val, var);                warningx(U_("value `%s' is invalid for option `%s'"), val, var);
                return FALSE;                debug_return_bool(false);
             }              }
             break;              break;
         case T_FLOAT:          case T_FLOAT:
             if (!val) {              if (!val) {
                 /* Check for bogus boolean usage or lack of a value. */                  /* Check for bogus boolean usage or lack of a value. */
                if (!ISSET(cur->type, T_BOOL) || op != FALSE) {                if (!ISSET(cur->type, T_BOOL) || op != false) {
                    warningx(_("no value specified for `%s'"), var);                    warningx(U_("no value specified for `%s'"), var);
                    return FALSE;                    debug_return_bool(false);
                 }                  }
             }              }
             if (!store_float(val, cur, op)) {              if (!store_float(val, cur, op)) {
                warningx(_("value `%s' is invalid for option `%s'"), val, var);                warningx(U_("value `%s' is invalid for option `%s'"), val, var);
                return FALSE;                debug_return_bool(false);
             }              }
             break;              break;
         case T_MODE:          case T_MODE:
             if (!val) {              if (!val) {
                 /* Check for bogus boolean usage or lack of a value. */                  /* Check for bogus boolean usage or lack of a value. */
                if (!ISSET(cur->type, T_BOOL) || op != FALSE) {                if (!ISSET(cur->type, T_BOOL) || op != false) {
                    warningx(_("no value specified for `%s'"), var);                    warningx(U_("no value specified for `%s'"), var);
                    return FALSE;                    debug_return_bool(false);
                 }                  }
             }              }
             if (!store_mode(val, cur, op)) {              if (!store_mode(val, cur, op)) {
                warningx(_("value `%s' is invalid for option `%s'"), val, var);                warningx(U_("value `%s' is invalid for option `%s'"), val, var);
                return FALSE;                debug_return_bool(false);
             }              }
             break;              break;
         case T_FLAG:          case T_FLAG:
             if (val) {              if (val) {
                warningx(_("option `%s' does not take a value"), var);                warningx(U_("option `%s' does not take a value"), var);
                return FALSE;                debug_return_bool(false);
             }              }
             cur->sd_un.flag = op;              cur->sd_un.flag = op;
             break;              break;
         case T_LIST:          case T_LIST:
             if (!val) {              if (!val) {
                 /* Check for bogus boolean usage or lack of a value. */                  /* Check for bogus boolean usage or lack of a value. */
                if (!ISSET(cur->type, T_BOOL) || op != FALSE) {                if (!ISSET(cur->type, T_BOOL) || op != false) {
                    warningx(_("no value specified for `%s'"), var);                    warningx(U_("no value specified for `%s'"), var);
                    return FALSE;                    debug_return_bool(false);
                 }                  }
             }              }
             if (!store_list(val, cur, op)) {              if (!store_list(val, cur, op)) {
                warningx(_("value `%s' is invalid for option `%s'"), val, var);                warningx(U_("value `%s' is invalid for option `%s'"), val, var);
                return FALSE;                debug_return_bool(false);
             }              }
             break;              break;
         case T_TUPLE:          case T_TUPLE:
             if (!val && !ISSET(cur->type, T_BOOL)) {              if (!val && !ISSET(cur->type, T_BOOL)) {
                warningx(_("no value specified for `%s'"), var);                warningx(U_("no value specified for `%s'"), var);
                return FALSE;                debug_return_bool(false);
             }              }
             if (!store_tuple(val, cur, op)) {              if (!store_tuple(val, cur, op)) {
                warningx(_("value `%s' is invalid for option `%s'"), val, var);                warningx(U_("value `%s' is invalid for option `%s'"), val, var);
                return FALSE;                debug_return_bool(false);
             }              }
             break;              break;
     }      }
   
    return TRUE;    debug_return_bool(true);
 }  }
   
 /*  /*
Line 340  init_defaults(void) Line 345  init_defaults(void)
 {  {
     static int firsttime = 1;      static int firsttime = 1;
     struct sudo_defs_types *def;      struct sudo_defs_types *def;
       debug_decl(init_defaults, SUDO_DEBUG_DEFAULTS)
   
     /* Clear any old settings. */      /* Clear any old settings. */
     if (!firsttime) {      if (!firsttime) {
Line 353  init_defaults(void) Line 359  init_defaults(void)
                     list_op(NULL, 0, def, freeall);                      list_op(NULL, 0, def, freeall);
                     break;                      break;
             }              }
            zero_bytes(&def->sd_un, sizeof(def->sd_un));            memset(&def->sd_un, 0, sizeof(def->sd_un));
         }          }
     }      }
   
     /* First initialize the flags. */      /* First initialize the flags. */
 #ifdef LONG_OTP_PROMPT  #ifdef LONG_OTP_PROMPT
    def_long_otp_prompt = TRUE;    def_long_otp_prompt = true;
 #endif  #endif
 #ifdef IGNORE_DOT_PATH  #ifdef IGNORE_DOT_PATH
    def_ignore_dot = TRUE;    def_ignore_dot = true;
 #endif  #endif
 #ifdef ALWAYS_SEND_MAIL  #ifdef ALWAYS_SEND_MAIL
    def_mail_always = TRUE;    def_mail_always = true;
 #endif  #endif
 #ifdef SEND_MAIL_WHEN_NO_USER  #ifdef SEND_MAIL_WHEN_NO_USER
    def_mail_no_user = TRUE;    def_mail_no_user = true;
 #endif  #endif
 #ifdef SEND_MAIL_WHEN_NO_HOST  #ifdef SEND_MAIL_WHEN_NO_HOST
    def_mail_no_host = TRUE;    def_mail_no_host = true;
 #endif  #endif
 #ifdef SEND_MAIL_WHEN_NOT_OK  #ifdef SEND_MAIL_WHEN_NOT_OK
    def_mail_no_perms = TRUE;    def_mail_no_perms = true;
 #endif  #endif
 #ifndef NO_TTY_TICKETS  #ifndef NO_TTY_TICKETS
    def_tty_tickets = TRUE;    def_tty_tickets = true;
 #endif  #endif
 #ifndef NO_LECTURE  #ifndef NO_LECTURE
     def_lecture = once;      def_lecture = once;
 #endif  #endif
 #ifndef NO_AUTHENTICATION  #ifndef NO_AUTHENTICATION
    def_authenticate = TRUE;    def_authenticate = true;
 #endif  #endif
 #ifndef NO_ROOT_SUDO  #ifndef NO_ROOT_SUDO
    def_root_sudo = TRUE;    def_root_sudo = true;
 #endif  #endif
 #ifdef HOST_IN_LOG  #ifdef HOST_IN_LOG
    def_log_host = TRUE;    def_log_host = true;
 #endif  #endif
 #ifdef SHELL_IF_NO_ARGS  #ifdef SHELL_IF_NO_ARGS
    def_shell_noargs = TRUE;    def_shell_noargs = true;
 #endif  #endif
 #ifdef SHELL_SETS_HOME  #ifdef SHELL_SETS_HOME
    def_set_home = TRUE;    def_set_home = true;
 #endif  #endif
 #ifndef DONT_LEAK_PATH_INFO  #ifndef DONT_LEAK_PATH_INFO
    def_path_info = TRUE;    def_path_info = true;
 #endif  #endif
 #ifdef FQDN  #ifdef FQDN
    def_fqdn = TRUE;    def_fqdn = true;
 #endif  #endif
 #ifdef USE_INSULTS  #ifdef USE_INSULTS
    def_insults = TRUE;    def_insults = true;
 #endif  #endif
 #ifdef ENV_EDITOR  #ifdef ENV_EDITOR
    def_env_editor = TRUE;    def_env_editor = true;
 #endif  #endif
 #ifdef UMASK_OVERRIDE  #ifdef UMASK_OVERRIDE
    def_umask_override = TRUE;    def_umask_override = true;
 #endif  #endif
     def_iolog_file = estrdup("%{seq}");      def_iolog_file = estrdup("%{seq}");
     def_iolog_dir = estrdup(_PATH_SUDO_IO_LOGDIR);      def_iolog_dir = estrdup(_PATH_SUDO_IO_LOGDIR);
     def_sudoers_locale = estrdup("C");      def_sudoers_locale = estrdup("C");
     def_env_reset = ENV_RESET;      def_env_reset = ENV_RESET;
    def_set_logname = TRUE;    def_set_logname = true;
     def_closefrom = STDERR_FILENO + 1;      def_closefrom = STDERR_FILENO + 1;
       def_pam_service = estrdup("sudo");
   #ifdef HAVE_PAM_LOGIN
       def_pam_login_service = estrdup("sudo-i");
   #else
       def_pam_login_service = estrdup("sudo");
   #endif
   #ifdef NO_PAM_SESSION
       def_pam_session = false;
   #else
       def_pam_session = true;
   #endif
   #ifdef HAVE_INNETGR
       def_use_netgroups = true;
   #endif
   
     /* Syslog options need special care since they both strings and ints */      /* Syslog options need special care since they both strings and ints */
 #if (LOGGING & SLOG_SYSLOG)  #if (LOGGING & SLOG_SYSLOG)
    (void) store_syslogfac(LOGFAC, &sudo_defs_table[I_SYSLOG], TRUE);    (void) store_syslogfac(LOGFAC, &sudo_defs_table[I_SYSLOG], true);
     (void) store_syslogpri(PRI_SUCCESS, &sudo_defs_table[I_SYSLOG_GOODPRI],      (void) store_syslogpri(PRI_SUCCESS, &sudo_defs_table[I_SYSLOG_GOODPRI],
        TRUE);        true);
     (void) store_syslogpri(PRI_FAILURE, &sudo_defs_table[I_SYSLOG_BADPRI],      (void) store_syslogpri(PRI_FAILURE, &sudo_defs_table[I_SYSLOG_BADPRI],
        TRUE);        true);
 #endif  #endif
   
     /* Password flags also have a string and integer component. */      /* Password flags also have a string and integer component. */
    (void) store_tuple("any", &sudo_defs_table[I_LISTPW], TRUE);    (void) store_tuple("any", &sudo_defs_table[I_LISTPW], true);
    (void) store_tuple("all", &sudo_defs_table[I_VERIFYPW], TRUE);    (void) store_tuple("all", &sudo_defs_table[I_VERIFYPW], true);
   
     /* Then initialize the int-like things. */      /* Then initialize the int-like things. */
 #ifdef SUDO_UMASK  #ifdef SUDO_UMASK
Line 443  init_defaults(void) Line 463  init_defaults(void)
     def_passwd_timeout = PASSWORD_TIMEOUT;      def_passwd_timeout = PASSWORD_TIMEOUT;
     def_passwd_tries = TRIES_FOR_PASSWORD;      def_passwd_tries = TRIES_FOR_PASSWORD;
 #ifdef HAVE_ZLIB_H  #ifdef HAVE_ZLIB_H
    def_compress_io = TRUE;    def_compress_io = true;
 #endif  #endif
   
     /* Now do the strings */      /* Now do the strings */
     def_mailto = estrdup(MAILTO);      def_mailto = estrdup(MAILTO);
    def_mailsub = estrdup(_(MAILSUBJECT));    def_mailsub = estrdup(N_(MAILSUBJECT));
     def_badpass_message = estrdup(_(INCORRECT_PASSWORD));      def_badpass_message = estrdup(_(INCORRECT_PASSWORD));
       def_lecture_status_dir = estrdup(_PATH_SUDO_LECTURE_DIR);
     def_timestampdir = estrdup(_PATH_SUDO_TIMEDIR);      def_timestampdir = estrdup(_PATH_SUDO_TIMEDIR);
     def_passprompt = estrdup(_(PASSPROMPT));      def_passprompt = estrdup(_(PASSPROMPT));
     def_runas_default = estrdup(RUNAS_DEFAULT);      def_runas_default = estrdup(RUNAS_DEFAULT);
Line 467  init_defaults(void) Line 488  init_defaults(void)
     def_secure_path = estrdup(SECURE_PATH);      def_secure_path = estrdup(SECURE_PATH);
 #endif  #endif
     def_editor = estrdup(EDITOR);      def_editor = estrdup(EDITOR);
    def_set_utmp = TRUE;    def_set_utmp = true;
     def_pam_setcred = true;
   
     /* Finally do the lists (currently just environment tables). */      /* Finally do the lists (currently just environment tables). */
     init_envtables();      init_envtables();
   
     firsttime = 0;      firsttime = 0;
   
       debug_return;
 }  }
   
 /*  /*
  * Update the defaults based on what was set by sudoers.   * Update the defaults based on what was set by sudoers.
  * Pass in an OR'd list of which default types to update.   * Pass in an OR'd list of which default types to update.
  */   */
intbool
 update_defaults(int what)  update_defaults(int what)
 {  {
     struct defaults *def;      struct defaults *def;
    int rc = TRUE;    bool rc = true;
     debug_decl(update_defaults, SUDO_DEBUG_DEFAULTS)
   
    tq_foreach_fwd(&defaults, def) {    TAILQ_FOREACH(def, &defaults, entries) {
         switch (def->type) {          switch (def->type) {
             case DEFAULTS:              case DEFAULTS:
                 if (ISSET(what, SETDEF_GENERIC) &&                  if (ISSET(what, SETDEF_GENERIC) &&
                     !set_default(def->var, def->val, def->op))                      !set_default(def->var, def->val, def->op))
                    rc = FALSE;                    rc = false;
                 break;                  break;
             case DEFAULTS_USER:              case DEFAULTS_USER:
   #if 1
                   if (ISSET(what, SETDEF_USER)) {
                       int m;
                       m = userlist_matches(sudo_user.pw, def->binding);
                       if (m == ALLOW) {
                           if (!set_default(def->var, def->val, def->op))
                               rc = false;
                       }
                   }
   #else
                 if (ISSET(what, SETDEF_USER) &&                  if (ISSET(what, SETDEF_USER) &&
                    userlist_matches(sudo_user.pw, &def->binding) == ALLOW &&                    userlist_matches(sudo_user.pw, def->binding) == ALLOW &&
                     !set_default(def->var, def->val, def->op))                      !set_default(def->var, def->val, def->op))
                    rc = FALSE;                    rc = false;
 #endif
                 break;                  break;
             case DEFAULTS_RUNAS:              case DEFAULTS_RUNAS:
                 if (ISSET(what, SETDEF_RUNAS) &&                  if (ISSET(what, SETDEF_RUNAS) &&
                    runaslist_matches(&def->binding, NULL) == ALLOW &&                    runaslist_matches(def->binding, NULL, NULL, NULL) == ALLOW &&
                     !set_default(def->var, def->val, def->op))                      !set_default(def->var, def->val, def->op))
                    rc = FALSE;                    rc = false;
                 break;                  break;
             case DEFAULTS_HOST:              case DEFAULTS_HOST:
                 if (ISSET(what, SETDEF_HOST) &&                  if (ISSET(what, SETDEF_HOST) &&
                    hostlist_matches(&def->binding) == ALLOW &&                    hostlist_matches(def->binding) == ALLOW &&
                     !set_default(def->var, def->val, def->op))                      !set_default(def->var, def->val, def->op))
                    rc = FALSE;                    rc = false;
                 break;                  break;
             case DEFAULTS_CMND:              case DEFAULTS_CMND:
                 if (ISSET(what, SETDEF_CMND) &&                  if (ISSET(what, SETDEF_CMND) &&
                    cmndlist_matches(&def->binding) == ALLOW &&                    cmndlist_matches(def->binding) == ALLOW &&
                     !set_default(def->var, def->val, def->op))                      !set_default(def->var, def->val, def->op))
                    rc = FALSE;                    rc = false;
                 break;                  break;
         }          }
     }      }
    return rc;    debug_return_bool(rc);
 }  }
   
static int/*
  * Check the defaults entries without actually setting them.
  * Pass in an OR'd list of which default types to check.
  */
 bool
 check_defaults(int what, bool quiet)
 {
     struct sudo_defs_types *cur;
     struct defaults *def;
     bool rc = true;
     debug_decl(check_defaults, SUDO_DEBUG_DEFAULTS)
 
     TAILQ_FOREACH(def, &defaults, entries) {
         switch (def->type) {
             case DEFAULTS:
                 if (!ISSET(what, SETDEF_GENERIC))
                     continue;
                 break;
             case DEFAULTS_USER:
                 if (!ISSET(what, SETDEF_USER))
                     continue;
                 break;
             case DEFAULTS_RUNAS:
                 if (!ISSET(what, SETDEF_RUNAS))
                     continue;
                 break;
             case DEFAULTS_HOST:
                 if (!ISSET(what, SETDEF_HOST))
                     continue;
                 break;
             case DEFAULTS_CMND:
                 if (!ISSET(what, SETDEF_CMND))
                     continue;
                 break;
         }
         for (cur = sudo_defs_table; cur->name != NULL; cur++) {
             if (strcmp(def->var, cur->name) == 0)
                 break;
         }
         if (cur->name == NULL) {
             if (!quiet)
                 warningx(U_("unknown defaults entry `%s'"), def->var);
             rc = false;
         }
     }
     debug_return_bool(rc);
 }
 
 static bool
 store_int(char *val, struct sudo_defs_types *def, int op)  store_int(char *val, struct sudo_defs_types *def, int op)
 {  {
    char *endp;    const char *errstr;
    long l;    int i;
     debug_decl(store_int, SUDO_DEBUG_DEFAULTS)
   
    if (op == FALSE) {    if (op == false) {
         def->sd_un.ival = 0;          def->sd_un.ival = 0;
     } else {      } else {
        l = strtol(val, &endp, 10);        i = strtonum(val, INT_MIN, INT_MAX, &errstr);
        if (*endp != '\0')        if (errstr != NULL) {
            return FALSE;            sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
        /* XXX - should check against INT_MAX */                "%s: %s", val, errstr);
        def->sd_un.ival = (int)l;            debug_return_bool(false);
         }
         def->sd_un.ival = i;
     }      }
     if (def->callback)      if (def->callback)
        return def->callback(val);        debug_return_bool(def->callback(val));
    return TRUE;    debug_return_bool(true);
 }  }
   
static intstatic bool
 store_uint(char *val, struct sudo_defs_types *def, int op)  store_uint(char *val, struct sudo_defs_types *def, int op)
 {  {
    char *endp;    const char *errstr;
    long l;    unsigned int u;
     debug_decl(store_uint, SUDO_DEBUG_DEFAULTS)
   
    if (op == FALSE) {    if (op == false) {
        def->sd_un.ival = 0;        def->sd_un.uival = 0;
     } else {      } else {
        l = strtol(val, &endp, 10);        u = strtonum(val, 0, UINT_MAX, &errstr);
        if (*endp != '\0' || l < 0)        if (errstr != NULL) {
            return FALSE;            sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
        /* XXX - should check against INT_MAX */                "%s: %s", val, errstr);
        def->sd_un.ival = (unsigned int)l;            debug_return_bool(false);
         }
         def->sd_un.uival = u;
     }      }
     if (def->callback)      if (def->callback)
        return def->callback(val);        debug_return_bool(def->callback(val));
    return TRUE;    debug_return_bool(true);
 }  }
   
static intstatic bool
 store_float(char *val, struct sudo_defs_types *def, int op)  store_float(char *val, struct sudo_defs_types *def, int op)
 {  {
     char *endp;      char *endp;
     double d;      double d;
       debug_decl(store_float, SUDO_DEBUG_DEFAULTS)
   
    if (op == FALSE) {    if (op == false) {
         def->sd_un.fval = 0.0;          def->sd_un.fval = 0.0;
     } else {      } else {
         d = strtod(val, &endp);          d = strtod(val, &endp);
         if (*endp != '\0')          if (*endp != '\0')
            return FALSE;            debug_return_bool(false);
         /* XXX - should check against HUGE_VAL */          /* XXX - should check against HUGE_VAL */
         def->sd_un.fval = d;          def->sd_un.fval = d;
     }      }
     if (def->callback)      if (def->callback)
        return def->callback(val);        debug_return_bool(def->callback(val));
    return TRUE;    debug_return_bool(true);
 }  }
   
static intstatic bool
 store_tuple(char *val, struct sudo_defs_types *def, int op)  store_tuple(char *val, struct sudo_defs_types *def, int op)
 {  {
     struct def_values *v;      struct def_values *v;
       debug_decl(store_tuple, SUDO_DEBUG_DEFAULTS)
   
     /*      /*
     * Since enums are really just ints we store the value as an ival.     * Look up tuple value by name to find enum def_tuple value.
     * In the future, there may be multiple enums for different tuple     * For negation to work the first element of enum def_tuple
     * types we want to avoid and special knowledge of the tuple type.     * must be equivalent to boolean false.
     * This does assume that the first entry in the tuple enum will 
     * be the equivalent to a boolean "false". 
      */       */
     if (!val) {      if (!val) {
        def->sd_un.ival = (op == FALSE) ? 0 : 1;        def->sd_un.ival = (op == false) ? 0 : 1;
     } else {      } else {
         for (v = def->values; v->sval != NULL; v++) {          for (v = def->values; v->sval != NULL; v++) {
             if (strcmp(v->sval, val) == 0) {              if (strcmp(v->sval, val) == 0) {
                def->sd_un.ival = v->ival;                def->sd_un.tuple = v->nval;
                 break;                  break;
             }              }
         }          }
         if (v->sval == NULL)          if (v->sval == NULL)
            return FALSE;            debug_return_bool(false);
     }      }
     if (def->callback)      if (def->callback)
        return def->callback(val);        debug_return_bool(def->callback(val));
    return TRUE;    debug_return_bool(true);
 }  }
   
static intstatic bool
 store_str(char *val, struct sudo_defs_types *def, int op)  store_str(char *val, struct sudo_defs_types *def, int op)
 {  {
       debug_decl(store_str, SUDO_DEBUG_DEFAULTS)
   
     efree(def->sd_un.str);      efree(def->sd_un.str);
    if (op == FALSE)    if (op == false)
         def->sd_un.str = NULL;          def->sd_un.str = NULL;
     else      else
         def->sd_un.str = estrdup(val);          def->sd_un.str = estrdup(val);
     if (def->callback)      if (def->callback)
        return def->callback(val);        debug_return_bool(def->callback(val));
    return TRUE;    debug_return_bool(true);
 }  }
   
static intstatic bool
 store_list(char *str, struct sudo_defs_types *def, int op)  store_list(char *str, struct sudo_defs_types *def, int op)
 {  {
     char *start, *end;      char *start, *end;
       debug_decl(store_list, SUDO_DEBUG_DEFAULTS)
   
     /* Remove all old members. */      /* Remove all old members. */
    if (op == FALSE || op == TRUE)    if (op == false || op == true)
         list_op(NULL, 0, def, freeall);          list_op(NULL, 0, def, freeall);
   
     /* Split str into multiple space-separated words and act on each one. */      /* Split str into multiple space-separated words and act on each one. */
    if (op != FALSE) {    if (op != false) {
         end = str;          end = str;
         do {          do {
             /* Remove leading blanks, if nothing but blanks we are done. */              /* Remove leading blanks, if nothing but blanks we are done. */
Line 649  store_list(char *str, struct sudo_defs_types *def, int Line 741  store_list(char *str, struct sudo_defs_types *def, int
             list_op(start, end - start, def, op == '-' ? delete : add);              list_op(start, end - start, def, op == '-' ? delete : add);
         } while (*end++ != '\0');          } while (*end++ != '\0');
     }      }
    return TRUE;    debug_return_bool(true);
 }  }
   
static intstatic bool
 store_syslogfac(char *val, struct sudo_defs_types *def, int op)  store_syslogfac(char *val, struct sudo_defs_types *def, int op)
 {  {
     struct strmap *fac;      struct strmap *fac;
       debug_decl(store_syslogfac, SUDO_DEBUG_DEFAULTS)
   
    if (op == FALSE) {    if (op == false) {
        def->sd_un.ival = FALSE;        def->sd_un.ival = false;
        return TRUE;        debug_return_bool(true);
     }      }
 #ifdef LOG_NFACILITIES  #ifdef LOG_NFACILITIES
     if (!val)      if (!val)
        return FALSE;        debug_return_bool(false);
     for (fac = facilities; fac->name && strcmp(val, fac->name); fac++)      for (fac = facilities; fac->name && strcmp(val, fac->name); fac++)
         ;          ;
     if (fac->name == NULL)      if (fac->name == NULL)
        return FALSE;                          /* not found */        debug_return_bool(false);                /* not found */
   
     def->sd_un.ival = fac->num;      def->sd_un.ival = fac->num;
 #else  #else
     def->sd_un.ival = -1;      def->sd_un.ival = -1;
 #endif /* LOG_NFACILITIES */  #endif /* LOG_NFACILITIES */
    return TRUE;    debug_return_bool(true);
 }  }
   
 static const char *  static const char *
Line 681  logfac2str(int n) Line 774  logfac2str(int n)
 {  {
 #ifdef LOG_NFACILITIES  #ifdef LOG_NFACILITIES
     struct strmap *fac;      struct strmap *fac;
       debug_decl(logfac2str, SUDO_DEBUG_DEFAULTS)
   
     for (fac = facilities; fac->name && fac->num != n; fac++)      for (fac = facilities; fac->name && fac->num != n; fac++)
         ;          ;
    return fac->name;    debug_return_const_str(fac->name);
 #else  #else
     return "default";      return "default";
 #endif /* LOG_NFACILITIES */  #endif /* LOG_NFACILITIES */
 }  }
   
static intstatic bool
 store_syslogpri(char *val, struct sudo_defs_types *def, int op)  store_syslogpri(char *val, struct sudo_defs_types *def, int op)
 {  {
     struct strmap *pri;      struct strmap *pri;
       debug_decl(store_syslogpri, SUDO_DEBUG_DEFAULTS)
   
    if (op == FALSE || !val)    if (op == false || !val)
        return FALSE;        debug_return_bool(false);
   
     for (pri = priorities; pri->name && strcmp(val, pri->name); pri++)      for (pri = priorities; pri->name && strcmp(val, pri->name); pri++)
         ;          ;
     if (pri->name == NULL)      if (pri->name == NULL)
        return FALSE;                          /* not found */        debug_return_bool(false);   /* not found */
   
     def->sd_un.ival = pri->num;      def->sd_un.ival = pri->num;
    return TRUE;    debug_return_bool(true);
 }  }
   
 static const char *  static const char *
 logpri2str(int n)  logpri2str(int n)
 {  {
     struct strmap *pri;      struct strmap *pri;
       debug_decl(logpri2str, SUDO_DEBUG_DEFAULTS)
   
     for (pri = priorities; pri->name && pri->num != n; pri++)      for (pri = priorities; pri->name && pri->num != n; pri++)
         ;          ;
    return pri->name;    debug_return_const_str(pri->name);
 }  }
   
static intstatic bool
 store_mode(char *val, struct sudo_defs_types *def, int op)  store_mode(char *val, struct sudo_defs_types *def, int op)
 {  {
    char *endp;    mode_t mode;
    long l;    const char *errstr;
     debug_decl(store_mode, SUDO_DEBUG_DEFAULTS)
   
    if (op == FALSE) {    if (op == false) {
        def->sd_un.mode = (mode_t)0777;        def->sd_un.mode = 0777;
     } else {      } else {
        l = strtol(val, &endp, 8);        mode = atomode(val, &errstr);
        if (*endp != '\0' || l < 0 || l > 0777)        if (errstr != NULL) {
            return FALSE;            sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
        def->sd_un.mode = (mode_t)l;                "%s is %s", val, errstr);
             debug_return_bool(false);
         }
         def->sd_un.mode = mode;
     }      }
     if (def->callback)      if (def->callback)
        return def->callback(val);        debug_return_bool(def->callback(val));
    return TRUE;    debug_return_bool(true);
 }  }
   
 static void  static void
 list_op(char *val, size_t len, struct sudo_defs_types *def, enum list_ops op)  list_op(char *val, size_t len, struct sudo_defs_types *def, enum list_ops op)
 {  {
    struct list_member *cur, *prev, *tmp;    struct list_member *cur, *prev = NULL;
     debug_decl(list_op, SUDO_DEBUG_DEFAULTS)
   
     if (op == freeall) {      if (op == freeall) {
        for (cur = def->sd_un.list; cur; ) {        while ((cur = SLIST_FIRST(&def->sd_un.list)) != NULL) {
            tmp = cur;            SLIST_REMOVE_HEAD(&def->sd_un.list, entries);
            cur = tmp->next;            efree(cur->value);
            efree(tmp->value);            efree(cur);
            efree(tmp); 
         }          }
        def->sd_un.list = NULL;        debug_return;
        return; 
     }      }
   
    for (cur = def->sd_un.list, prev = NULL; cur; prev = cur, cur = cur->next) {    SLIST_FOREACH(cur, &def->sd_un.list, entries) {
         if ((strncmp(cur->value, val, len) == 0 && cur->value[len] == '\0')) {          if ((strncmp(cur->value, val, len) == 0 && cur->value[len] == '\0')) {
   
             if (op == add)              if (op == add)
                return;                 /* already exists */                debug_return;         /* already exists */
   
             /* Delete node */              /* Delete node */
            if (prev != NULL)            if (prev == NULL)
                prev->next = cur->next;                SLIST_REMOVE_HEAD(&def->sd_un.list, entries);
             else              else
                def->sd_un.list = cur->next;                SLIST_REMOVE_AFTER(prev, entries);
             efree(cur->value);              efree(cur->value);
             efree(cur);              efree(cur);
             break;              break;
         }          }
           prev = cur;
     }      }
   
     /* Add new node to the head of the list. */      /* Add new node to the head of the list. */
     if (op == add) {      if (op == add) {
        cur = emalloc(sizeof(struct list_member));        cur = ecalloc(1, sizeof(struct list_member));
        cur->value = emalloc(len + 1);        cur->value = estrndup(val, len);
        (void) memcpy(cur->value, val, len);        SLIST_INSERT_HEAD(&def->sd_un.list, cur, entries);
        cur->value[len] = '\0'; 
        cur->next = def->sd_un.list; 
        def->sd_un.list = cur; 
     }      }
       debug_return;
 }  }

Removed from v.1.1  
changed lines
  Added in v.1.1.1.6


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>