Blob


1 /*
2 * Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
3 * Copyright (c) 2016-2019, 2020-2021 Tracey Emery <tracey@traceyemery.net>
4 * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
5 * Copyright (c) 2004 Ryan McBride <mcbride@openbsd.org>
6 * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
7 * Copyright (c) 2001 Markus Friedl. All rights reserved.
8 * Copyright (c) 2001 Daniel Hartmeier. All rights reserved.
9 * Copyright (c) 2001 Theo de Raadt. All rights reserved.
10 *
11 * Permission to use, copy, modify, and distribute this software for any
12 * purpose with or without fee is hereby granted, provided that the above
13 * copyright notice and this permission notice appear in all copies.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
16 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
18 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 */
24 %{
25 #include <sys/time.h>
26 #include <sys/types.h>
27 #include <sys/queue.h>
28 #include <sys/stat.h>
30 #include <ctype.h>
31 #include <err.h>
32 #include <errno.h>
33 #include <event.h>
34 #include <imsg.h>
35 #include <limits.h>
36 #include <sha1.h>
37 #include <stdarg.h>
38 #include <stdlib.h>
39 #include <stdio.h>
40 #include <string.h>
41 #include <syslog.h>
42 #include <unistd.h>
44 #include "got_error.h"
45 #include "got_path.h"
47 #include "log.h"
48 #include "gotd.h"
49 #include "auth.h"
50 #include "listen.h"
52 TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
53 static struct file {
54 TAILQ_ENTRY(file) entry;
55 FILE *stream;
56 char *name;
57 int lineno;
58 int errors;
59 } *file;
60 struct file *newfile(const char *, int);
61 static void closefile(struct file *);
62 int check_file_secrecy(int, const char *);
63 int yyparse(void);
64 int yylex(void);
65 int yyerror(const char *, ...)
66 __attribute__((__format__ (printf, 1, 2)))
67 __attribute__((__nonnull__ (1)));
68 int kw_cmp(const void *, const void *);
69 int lookup(char *);
70 int lgetc(int);
71 int lungetc(int);
72 int findeol(void);
74 TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead);
75 struct sym {
76 TAILQ_ENTRY(sym) entry;
77 int used;
78 int persist;
79 char *nam;
80 char *val;
81 };
83 int symset(const char *, const char *, int);
84 char *symget(const char *);
86 static int errors;
88 static struct gotd *gotd;
89 static struct gotd_repo *new_repo;
90 static int conf_limit_user_connections(const char *, int);
91 static struct gotd_repo *conf_new_repo(const char *);
92 static void conf_new_access_rule(struct gotd_repo *,
93 enum gotd_access, int, char *);
94 static enum gotd_procid gotd_proc_id;
96 typedef struct {
97 union {
98 long long number;
99 char *string;
100 struct timeval tv;
101 } v;
102 int lineno;
103 } YYSTYPE;
105 %}
107 %token PATH ERROR ON UNIX_SOCKET UNIX_GROUP USER REPOSITORY PERMIT DENY
108 %token RO RW CONNECTION LIMIT REQUEST TIMEOUT
110 %token <v.string> STRING
111 %token <v.number> NUMBER
112 %type <v.number> boolean
113 %type <v.tv> timeout
115 %%
117 grammar :
118 | grammar '\n'
119 | grammar main '\n'
120 | grammar repository '\n'
123 boolean : STRING {
124 if (strcasecmp($1, "1") == 0 ||
125 strcasecmp($1, "yes") == 0 ||
126 strcasecmp($1, "on") == 0)
127 $$ = 1;
128 else if (strcasecmp($1, "0") == 0 ||
129 strcasecmp($1, "off") == 0 ||
130 strcasecmp($1, "no") == 0)
131 $$ = 0;
132 else {
133 yyerror("invalid boolean value '%s'", $1);
134 free($1);
135 YYERROR;
137 free($1);
139 | ON { $$ = 1; }
140 | NUMBER { $$ = $1; }
143 timeout : NUMBER {
144 if ($1 < 0) {
145 yyerror("invalid timeout: %lld", $1);
146 YYERROR;
148 $$.tv_sec = $1;
149 $$.tv_usec = 0;
151 | STRING {
152 const char *errstr;
153 const char *type = "seconds";
154 size_t len;
155 int mul = 1;
157 if (*$1 == '\0') {
158 yyerror("invalid number of seconds: %s", $1);
159 free($1);
160 YYERROR;
163 len = strlen($1);
164 switch ($1[len - 1]) {
165 case 'S':
166 case 's':
167 $1[len - 1] = '\0';
168 break;
169 case 'M':
170 case 'm':
171 type = "minutes";
172 mul = 60;
173 $1[len - 1] = '\0';
174 break;
175 case 'H':
176 case 'h':
177 type = "hours";
178 mul = 60 * 60;
179 $1[len - 1] = '\0';
180 break;
183 $$.tv_usec = 0;
184 $$.tv_sec = strtonum($1, 0, INT_MAX / mul, &errstr);
185 if (errstr) {
186 yyerror("number of %s is %s: %s", type,
187 errstr, $1);
188 free($1);
189 YYERROR;
192 $$.tv_sec *= mul;
193 free($1);
197 main : UNIX_SOCKET STRING {
198 if (gotd_proc_id == PROC_LISTEN) {
199 if (strlcpy(gotd->unix_socket_path, $2,
200 sizeof(gotd->unix_socket_path)) >=
201 sizeof(gotd->unix_socket_path)) {
202 yyerror("%s: unix socket path too long",
203 __func__);
204 free($2);
205 YYERROR;
208 free($2);
210 | UNIX_GROUP STRING {
211 if (strlcpy(gotd->unix_group_name, $2,
212 sizeof(gotd->unix_group_name)) >=
213 sizeof(gotd->unix_group_name)) {
214 yyerror("%s: unix group name too long",
215 __func__);
216 free($2);
217 YYERROR;
219 free($2);
221 | USER STRING {
222 if (strlcpy(gotd->user_name, $2,
223 sizeof(gotd->user_name)) >=
224 sizeof(gotd->user_name)) {
225 yyerror("%s: user name too long", __func__);
226 free($2);
227 YYERROR;
229 free($2);
231 | connection
234 connection : CONNECTION '{' optnl conflags_l '}'
235 | CONNECTION conflags
237 conflags_l : conflags optnl conflags_l
238 | conflags optnl
241 conflags : REQUEST TIMEOUT timeout {
242 if ($3.tv_sec <= 0) {
243 yyerror("invalid timeout: %lld", $3.tv_sec);
244 YYERROR;
246 memcpy(&gotd->request_timeout, &$3,
247 sizeof(gotd->request_timeout));
249 | LIMIT USER STRING NUMBER {
250 if (gotd_proc_id == PROC_LISTEN &&
251 conf_limit_user_connections($3, $4) == -1) {
252 free($3);
253 YYERROR;
255 free($3);
259 repository : REPOSITORY STRING {
260 struct gotd_repo *repo;
262 TAILQ_FOREACH(repo, &gotd->repos, entry) {
263 if (strcmp(repo->name, $2) == 0) {
264 yyerror("duplicate repository '%s'", $2);
265 free($2);
266 YYERROR;
270 if (gotd_proc_id == PROC_GOTD ||
271 gotd_proc_id == PROC_AUTH) {
272 new_repo = conf_new_repo($2);
274 free($2);
275 } '{' optnl repoopts2 '}' {
279 repoopts1 : PATH STRING {
280 if (gotd_proc_id == PROC_GOTD ||
281 gotd_proc_id == PROC_AUTH) {
282 if (!got_path_is_absolute($2)) {
283 yyerror("%s: path %s is not absolute",
284 __func__, $2);
285 free($2);
286 YYERROR;
288 if (strlcpy(new_repo->path, $2,
289 sizeof(new_repo->path)) >=
290 sizeof(new_repo->path)) {
291 yyerror("%s: path truncated", __func__);
292 free($2);
293 YYERROR;
296 free($2);
298 | PERMIT RO STRING {
299 if (gotd_proc_id == PROC_AUTH) {
300 conf_new_access_rule(new_repo,
301 GOTD_ACCESS_PERMITTED, GOTD_AUTH_READ, $3);
304 | PERMIT RW STRING {
305 if (gotd_proc_id == PROC_AUTH) {
306 conf_new_access_rule(new_repo,
307 GOTD_ACCESS_PERMITTED,
308 GOTD_AUTH_READ | GOTD_AUTH_WRITE, $3);
311 | DENY STRING {
312 if (gotd_proc_id == PROC_AUTH) {
313 conf_new_access_rule(new_repo,
314 GOTD_ACCESS_DENIED, 0, $2);
319 repoopts2 : repoopts2 repoopts1 nl
320 | repoopts1 optnl
323 nl : '\n' optnl
326 optnl : '\n' optnl /* zero or more newlines */
327 | /* empty */
330 %%
332 struct keywords {
333 const char *k_name;
334 int k_val;
335 };
337 int
338 yyerror(const char *fmt, ...)
340 va_list ap;
341 char *msg;
343 file->errors++;
344 va_start(ap, fmt);
345 if (vasprintf(&msg, fmt, ap) == -1)
346 fatalx("yyerror vasprintf");
347 va_end(ap);
348 logit(LOG_CRIT, "%s:%d: %s", file->name, yylval.lineno, msg);
349 free(msg);
350 return (0);
353 int
354 kw_cmp(const void *k, const void *e)
356 return (strcmp(k, ((const struct keywords *)e)->k_name));
359 int
360 lookup(char *s)
362 /* This has to be sorted always. */
363 static const struct keywords keywords[] = {
364 { "connection", CONNECTION },
365 { "deny", DENY },
366 { "limit", LIMIT },
367 { "on", ON },
368 { "path", PATH },
369 { "permit", PERMIT },
370 { "repository", REPOSITORY },
371 { "request", REQUEST },
372 { "ro", RO },
373 { "rw", RW },
374 { "timeout", TIMEOUT },
375 { "unix_group", UNIX_GROUP },
376 { "unix_socket", UNIX_SOCKET },
377 { "user", USER },
378 };
379 const struct keywords *p;
381 p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
382 sizeof(keywords[0]), kw_cmp);
384 if (p)
385 return (p->k_val);
386 else
387 return (STRING);
390 #define MAXPUSHBACK 128
392 unsigned char *parsebuf;
393 int parseindex;
394 unsigned char pushback_buffer[MAXPUSHBACK];
395 int pushback_index = 0;
397 int
398 lgetc(int quotec)
400 int c, next;
402 if (parsebuf) {
403 /* Read character from the parsebuffer instead of input. */
404 if (parseindex >= 0) {
405 c = parsebuf[parseindex++];
406 if (c != '\0')
407 return (c);
408 parsebuf = NULL;
409 } else
410 parseindex++;
413 if (pushback_index)
414 return (pushback_buffer[--pushback_index]);
416 if (quotec) {
417 c = getc(file->stream);
418 if (c == EOF)
419 yyerror("reached end of file while parsing "
420 "quoted string");
421 return (c);
424 c = getc(file->stream);
425 while (c == '\\') {
426 next = getc(file->stream);
427 if (next != '\n') {
428 c = next;
429 break;
431 yylval.lineno = file->lineno;
432 file->lineno++;
433 c = getc(file->stream);
436 return (c);
439 int
440 lungetc(int c)
442 if (c == EOF)
443 return (EOF);
444 if (parsebuf) {
445 parseindex--;
446 if (parseindex >= 0)
447 return (c);
449 if (pushback_index < MAXPUSHBACK-1)
450 return (pushback_buffer[pushback_index++] = c);
451 else
452 return (EOF);
455 int
456 findeol(void)
458 int c;
460 parsebuf = NULL;
462 /* Skip to either EOF or the first real EOL. */
463 while (1) {
464 if (pushback_index)
465 c = pushback_buffer[--pushback_index];
466 else
467 c = lgetc(0);
468 if (c == '\n') {
469 file->lineno++;
470 break;
472 if (c == EOF)
473 break;
475 return (ERROR);
478 int
479 yylex(void)
481 unsigned char buf[8096];
482 unsigned char *p, *val;
483 int quotec, next, c;
484 int token;
486 top:
487 p = buf;
488 c = lgetc(0);
489 while (c == ' ' || c == '\t')
490 c = lgetc(0); /* nothing */
492 yylval.lineno = file->lineno;
493 if (c == '#') {
494 c = lgetc(0);
495 while (c != '\n' && c != EOF)
496 c = lgetc(0); /* nothing */
498 if (c == '$' && parsebuf == NULL) {
499 while (1) {
500 c = lgetc(0);
501 if (c == EOF)
502 return (0);
504 if (p + 1 >= buf + sizeof(buf) - 1) {
505 yyerror("string too long");
506 return (findeol());
508 if (isalnum(c) || c == '_') {
509 *p++ = c;
510 continue;
512 *p = '\0';
513 lungetc(c);
514 break;
516 val = symget(buf);
517 if (val == NULL) {
518 yyerror("macro '%s' not defined", buf);
519 return (findeol());
521 parsebuf = val;
522 parseindex = 0;
523 goto top;
526 switch (c) {
527 case '\'':
528 case '"':
529 quotec = c;
530 while (1) {
531 c = lgetc(quotec);
532 if (c == EOF)
533 return (0);
534 if (c == '\n') {
535 file->lineno++;
536 continue;
537 } else if (c == '\\') {
538 next = lgetc(quotec);
539 if (next == EOF)
540 return (0);
541 if (next == quotec || c == ' ' || c == '\t')
542 c = next;
543 else if (next == '\n') {
544 file->lineno++;
545 continue;
546 } else
547 lungetc(next);
548 } else if (c == quotec) {
549 *p = '\0';
550 break;
551 } else if (c == '\0') {
552 yyerror("syntax error");
553 return (findeol());
555 if (p + 1 >= buf + sizeof(buf) - 1) {
556 yyerror("string too long");
557 return (findeol());
559 *p++ = c;
561 yylval.v.string = strdup(buf);
562 if (yylval.v.string == NULL)
563 err(1, "yylex: strdup");
564 return (STRING);
567 #define allowed_to_end_number(x) \
568 (isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
570 if (c == '-' || isdigit(c)) {
571 do {
572 *p++ = c;
573 if ((unsigned)(p-buf) >= sizeof(buf)) {
574 yyerror("string too long");
575 return (findeol());
577 c = lgetc(0);
578 } while (c != EOF && isdigit(c));
579 lungetc(c);
580 if (p == buf + 1 && buf[0] == '-')
581 goto nodigits;
582 if (c == EOF || allowed_to_end_number(c)) {
583 const char *errstr = NULL;
585 *p = '\0';
586 yylval.v.number = strtonum(buf, LLONG_MIN,
587 LLONG_MAX, &errstr);
588 if (errstr) {
589 yyerror("\"%s\" invalid number: %s",
590 buf, errstr);
591 return (findeol());
593 return (NUMBER);
594 } else {
595 nodigits:
596 while (p > buf + 1)
597 lungetc(*--p);
598 c = *--p;
599 if (c == '-')
600 return (c);
604 #define allowed_in_string(x) \
605 (isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
606 x != '{' && x != '}' && \
607 x != '!' && x != '=' && x != '#' && \
608 x != ','))
610 if (isalnum(c) || c == ':' || c == '_') {
611 do {
612 *p++ = c;
613 if ((unsigned)(p-buf) >= sizeof(buf)) {
614 yyerror("string too long");
615 return (findeol());
617 c = lgetc(0);
618 } while (c != EOF && (allowed_in_string(c)));
619 lungetc(c);
620 *p = '\0';
621 token = lookup(buf);
622 if (token == STRING) {
623 yylval.v.string = strdup(buf);
624 if (yylval.v.string == NULL)
625 err(1, "yylex: strdup");
627 return (token);
629 if (c == '\n') {
630 yylval.lineno = file->lineno;
631 file->lineno++;
633 if (c == EOF)
634 return (0);
635 return (c);
638 int
639 check_file_secrecy(int fd, const char *fname)
641 struct stat st;
643 if (fstat(fd, &st)) {
644 log_warn("cannot stat %s", fname);
645 return (-1);
647 if (st.st_uid != 0 && st.st_uid != getuid()) {
648 log_warnx("%s: owner not root or current user", fname);
649 return (-1);
651 if (st.st_mode & (S_IWGRP | S_IXGRP | S_IRWXO)) {
652 log_warnx("%s: group writable or world read/writable", fname);
653 return (-1);
655 return (0);
658 struct file *
659 newfile(const char *name, int secret)
661 struct file *nfile;
663 nfile = calloc(1, sizeof(struct file));
664 if (nfile == NULL) {
665 log_warn("calloc");
666 return (NULL);
668 nfile->name = strdup(name);
669 if (nfile->name == NULL) {
670 log_warn("strdup");
671 free(nfile);
672 return (NULL);
674 nfile->stream = fopen(nfile->name, "r");
675 if (nfile->stream == NULL) {
676 /* no warning, we don't require a conf file */
677 free(nfile->name);
678 free(nfile);
679 return (NULL);
680 } else if (secret &&
681 check_file_secrecy(fileno(nfile->stream), nfile->name)) {
682 fclose(nfile->stream);
683 free(nfile->name);
684 free(nfile);
685 return (NULL);
687 nfile->lineno = 1;
688 return (nfile);
691 static void
692 closefile(struct file *xfile)
694 fclose(xfile->stream);
695 free(xfile->name);
696 free(xfile);
699 int
700 parse_config(const char *filename, enum gotd_procid proc_id,
701 struct gotd *env)
703 struct sym *sym, *next;
704 struct gotd_repo *repo;
706 memset(env, 0, sizeof(*env));
708 gotd = env;
709 gotd_proc_id = proc_id;
710 TAILQ_INIT(&gotd->repos);
712 /* Apply default values. */
713 if (strlcpy(gotd->unix_socket_path, GOTD_UNIX_SOCKET,
714 sizeof(gotd->unix_socket_path)) >= sizeof(gotd->unix_socket_path)) {
715 fprintf(stderr, "%s: unix socket path too long", __func__);
716 return -1;
718 if (strlcpy(gotd->unix_group_name, GOTD_UNIX_GROUP,
719 sizeof(gotd->unix_group_name)) >= sizeof(gotd->unix_group_name)) {
720 fprintf(stderr, "%s: unix group name too long", __func__);
721 return -1;
723 if (strlcpy(gotd->user_name, GOTD_USER,
724 sizeof(gotd->user_name)) >= sizeof(gotd->user_name)) {
725 fprintf(stderr, "%s: user name too long", __func__);
726 return -1;
729 gotd->request_timeout.tv_sec = GOTD_DEFAULT_REQUEST_TIMEOUT;
730 gotd->request_timeout.tv_usec = 0;
732 file = newfile(filename, 0);
733 if (file == NULL) {
734 /* just return, as we don't require a conf file */
735 return (0);
738 yyparse();
739 errors = file->errors;
740 closefile(file);
742 /* Free macros and check which have not been used. */
743 TAILQ_FOREACH_SAFE(sym, &symhead, entry, next) {
744 if ((gotd->verbosity > 1) && !sym->used)
745 fprintf(stderr, "warning: macro '%s' not used\n",
746 sym->nam);
747 if (!sym->persist) {
748 free(sym->nam);
749 free(sym->val);
750 TAILQ_REMOVE(&symhead, sym, entry);
751 free(sym);
755 if (errors)
756 return (-1);
758 TAILQ_FOREACH(repo, &gotd->repos, entry) {
759 if (repo->path[0] == '\0') {
760 log_warnx("repository \"%s\": no path provided in "
761 "configuration file", repo->name);
762 return (-1);
766 return (0);
769 static int
770 uid_connection_limit_cmp(const void *pa, const void *pb)
772 const struct gotd_uid_connection_limit *a = pa, *b = pb;
774 if (a->uid < b->uid)
775 return -1;
776 else if (a->uid > b->uid);
777 return 1;
779 return 0;
782 static int
783 conf_limit_user_connections(const char *user, int maximum)
785 uid_t uid;
786 struct gotd_uid_connection_limit *limit;
787 size_t nlimits;
789 if (maximum < 1) {
790 yyerror("max connections cannot be smaller 1");
791 return -1;
793 if (maximum > GOTD_MAXCLIENTS) {
794 yyerror("max connections must be <= %d", GOTD_MAXCLIENTS);
795 return -1;
798 if (gotd_auth_parseuid(user, &uid) == -1) {
799 yyerror("%s: no such user", user);
800 return -1;
803 limit = gotd_find_uid_connection_limit(gotd->connection_limits,
804 gotd->nconnection_limits, uid);
805 if (limit) {
806 limit->max_connections = maximum;
807 return 0;
810 limit = gotd->connection_limits;
811 nlimits = gotd->nconnection_limits + 1;
812 limit = reallocarray(limit, nlimits, sizeof(*limit));
813 if (limit == NULL)
814 fatal("reallocarray");
816 limit[nlimits - 1].uid = uid;
817 limit[nlimits - 1].max_connections = maximum;
819 gotd->connection_limits = limit;
820 gotd->nconnection_limits = nlimits;
821 qsort(gotd->connection_limits, gotd->nconnection_limits,
822 sizeof(gotd->connection_limits[0]), uid_connection_limit_cmp);
824 return 0;
827 static struct gotd_repo *
828 conf_new_repo(const char *name)
830 struct gotd_repo *repo;
832 if (name[0] == '\0') {
833 fatalx("syntax error: empty repository name found in %s",
834 file->name);
837 if (strchr(name, '\n') != NULL)
838 fatalx("repository names must not contain linefeeds: %s", name);
840 repo = calloc(1, sizeof(*repo));
841 if (repo == NULL)
842 fatalx("%s: calloc", __func__);
844 STAILQ_INIT(&repo->rules);
846 if (strlcpy(repo->name, name, sizeof(repo->name)) >=
847 sizeof(repo->name))
848 fatalx("%s: strlcpy", __func__);
850 TAILQ_INSERT_TAIL(&gotd->repos, repo, entry);
851 gotd->nrepos++;
853 return repo;
854 };
856 static void
857 conf_new_access_rule(struct gotd_repo *repo, enum gotd_access access,
858 int authorization, char *identifier)
860 struct gotd_access_rule *rule;
862 rule = calloc(1, sizeof(*rule));
863 if (rule == NULL)
864 fatal("calloc");
866 rule->access = access;
867 rule->authorization = authorization;
868 rule->identifier = identifier;
870 STAILQ_INSERT_TAIL(&repo->rules, rule, entry);
873 int
874 symset(const char *nam, const char *val, int persist)
876 struct sym *sym;
878 TAILQ_FOREACH(sym, &symhead, entry) {
879 if (strcmp(nam, sym->nam) == 0)
880 break;
883 if (sym != NULL) {
884 if (sym->persist == 1)
885 return (0);
886 else {
887 free(sym->nam);
888 free(sym->val);
889 TAILQ_REMOVE(&symhead, sym, entry);
890 free(sym);
893 sym = calloc(1, sizeof(*sym));
894 if (sym == NULL)
895 return (-1);
897 sym->nam = strdup(nam);
898 if (sym->nam == NULL) {
899 free(sym);
900 return (-1);
902 sym->val = strdup(val);
903 if (sym->val == NULL) {
904 free(sym->nam);
905 free(sym);
906 return (-1);
908 sym->used = 0;
909 sym->persist = persist;
910 TAILQ_INSERT_TAIL(&symhead, sym, entry);
911 return (0);
914 char *
915 symget(const char *nam)
917 struct sym *sym;
919 TAILQ_FOREACH(sym, &symhead, entry) {
920 if (strcmp(nam, sym->nam) == 0) {
921 sym->used = 1;
922 return (sym->val);
925 return (NULL);