Annotation of coherent/d/bin/uucheck/checkperms/checkperms.y, revision 1.1.1.1

1.1       root        1: /* checkperms.y
                      2:  * yacc grammar to read permissions description files.
                      3:  * part of uucheck.
                      4:  */
                      5: 
                      6: %token FOREACH PATHNAME STRING INDENT UNINDENT NL ERROR_TOKEN WARNING_TOKEN
                      7: %token EXIST OWNER GROUP CHMOD_PERMISSION NUMBER
                      8: %token FILE_TOKEN DIRECTORY PIPE CHARACTER_SPECIAL BLOCK_SPECIAL
                      9: %start statement_list
                     10: %%
                     11: 
                     12: statement_list : statement
                     13:                | statement_list statement
                     14:                ;
                     15: 
                     16: statement      : foreach_block
                     17:                | path_block
                     18:                | message_statement NL
                     19:                | NL    /* Blank line is nop.  */
                     20:                | error NL
                     21:                        {yyerrok;}
                     22:                ;
                     23: 
                     24: /* This is our looping construct--it runs through all possible hosts.  */
                     25: foreach_block  : foreach_declarator NL block {
                     26:                         /* Put lost character back into stdin.  */
                     27:                        my_ungetchar(delayed_char);
                     28: #ifdef DEBUG
                     29:                        printf("%d:  finished foreach_block.\n", lineno);
                     30: #endif /* DEBUG */
                     31:                } /* finish a foreach_block */
                     32:                ;
                     33: 
                     34: foreach_declarator     : FOREACH string {
                     35:                                if(host_looping) {
                     36:                                  FATAL("%d: foreach can not nest.",
                     37:                                          lineno);
                     38:                                } else {
                     39: #ifdef DEBUG
                     40: /* DEBUG */              printf("%d: Foreach identified\n", lineno);
                     41: #endif /* DEBUG */
                     42:                                  host_looping = TRUE;
                     43:                                  current_host = first_host($2);
                     44:                                  saving_to_monitor_file = TRUE;
                     45:                                  reading_from_monitor_file = FALSE;
                     46:                                  open_monitor_file(); /* Start saving input.  */
                     47:                                } /* if host_looping */
                     48:                        } /* FOREACH */
                     49:                        ;
                     50: 
                     51: /* There's one of these for each file.  */
                     52: path_block     : path_declarator NL block {
                     53:                        /* Once beyond the scope of a path_block, make sure
                     54:                         * that there is no current_path set.
                     55:                         */
                     56:                        free(current_path);
                     57:                        current_path = NULL;
                     58:                } /* path_block */
                     59:                ;
                     60: 
                     61: path_declarator        : PATHNAME string {
                     62:                        if(host_looping) {
                     63:                                /* We need to build a whole pathname.  */
                     64:                                current_path = malloc(strlen(current_host)+
                     65:                                                      strlen($2) + 1 );
                     66:                                /* Insert the current host into the 
                     67:                                 * partial path provided. */
                     68:                                sprintf(current_path, $2, current_host);
                     69:                        } else {
                     70:                                if(current_path != NULL) {
                     71:                                  FATAL("%d: pathnames can not be nested.\n",
                     72:                                         lineno);
                     73:                                } /* if there is a current path */
                     74:                                copy_str(&current_path, $2);
                     75:                        } /* if in a loop of host names */
                     76: 
                     77:                        /* Now that we have a full pathname, we can build
                     78:                         * a stat structure for it.
                     79:                         */
                     80:                        if (stat(current_path, &current_stat) == -1){
                     81: #ifdef DEBUG
                     82: /* DEBUG */            printf("Can not stat %s.\n", current_path);
                     83: #endif /* DEBUG */
                     84:                                it_exists = FALSE;
                     85:                        } /* if stat failed */
                     86:                        else {
                     87: #ifdef DEBUG
                     88: /* DEBUG */            printf("Just stat ed %s.\n", current_path);
                     89: #endif /* DEBUG */
                     90:                                it_exists = TRUE;
                     91:                        } /* else stat succeeded */
                     92:                        sprintf(bigbuf, "Examining %s.\n", current_path);
                     93:                        REALLYVERBOSE(bigbuf);
                     94:                }
                     95:                ;
                     96: 
                     97: block          : INDENT statement_list UNINDENT
                     98:                | /* nothing--blocks are optional */
                     99:                ;
                    100: 
                    101: message_statement      : message_type check_type string {
                    102: #ifdef DEBUG
                    103: /* DEBUG */                printf("%d: Message %d, Check %d, String:  %s\n",
                    104:                                lineno, $1, $2, $3);
                    105: #endif /* DEBUG */
                    106:                            do_check($1, $2, $3);
                    107:                        } /* message_type check_type */
                    108:                        | message_type check_type {
                    109: #ifdef DEBUG
                    110: /* DEBUG */                printf("%d: Message %d, Check %d\n",
                    111:                                lineno, $1, $2);
                    112: #endif
                    113:                            do_check($1, $2, NULL);
                    114:                        } /* message_type check_type */
                    115:                        ;
                    116: 
                    117: /* Should this generate error, or warning messages?  */
                    118: message_type   : ERROR_TOKEN
                    119:                        {$$ = ERROR_TOKEN;}
                    120:                | WARNING_TOKEN
                    121:                        {$$ = WARNING_TOKEN;}
                    122:                ;
                    123: 
                    124: /* What are we checking about the file?  */
                    125: check_type     :       existence
                    126:                        {$$=$1;}
                    127:                |       file_type
                    128:                        {$$=$1;}
                    129:                |       ownership
                    130:                        {$$=$1;}
                    131:                |       groupship
                    132:                        {$$=$1;}
                    133:                |       CHMOD_PERMISSION {
                    134:                          $$=CHMOD_PERMISSION;
                    135:                        } /* CHMOD_PERMISSION */
                    136:                ;
                    137:                
                    138: existence      :       EXIST
                    139:                        {$$=EXIST;}
                    140:                ;
                    141: 
                    142: file_type      :       FILE_TOKEN
                    143:                        {$$=FILE_TOKEN;}
                    144:                |       DIRECTORY
                    145:                        {$$=DIRECTORY;}
                    146:                |       PIPE
                    147:                        {$$=PIPE;}
                    148:                |       CHARACTER_SPECIAL
                    149:                        {$$=CHARACTER_SPECIAL;}
                    150:                |       BLOCK_SPECIAL
                    151:                        {$$=BLOCK_SPECIAL;}
                    152:                ;
                    153: 
                    154: ownership      :       OWNER string {
                    155:                                $$=OWNER;
                    156:                                copy_str(&id_string, $2);
                    157:                        } /* ownership */
                    158:                ;
                    159: 
                    160: groupship      :       GROUP string {
                    161:                                $$=GROUP;
                    162:                                copy_str(&id_string, $2);
                    163:                        } /* groupship */
                    164:                ;
                    165: 
                    166: string         :       STRING {
                    167:                          $$=ret_string; 
                    168:                          ret_string = NULL;
                    169:                        } /* string */
                    170:                ;
                    171: 
                    172: number         :       NUMBER {
                    173:                          $$ = ret_number;
                    174:                        } /* number */
                    175:                ;
                    176: %%
                    177: 
                    178: #include <stdio.h>
                    179: #include "checkperms.h"
                    180: #include "monitor.h"
                    181: 
                    182: yyerror (s)
                    183:        char *s;
                    184: {
                    185:        fprintf (stderr, "line %d: %s, Token: %d\n", lineno, s, yychar);
                    186: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.