static int user_implicit_bounds(hashtab_t users_tab, char *user_id, user_datum_t * user) { user_datum_t *bounds; char *bounds_id, *delim; delim = strrchr(user_id, '.'); if (!delim) return 0; /* no implicit boundary */ bounds_id = strdup(user_id); if (!bounds_id) { yyerror("out of memory"); return -1; } bounds_id[(size_t) (delim - user_id)] = '\0'; bounds = hashtab_search(users_tab, bounds_id); if (!bounds) { yyerror2("user %s doesn't exist, is implicit bounds of %s", bounds_id, user_id); return -1; } if (!user->bounds) user->bounds = bounds->s.value; else if (user->bounds != bounds->s.value) { yyerror2("user %s has inconsistent bounds %s/%s", user_id, bounds_id, policydbp->p_role_val_to_name[user->bounds - 1]); return -1; } free(bounds_id); return 0; }
static void ScanCodeBlock(void) { int startline = yyline; /* keutzer char c; */ int c; if(curCdBlock==NULL) { curCdBlock = CodeGetBlock(); curCdBlock = CodeMarkLine(curCdBlock,yyline); } while((c=getc(fin))!=EOF) { if (c=='}') return; else if (c=='$') ScanTreeReference(); else curCdBlock = CodeStoreChar(curCdBlock, c); if (c=='\n') yyline++; if (c=='"') ScanString(getput); else if (c=='\'') ScanChar(); else if (c=='/') { if ((c=getc(fin))=='*') { curCdBlock = CodeStoreChar(curCdBlock, '*'); ScanComment(getput); } else ungetc(c, fin); } else if (c=='{') { ScanCodeBlock(); curCdBlock = CodeStoreChar (curCdBlock, '}'); } } yyerror2("{ on line %d has no closing }", startline); nerrors++; }
static void ScanChar(void) { int startline = yyline; /* keutzer char c; */ int c; int saw_backsl = 0; while((c=getput())!=EOF) { if (c=='\'' && !saw_backsl) return; if (c=='\\' && !saw_backsl) { saw_backsl = 1; continue; } saw_backsl = 0; } /* fall thru due to EOF */ yyerror2("unexpected EOF in character constant beginning on line %d", startline); nerrors++; cleanup(1); }
static void ScanComment(char (*rdfunc)(void)) { int startline = yyline; /* keutzer char c; */ int c; int saw_star = 0; while ((c=rdfunc())!=EOF) { if (c=='*') saw_star++; else if(c=='/' && saw_star) { return; } else saw_star = 0; } yyerror2("unexpected EOF in comment beginning on line %d", startline); nerrors++; cleanup(1); }
static void ScanString(char (*rdfunc)(void)) { int startline = yyline; /* keutzer char c; */ int c; int saw_backsl = 0; while((c=rdfunc())!=EOF) { if (c=='"' && !saw_backsl) return; if (c=='\\' && !saw_backsl) { saw_backsl = 1; continue; } saw_backsl = 0; } /* fall thru due to EOF */ yyerror2("unexpected EOF in string beginning on line %d", startline); nerrors++; cleanup(1); }
type_datum_t *declare_type(unsigned char primary, unsigned char isattr) { char *id; type_datum_t *typdatum; int retval; uint32_t value = 0; id = (char *)queue_remove(id_queue); if (!id) { yyerror("no type/attribute name?"); return NULL; } if (strcmp(id, "self") == 0) { yyerror("'self' is a reserved type name and may not be declared."); free(id); return NULL; } typdatum = (type_datum_t *) malloc(sizeof(type_datum_t)); if (!typdatum) { yyerror("Out of memory!"); free(id); return NULL; } type_datum_init(typdatum); typdatum->primary = primary; typdatum->flavor = isattr ? TYPE_ATTRIB : TYPE_TYPE; retval = declare_symbol(SYM_TYPES, id, typdatum, &value, &value); if (retval == 0 || retval == 1) { if (typdatum->primary) { typdatum->s.value = value; } } else { /* error occurred (can't have duplicate type declarations) */ free(id); type_datum_destroy(typdatum); free(typdatum); } switch (retval) { case -3:{ yyerror("Out of memory!"); return NULL; } case -2:{ yyerror2("duplicate declaration of type/attribute"); return NULL; } case -1:{ yyerror("could not declare type/attribute here"); return NULL; } case 0: case 1:{ return typdatum; } default:{ assert(0); /* should never get here */ } } }
int yylex(void) { register c; register char *cp; yylval.y_nodep = (struct node *) NULL; cp = token_buffer; while((c=getc(fin))!=EOF) { switch(c) { case ' ': case '\t': case '\f': continue; case '@': case '[': case ']': case ';': case ':': case '(': case ')': case ',': case '=': case '*': if(debug_flag&DB_LEX) { putc(c,stderr); putc('\n', stderr); } *cp++ = c; *cp = '\0'; return(c); case '{': ScanCodeBlock(); yylval.y_code = curCdBlock; curCdBlock = NULL; *cp++ = '{'; *cp = '}'; return(CBLOCK); case '\n': yyline++; continue; case '/': if ((c=getc(fin))=='*') { ScanComment(get); continue; } else { ungetc(c, fin); c = '/'; } /* FALL THRU */ default: if (isdigit(c)) { int errs = 0; do { if(cp > &token_buffer[MAXIDSIZE]) { token_buffer[MAXIDSIZE] = '\0'; yyerror("number too long"); errs++; } else *cp++ = c; c = getc(fin); } while (isdigit(c)); if(isalpha(c)) yyerror2("illegal digit '%c'", c); ungetc(c, fin); if(errs) return(ERROR); yylval.y_int = atoi(token_buffer); return(NUMBER); } if (isalpha(c)) { SymbolEntry *sp; int errs = 0; do { if(cp > &token_buffer[MAXIDSIZE]) { token_buffer[MAXIDSIZE] = '\0'; yyerror("ID too long"); errs++; } else *cp++ = c; c = getc(fin); } while (isalpha(c)||isdigit(c)||c=='_'); ungetc(c, fin); if(errs) return(ERROR); *cp = '\0'; sp = SymbolLookup (token_buffer); if (sp==NULL) { /* undefined */ yylval.y_symp = SymbolAllocate(token_buffer); } else { /* already defined */ if (sp->attr == A_KEYWORD) return (sp->sd.keyword); yylval.y_symp = sp; } if(debug_flag&DB_LEX) fprintf(stderr, "ID\n"); return(ID); } yyerror2("illegal character (\\%03o)", c); } } strcpy(token_buffer, "EOF"); return(0); }