Diff for /embedaddon/sudo/plugins/sudoers/gram.y between versions 1.1.1.3 and 1.1.1.4

version 1.1.1.3, 2012/10/09 09:29:52 version 1.1.1.4, 2013/07/22 10:46:12
Line 1 Line 1
 %{  %{
 /*  /*
 * Copyright (c) 1996, 1998-2005, 2007-2012 * Copyright (c) 1996, 1998-2005, 2007-2013
  *      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 25 Line 25
 #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 55 Line 54
 #include "sudoers.h" /* XXX */  #include "sudoers.h" /* XXX */
 #include "parse.h"  #include "parse.h"
 #include "toke.h"  #include "toke.h"
 #include "gram.h"  
   
 /*  /*
  * We must define SIZE_MAX for yacc's skeleton.c.   * We must define SIZE_MAX for yacc's skeleton.c.
Line 91  static void  add_defaults(int, struct member *, struct Line 89  static void  add_defaults(int, struct member *, struct
 static void  add_userspec(struct member *, struct privilege *);  static void  add_userspec(struct member *, struct privilege *);
 static struct defaults *new_default(char *, char *, int);  static struct defaults *new_default(char *, char *, int);
 static struct member *new_member(char *, int);  static struct member *new_member(char *, int);
       void  yyerror(const char *);static struct sudo_digest *new_digest(int, const char *);
 
void 
yyerror(const char *s) 
{ 
    debug_decl(yyerror, SUDO_DEBUG_PARSER) 
 
    /* If we last saw a newline the error is on the preceding line. */ 
    if (last_token == COMMENT) 
        sudolineno--; 
 
    /* Save the line the first error occurred on. */ 
    if (errorlineno == -1) { 
        errorlineno = sudolineno; 
        errorfile = estrdup(sudoers); 
    } 
    if (sudoers_warnings && s != NULL) { 
        LEXTRACE("<*> "); 
#ifndef TRACELEXER 
        if (trace_print == NULL || trace_print == sudoers_trace_print) 
            warningx(_(">>> %s: %s near line %d <<<"), sudoers, s, sudolineno); 
#endif 
    } 
    parse_error = true; 
    debug_return; 
} 
 %}  %}
   
 %union {  %union {
Line 125  yyerror(const char *s) Line 98  yyerror(const char *s)
     struct member *member;      struct member *member;
     struct runascontainer *runas;      struct runascontainer *runas;
     struct privilege *privilege;      struct privilege *privilege;
       struct sudo_digest *digest;
     struct sudo_command command;      struct sudo_command command;
     struct cmndtag tag;      struct cmndtag tag;
     struct selinux_info seinfo;      struct selinux_info seinfo;
Line 141  yyerror(const char *s) Line 115  yyerror(const char *s)
 %token <string>  NETGROUP               /* a netgroup (+NAME) */  %token <string>  NETGROUP               /* a netgroup (+NAME) */
 %token <string>  USERGROUP              /* a usergroup (%NAME) */  %token <string>  USERGROUP              /* a usergroup (%NAME) */
 %token <string>  WORD                   /* a word */  %token <string>  WORD                   /* a word */
   %token <string>  DIGEST                 /* a SHA-2 digest */
 %token <tok>     DEFAULTS               /* Defaults entry */  %token <tok>     DEFAULTS               /* Defaults entry */
 %token <tok>     DEFAULTS_HOST          /* Host-specific defaults entry */  %token <tok>     DEFAULTS_HOST          /* Host-specific defaults entry */
 %token <tok>     DEFAULTS_USER          /* User-specific defaults entry */  %token <tok>     DEFAULTS_USER          /* User-specific defaults entry */
Line 170  yyerror(const char *s) Line 145  yyerror(const char *s)
 %token <tok>     PRIVS                  /* Solaris privileges */  %token <tok>     PRIVS                  /* Solaris privileges */
 %token <tok>     LIMITPRIVS             /* Solaris limit privileges */  %token <tok>     LIMITPRIVS             /* Solaris limit privileges */
 %token <tok>     MYSELF                 /* run as myself, not another user */  %token <tok>     MYSELF                 /* run as myself, not another user */
   %token <tok>     SHA224                 /* sha224 digest */
   %token <tok>     SHA256                 /* sha256 digest */
   %token <tok>     SHA384                 /* sha384 digest */
   %token <tok>     SHA512                 /* sha512 digest */
   
 %type <cmndspec>  cmndspec  %type <cmndspec>  cmndspec
 %type <cmndspec>  cmndspeclist  %type <cmndspec>  cmndspeclist
Line 177  yyerror(const char *s) Line 156  yyerror(const char *s)
 %type <defaults>  defaults_list  %type <defaults>  defaults_list
 %type <member>    cmnd  %type <member>    cmnd
 %type <member>    opcmnd  %type <member>    opcmnd
   %type <member>    digcmnd
 %type <member>    cmndlist  %type <member>    cmndlist
 %type <member>    host  %type <member>    host
 %type <member>    hostlist  %type <member>    hostlist
Line 198  yyerror(const char *s) Line 178  yyerror(const char *s)
 %type <privinfo>  solarisprivs  %type <privinfo>  solarisprivs
 %type <string>    privsspec  %type <string>    privsspec
 %type <string>    limitprivsspec  %type <string>    limitprivsspec
   %type <digest>    digest
   
 %%  %%
   
Line 355  cmndspeclist : cmndspec Line 336  cmndspeclist : cmndspec
                         }                          }
                 ;                  ;
   
