version 1.7, 2022/03/22 01:51:36 |
version 1.10, 2022/03/25 22:43:43 |
|
|
|
|
%{ |
%{ |
#include <sys/queue.h> |
#include <sys/queue.h> |
#include <sys/stat.h> |
|
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdarg.h> |
#include <stdarg.h> |
#include <unistd.h> |
|
#include <ctype.h> |
#include <ctype.h> |
|
|
#include "blind.h" |
#include "blind.h" |
|
#include "config.h" |
#include "log.h" |
#include "log.h" |
|
|
TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files); |
//TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files); |
static struct file { |
static struct file { |
TAILQ_ENTRY(file) entry; |
// TAILQ_ENTRY(file) entry; |
FILE *stream; |
FILE *stream; |
char *name; |
char *name; |
size_t ungetpos; |
size_t ungetpos; |
Line 37 static struct file { |
|
Line 36 static struct file { |
|
int eof_reached; |
int eof_reached; |
int lineno; |
int lineno; |
int errors; |
int errors; |
} *file, *top; |
} *file; |
|
//, *top; |
|
|
int lookup(char *); |
int lookup(char *); |
int igetc(void); |
int igetc(void); |
Line 48 int kw_cmp(const void *, const void *); |
|
Line 48 int kw_cmp(const void *, const void *); |
|
int yyparse(void); |
int yyparse(void); |
int yylex(void); |
int yylex(void); |
int yyerror(const char *, ...) |
int yyerror(const char *, ...) |
__attribute__((__format__ (printf, 1, 2))) |
__attribute__((__format__ (printf, 1, 2))) |
__attribute__((__nonnull__ (1))); |
__attribute__((__nonnull__ (1))); |
|
|
int config_load(struct blind *); |
int config_load(struct blind *); |
struct file *config_push(const char *); |
struct file *config_push(const char *); |
int config_pop(void); |
int config_pop(void); |
int config_perm(int, const char *); |
|
|
|
|
|
TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead); |
TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead); |
struct sym { |
struct sym { |
TAILQ_ENTRY(sym) entry; |
TAILQ_ENTRY(sym) entry; |
Line 203 lgetc(int quotec) |
|
Line 201 lgetc(int quotec) |
|
if ((c = igetc()) == EOF) { |
if ((c = igetc()) == EOF) { |
yyerror("reached end of file while parsing " |
yyerror("reached end of file while parsing " |
"quoted string"); |
"quoted string"); |
if (file == top || config_pop() == EOF) |
// if (file == top || config_pop() == EOF) |
|
if (config_pop() == EOF) |
return (EOF); |
return (EOF); |
return (quotec); |
return (quotec); |
} |
} |
Line 231 lgetc(int quotec) |
|
Line 230 lgetc(int quotec) |
|
return ('\n'); |
return ('\n'); |
} |
} |
while (c == EOF) { |
while (c == EOF) { |
if (file == top || config_pop() == EOF) |
//if (file == top || config_pop() == EOF) |
|
if (config_pop() == EOF) |
return (EOF); |
return (EOF); |
c = igetc(); |
c = igetc(); |
} |
} |
Line 445 config_load(struct blind *temp) |
|
Line 445 config_load(struct blind *temp) |
|
// config_purge(PURGE_ALL); |
// config_purge(PURGE_ALL); |
return (-1); |
return (-1); |
} |
} |
top = file; |
// top = file; |
|
|
yyparse(); |
yyparse(); |
|
|
Line 488 config_push(const char *name) |
|
Line 488 config_push(const char *name) |
|
free(nfile); |
free(nfile); |
return (NULL); |
return (NULL); |
} |
} |
nfile->lineno = TAILQ_EMPTY(&files) ? 1 : 0; |
nfile->lineno = 1; // TAILQ_EMPTY(&files) ? 1 : 0; |
nfile->ungetsize = 16; |
nfile->ungetsize = 16; |
nfile->ungetbuf = malloc(nfile->ungetsize); |
nfile->ungetbuf = malloc(nfile->ungetsize); |
if (nfile->ungetbuf == NULL) { |
if (nfile->ungetbuf == NULL) { |
Line 498 config_push(const char *name) |
|
Line 498 config_push(const char *name) |
|
free(nfile); |
free(nfile); |
return (NULL); |
return (NULL); |
} |
} |
TAILQ_INSERT_TAIL(&files, nfile, entry); |
//TAILQ_INSERT_TAIL(&files, nfile, entry); |
return (nfile); |
return (nfile); |
} |
} |
|
|
int |
int |
config_pop(void) |
config_pop(void) |
{ |
{ |
struct file *prv; |
// struct file *prv; |
|
|
if ((prv = TAILQ_PREV(file, files, entry)) != NULL) |
//if ((prv = TAILQ_PREV(file, files, entry)) != NULL) |
prv->errors += file->errors; |
// prv->errors += file->errors; |
|
|
TAILQ_REMOVE(&files, file, entry); |
// TAILQ_REMOVE(&files, file, entry); |
fclose(file->stream); |
fclose(file->stream); |
free(file->name); |
free(file->name); |
free(file->ungetbuf); |
free(file->ungetbuf); |
free(file); |
// free(file); |
file = prv; |
// file = prv; |
|
|
return (file ? 0 : EOF); |
// return (file ? 0 : EOF); |
} |
return (EOF); |
|
|
int |
|
config_perm(int fd, const char *name) |
|
{ |
|
struct stat st; |
|
|
|
if (fstat(fd, &st)) { |
|
log_debug("cannot stat config file"); |
|
return (-1); |
|
} |
|
if (st.st_uid != 0 && st.st_uid != getuid()) { |
|
log_debug("not root or current user owned"); |
|
return (-1); |
|
} |
|
if (st.st_mode & (S_IWGRP | S_IXGRP | S_IRWXO)) { |
|
log_debug("insecure config file"); |
|
return (-1); |
|
} |
|
return (0); |
|
} |
} |