-/* $OpenBSD: parse.y,v 1.28 2018/08/03 17:51:40 benno Exp $ */
+/* $OpenBSD: parse.y,v 1.29 2018/08/03 17:57:21 benno Exp $ */
/*
* Copyright (c) 2016 Kristaps Dzonsons <kristaps@bsd.lv>
int
kw_cmp(const void *k, const void *e)
{
- return (strcmp(k, ((const struct keywords *)e)->k_name));
+ return strcmp(k, ((const struct keywords *)e)->k_name);
}
int
p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
sizeof(keywords[0]), kw_cmp);
- if (p)
- return (p->k_val);
+ if (p != NULL)
+ return p->k_val;
else
- return (STRING);
+ return STRING;
}
#define START_EXPAND 1
else
break;
}
- return (c);
+ return c;
}
int
"quoted string");
if (file == topfile || popfile() == EOF)
return (EOF);
- return (quotec);
+ return quotec;
}
- return (c);
+ return c;
}
while ((c = igetc()) == '\\') {
*/
if (file->eof_reached == 0) {
file->eof_reached = 1;
- return ('\n');
+ return '\n';
}
while (c == EOF) {
if (file == topfile || popfile() == EOF)
c = igetc();
}
}
- return (c);
+ return c;
}
void
if (c == EOF)
break;
}
- return (ERROR);
+ return ERROR;
}
int
if (c == '$' && !expanding) {
while (1) {
if ((c = lgetc(0)) == EOF)
- return (0);
+ return 0;
if (p + 1 >= buf + sizeof(buf) - 1) {
yyerror("string too long");
- return (findeol());
+ return findeol();
}
if (isalnum(c) || c == '_') {
*p++ = c;
val = symget(buf);
if (val == NULL) {
yyerror("macro '%s' not defined", buf);
- return (findeol());
+ return findeol();
}
p = val + strlen(val) - 1;
lungetc(DONE_EXPAND);
quotec = c;
while (1) {
if ((c = lgetc(quotec)) == EOF)
- return (0);
+ return 0;
if (c == '\n') {
file->lineno++;
continue;
} else if (c == '\\') {
if ((next = lgetc(quotec)) == EOF)
- return (0);
+ return 0;
if (next == quotec || c == ' ' || c == '\t')
c = next;
else if (next == '\n') {
break;
} else if (c == '\0') {
yyerror("syntax error");
- return (findeol());
+ return findeol();
}
if (p + 1 >= buf + sizeof(buf) - 1) {
yyerror("string too long");
- return (findeol());
+ return findeol();
}
*p++ = c;
}
yylval.v.string = strdup(buf);
if (yylval.v.string == NULL)
err(EXIT_FAILURE, "%s", __func__);
- return (STRING);
+ return STRING;
}
#define allowed_to_end_number(x) \
*p++ = c;
if ((unsigned)(p-buf) >= sizeof(buf)) {
yyerror("string too long");
- return (findeol());
+ return findeol();
}
} while ((c = lgetc(0)) != EOF && isdigit(c));
lungetc(c);
*p = '\0';
yylval.v.number = strtonum(buf, LLONG_MIN,
LLONG_MAX, &errstr);
- if (errstr) {
+ if (errstr != NULL) {
yyerror("\"%s\" invalid number: %s",
buf, errstr);
return (findeol());
}
- return (NUMBER);
+ return NUMBER;
} else {
nodigits:
while (p > buf + 1)
lungetc(*--p);
c = *--p;
if (c == '-')
- return (c);
+ return c;
}
}
if ((yylval.v.string = strdup(buf)) == NULL)
err(EXIT_FAILURE, "%s", __func__);
}
- return (token);
+ return token;
}
if (c == '\n') {
yylval.lineno = file->lineno;
file->lineno++;
}
if (c == EOF)
- return (0);
- return (c);
+ return 0;
+ return c;
}
struct file *
if ((nfile = calloc(1, sizeof(struct file))) == NULL) {
warn("%s", __func__);
- return (NULL);
+ return NULL;
}
if ((nfile->name = strdup(name)) == NULL) {
warn("%s", __func__);
free(nfile);
- return (NULL);
+ return NULL;
}
if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
warn("%s: %s", __func__, nfile->name);
free(nfile->name);
free(nfile);
- return (NULL);
+ return NULL;
}
nfile->lineno = TAILQ_EMPTY(&files) ? 1 : 0;
nfile->ungetsize = 16;
fclose(nfile->stream);
free(nfile->name);
free(nfile);
- return (NULL);
+ return NULL;
}
TAILQ_INSERT_TAIL(&files, nfile, entry);
- return (nfile);
+ return nfile;
}
int
if ((file = pushfile(filename)) == NULL) {
free(conf);
- return (NULL);
+ return NULL;
}
topfile = file;
}
}
- if (errors) {
+ if (errors != 0) {
clear_config(conf);
- return (NULL);
+ return NULL;
}
if (opts & ACME_OPT_CHECK)
print_config(conf);
- return (conf);
+ return conf;
}
int
}
}
if ((sym = calloc(1, sizeof(*sym))) == NULL)
- return (-1);
+ return -1;
sym->nam = strdup(nam);
if (sym->nam == NULL) {
free(sym);
- return (-1);
+ return -1;
}
sym->val = strdup(val);
if (sym->val == NULL) {
free(sym->nam);
free(sym);
- return (-1);
+ return -1;
}
sym->used = 0;
sym->persist = persist;
TAILQ_INSERT_TAIL(&symhead, sym, entry);
- return (0);
+ return 0;
}
int
size_t len;
if ((val = strrchr(s, '=')) == NULL)
- return (-1);
+ return -1;
len = strlen(s) - strlen(val) + 1;
if ((sym = malloc(len)) == NULL)
ret = symset(sym, val + 1, 1);
free(sym);
- return (ret);
+ return ret;
}
char *
TAILQ_FOREACH(sym, &symhead, entry) {
if (strcmp(nam, sym->nam) == 0) {
sym->used = 1;
- return (sym->val);
+ return sym->val;
}
}
- return (NULL);
+ return NULL;
}
struct authority_c *
struct authority_c *a;
a = authority_find(c, s);
- if (a)
- return (NULL);
+ if (a != NULL)
+ return NULL;
if ((a = calloc(1, sizeof(struct authority_c))) == NULL)
err(EXIT_FAILURE, "%s", __func__);
TAILQ_INSERT_TAIL(&c->authority_list, a, entry);
a->name = s;
- return (a);
+ return a;
}
struct authority_c *
TAILQ_FOREACH(a, &c->authority_list, entry) {
if (strncmp(a->name, s, AUTH_MAXLEN) == 0) {
- return (a);
+ return a;
}
}
- return (NULL);
+ return NULL;
}
struct authority_c *
struct domain_c *d;
d = domain_find(c, s);
- if (d)
+ if (d != NULL)
return (NULL);
if ((d = calloc(1, sizeof(struct domain_c))) == NULL)
err(EXIT_FAILURE, "%s", __func__);
d->domain = s;
TAILQ_INIT(&d->altname_list);
- return (d);
+ return d;
}
struct domain_c *
TAILQ_FOREACH(d, &c->domain_list, entry) {
if (strncmp(d->domain, s, DOMAIN_MAXLEN) == 0) {
- return (d);
+ return d;
}
}
- return (NULL);
+ return NULL;
}
struct keyfile *
LIST_FOREACH(k, &c->used_key_list, entry) {
if (strncmp(k->name, s, PATH_MAX) == 0) {
- return (NULL);
+ return NULL;
}
}
LIST_INSERT_HEAD(&c->used_key_list, k, entry);
k->name = s;
- return (k);
+ return k;
}
void
for ( ; *cp != '\0'; cp++)
if (!(*cp == '.' || *cp == '-' ||
*cp == '_' || isalnum((int)*cp)))
- return (0);
- return (1);
+ return 0;
+ return 1;
}
int
if (s[0] != '/') {
warnx("%s: not an absolute path", s);
- return (0);
+ return 0;
}
if (dontstat)
- return (1);
+ return 1;
if (stat(s, &st)) {
warn("cannot stat %s", s);
- return (0);
+ return 0;
}
if (st.st_mode & (S_IRWXG | S_IRWXO)) {
warnx("%s: group read/writable or world read/writable", s);
- return (0);
+ return 0;
}
- return (1);
+ return 1;
}