cmndspec        :       runasspec selinux solarisprivs cmndtag opcmnd {cmndspec        :       runasspec selinux solarisprivs cmndtag digcmnd {
                             struct cmndspec *cs = ecalloc(1, sizeof(*cs));                              struct cmndspec *cs = ecalloc(1, sizeof(*cs));
                             if ($1 != NULL) {                              if ($1 != NULL) {
                                 list2tq(&cs->runasuserlist, $1->runasusers);                                  list2tq(&cs->runasuserlist, $1->runasusers);
Line 385  cmndspec : runasspec selinux solarisprivs cmndtag opcm Line 366  cmndspec : runasspec selinux solarisprivs cmndtag opcm
                         }                          }
                 ;                  ;
   
   digest          :       SHA224 ':' DIGEST {
                               $$ = new_digest(SUDO_DIGEST_SHA224, $3);
                           }
                   |       SHA256 ':' DIGEST {
                               $$ = new_digest(SUDO_DIGEST_SHA256, $3);
                           }
                   |       SHA384 ':' DIGEST {
                               $$ = new_digest(SUDO_DIGEST_SHA384, $3);
                           }
                   |       SHA512 ':' DIGEST {
                               $$ = new_digest(SUDO_DIGEST_SHA512, $3);
                           }
                   ;
   
   digcmnd         :       opcmnd {
                               $$ = $1;
                           }
                   |       digest opcmnd {
                               /* XXX - yuck */
                               struct sudo_command *c = (struct sudo_command *)($2->name);
                               c->digest = $1;
                               $$ = $2;
                           }
                   ;
   
 opcmnd          :       cmnd {  opcmnd          :       cmnd {
                             $$ = $1;                              $$ = $1;
                             $$->negated = false;                              $$->negated = false;
Line 443  solarisprivs : /* empty */ { Line 449  solarisprivs : /* empty */ {
                 |       privsspec {                  |       privsspec {
                             $$.privs = $1;                              $$.privs = $1;
                             $$.limitprivs = NULL;                              $$.limitprivs = NULL;
                        }                               }
                 |       limitprivsspec {                  |       limitprivsspec {
                             $$.privs = NULL;                              $$.privs = NULL;
                             $$.limitprivs = $1;                              $$.limitprivs = $1;
                        }                               }
                 |       privsspec limitprivsspec {                  |       privsspec limitprivsspec {
                             $$.privs = $1;                              $$.privs = $1;
                             $$.limitprivs = $2;                              $$.limitprivs = $2;
                        }                               }
                 |       limitprivsspec privsspec {                  |       limitprivsspec privsspec {
                             $$.limitprivs = $1;                              $$.limitprivs = $1;
                             $$.privs = $2;                              $$.privs = $2;
                        }                               }
                 ;
   
 runasspec       :       /* empty */ {  runasspec       :       /* empty */ {
                             $$ = NULL;                              $$ = NULL;
Line 549  hostaliases : hostalias Line 556  hostaliases : hostalias
 hostalias       :       ALIAS '=' hostlist {  hostalias       :       ALIAS '=' hostlist {
                             char *s;                              char *s;
                             if ((s = alias_add($1, HOSTALIAS, $3)) != NULL) {                              if ((s = alias_add($1, HOSTALIAS, $3)) != NULL) {
                                yyerror(s);                                sudoerserror(s);
                                 YYERROR;                                  YYERROR;
                             }                              }
                         }                          }
Line 569  cmndaliases : cmndalias Line 576  cmndaliases : cmndalias
 cmndalias       :       ALIAS '=' cmndlist {  cmndalias       :       ALIAS '=' cmndlist {
                             char *s;                              char *s;
                             if ((s = alias_add($1, CMNDALIAS, $3)) != NULL) {                              if ((s = alias_add($1, CMNDALIAS, $3)) != NULL) {
                                yyerror(s);                                sudoerserror(s);
                                 YYERROR;                                  YYERROR;
                             }                              }
                         }                          }
                 ;                  ;
   
cmndlist        :       opcmndcmndlist        :       digcmnd
                |       cmndlist ',' opcmnd {                |       cmndlist ',' digcmnd {
                             list_append($1, $3);                              list_append($1, $3);
                             $$ = $1;                              $$ = $1;
                         }                          }
Line 589  runasaliases : runasalias Line 596  runasaliases : runasalias
 runasalias      :       ALIAS '=' userlist {  runasalias      :       ALIAS '=' userlist {
                             char *s;                              char *s;
                             if ((s = alias_add($1, RUNASALIAS, $3)) != NULL) {                              if ((s = alias_add($1, RUNASALIAS, $3)) != NULL) {
                                yyerror(s);                                sudoerserror(s);
                                 YYERROR;                                  YYERROR;
                             }                              }
                         }                          }
Line 602  useraliases : useralias Line 609  useraliases : useralias
 useralias       :       ALIAS '=' userlist {  useralias       :       ALIAS '=' userlist {
                             char *s;                              char *s;
                             if ((s = alias_add($1, USERALIAS, $3)) != NULL) {                              if ((s = alias_add($1, USERALIAS, $3)) != NULL) {
                                yyerror(s);                                sudoerserror(s);
                                 YYERROR;                                  YYERROR;
                             }                              }
                         }                          }
Line 671  group  : ALIAS { Line 678  group  : ALIAS {
                 ;                  ;
   
 %%  %%
   void
   sudoerserror(const char *s)
   {
       debug_decl(sudoerserror, SUDO_DEBUG_PARSER)
   
       /* If we last saw a newline the error is on the preceding line. */
       if (last_token == COMMENT)
           sudolineno--;
   
       /* Save the line the first error occurred on. */
       if (errorlineno == -1) {
           errorlineno = sudolineno;
           errorfile = estrdup(sudoers);
       }
       if (sudoers_warnings && s != NULL) {
           LEXTRACE("<*> ");
   #ifndef TRACELEXER
           if (trace_print == NULL || trace_print == sudoers_trace_print) {
               const char fmt[] = ">>> %s: %s near line %d <<<\n";
               int oldlocale;
   
               /* Warnings are displayed in the user's locale. */
               sudoers_setlocale(SUDOERS_LOCALE_USER, &oldlocale);
               sudo_printf(SUDO_CONV_ERROR_MSG, _(fmt), sudoers, _(s), sudolineno);
               sudoers_setlocale(oldlocale, NULL);
           }
   #endif
       }
       parse_error = true;
       debug_return;
   }
   
 static struct defaults *  static struct defaults *
 new_default(char *var, char *val, int op)  new_default(char *var, char *val, int op)
 {  {
Line 702  new_member(char *name, int type) Line 741  new_member(char *name, int type)
     /* m->next = NULL; */      /* m->next = NULL; */
   
     debug_return_ptr(m);      debug_return_ptr(m);
   }
   
   struct sudo_digest *
   new_digest(int digest_type, const char *digest_str)
   {
       struct sudo_digest *dig;
       debug_decl(new_digest, SUDO_DEBUG_PARSER)
   
       dig = emalloc(sizeof(*dig));
       dig->digest_type = digest_type;
       dig->digest_str = estrdup(digest_str);
   
       debug_return_ptr(dig);
 }  }
   
 /*  /*

Removed from v.1.1.1.3  
changed lines
  Added in v.1.1.1.4


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