Lines Matching +full:path +full:- +full:map

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
68 static void parse_map_yyin(struct node *parent, const char *map,
102 s1last = s1[strlen(s1) - 1]; in concat()
109 * it - skip the latter; otherwise concatenating "/" in concat()
128 create_directory(const char *path) in create_directory() argument
133 assert(path[0] == '/'); in create_directory()
138 copy = tofree = checked_strdup(path + 1); in create_directory()
168 n->n_key = checked_strdup("/"); in node_new_root()
169 n->n_options = checked_strdup(""); in node_new_root()
171 TAILQ_INIT(&n->n_children); in node_new_root()
186 TAILQ_INIT(&n->n_children); in node_new()
189 n->n_key = key; in node_new()
191 n->n_options = options; in node_new()
193 n->n_options = strdup(""); in node_new()
194 n->n_location = location; in node_new()
196 n->n_config_file = config_file; in node_new()
198 n->n_config_line = config_line; in node_new()
201 n->n_parent = parent; in node_new()
202 TAILQ_INSERT_TAIL(&parent->n_children, n, n_next); in node_new()
208 node_new_map(struct node *parent, char *key, char *options, char *map, in node_new_map() argument
217 TAILQ_INIT(&n->n_children); in node_new_map()
220 n->n_key = key; in node_new_map()
222 n->n_options = options; in node_new_map()
224 n->n_options = strdup(""); in node_new_map()
225 n->n_map = map; in node_new_map()
227 n->n_config_file = config_file; in node_new_map()
229 n->n_config_line = config_line; in node_new_map()
232 n->n_parent = parent; in node_new_map()
233 TAILQ_INSERT_TAIL(&parent->n_children, n, n_next); in node_new_map()
245 parent = o->n_parent; in node_duplicate()
247 n = node_new(parent, o->n_key, o->n_options, o->n_location, in node_duplicate()
248 o->n_config_file, o->n_config_line); in node_duplicate()
250 TAILQ_FOREACH(child, &o->n_children, n_next) in node_duplicate()
263 TAILQ_FOREACH_SAFE(child, &n->n_children, n_next, tmp) in node_delete()
266 if (n->n_parent != NULL) in node_delete()
267 TAILQ_REMOVE(&n->n_parent->n_children, n, n_next); in node_delete()
280 TAILQ_REMOVE(&n->n_parent->n_children, n, n_next); in node_move_after()
281 n->n_parent = previous->n_parent; in node_move_after()
282 TAILQ_INSERT_AFTER(&previous->n_parent->n_children, previous, n, n_next); in node_move_after()
291 TAILQ_FOREACH_SAFE(n, &root->n_children, n_next, tmp) { in node_expand_includes()
292 if (n->n_key[0] != '+') in node_expand_includes()
304 yyin = auto_popen(AUTO_INCLUDE_PATH, n->n_key + 1, NULL); in node_expand_includes()
309 parse_master_yyin(tmproot, n->n_key); in node_expand_includes()
311 parse_map_yyin(tmproot, n->n_key, NULL); in node_expand_includes()
317 n->n_key); in node_expand_includes()
325 &tmproot->n_children, nodehead, n_next, tmp2) { in node_expand_includes()
390 * key from map entries themselves. Keep in mind that maps
394 * Variant with NULL key is for "automount -LL".
401 if (n->n_location != NULL) { in node_expand_ampersand()
403 if (n->n_parent != NULL && in node_expand_ampersand()
404 strcmp(n->n_parent->n_key, "*") != 0) { in node_expand_ampersand()
405 n->n_location = expand_ampersand(n->n_location, in node_expand_ampersand()
406 n->n_parent->n_key); in node_expand_ampersand()
409 n->n_location = expand_ampersand(n->n_location, key); in node_expand_ampersand()
413 TAILQ_FOREACH(child, &n->n_children, n_next) in node_expand_ampersand()
427 if (strcmp(n->n_key, "*") == 0) { in node_expand_wildcard()
429 expanded->n_key = checked_strdup(key); in node_expand_wildcard()
433 TAILQ_FOREACH(child, &n->n_children, n_next) in node_expand_wildcard()
443 if (n->n_location != NULL) { in node_expand_defined()
444 n->n_location = defined_expand(n->n_location); in node_expand_defined()
445 if (n->n_location == NULL) { in node_expand_defined()
452 TAILQ_FOREACH(child, &n->n_children, n_next) { in node_expand_defined()
465 if (n->n_parent != NULL && n->n_parent->n_parent == NULL && in node_is_direct_key()
466 strcmp(n->n_key, "/-") == 0) { in node_is_direct_key()
478 assert(n->n_parent != NULL); in node_is_direct_map()
479 if (n->n_parent->n_parent == NULL) in node_is_direct_map()
481 n = n->n_parent; in node_is_direct_map()
492 TAILQ_FOREACH(child, &n->n_children, n_next) { in node_has_wildcards()
493 if (strcmp(child->n_key, "*") == 0) in node_has_wildcards()
505 TAILQ_FOREACH_SAFE(child, &n->n_children, n_next, tmp) { in node_expand_maps()
515 * This is the first-level map node; the one that contains in node_expand_maps()
516 * the key and subnodes with mountpoints and actual map names. in node_expand_maps()
518 if (child->n_map == NULL) in node_expand_maps()
522 log_debugx("map \"%s\" is an indirect map, parsing", in node_expand_maps()
523 child->n_map); in node_expand_maps()
525 log_debugx("map \"%s\" is a direct map, parsing", in node_expand_maps()
526 child->n_map); in node_expand_maps()
528 parse_map(child, child->n_map, NULL, NULL); in node_expand_maps()
549 char *path; in node_path_x() local
551 if (n->n_parent == NULL) in node_path_x()
555 * Return "/-" for direct maps only if we were asked for path in node_path_x()
556 * to the "/-" node itself, not to any of its subnodes. in node_path_x()
561 assert(n->n_key[0] != '\0'); in node_path_x()
562 path = concat(n->n_key, '/', x); in node_path_x()
565 return (node_path_x(n->n_parent, path)); in node_path_x()
569 * Return full path for node, consisting of concatenated
575 char *path; in node_path() local
578 path = node_path_x(n, checked_strdup("")); in node_path()
581 * Strip trailing slash, unless the whole path is "/". in node_path()
583 len = strlen(path); in node_path()
584 if (len > 1 && path[len - 1] == '/') in node_path()
585 path[len - 1] = '\0'; in node_path()
587 return (path); in node_path()
598 options = concat(x, ',', n->n_options); in node_options_x()
601 return (node_options_x(n->n_parent, options)); in node_options_x()
621 char *path, *options, *tmp; in node_print_indent() local
623 path = node_path(n); in node_print_indent()
631 * "key location", map entries are shown in a single line; in node_print_indent()
635 first_child = TAILQ_FIRST(&n->n_children); in node_print_indent()
637 strcmp(path, node_path(first_child)) != 0) { in node_print_indent()
638 assert(n->n_location == NULL || n->n_map == NULL); in node_print_indent()
639 printf("%*.s%-*s %s%-*s %-*s # %s map %s at %s:%d\n", in node_print_indent()
641 25 - indent, in node_print_indent()
642 path, in node_print_indent()
643 options[0] != '\0' ? "-" : " ", in node_print_indent()
647 n->n_location != NULL ? n->n_location : n->n_map != NULL ? n->n_map : "", in node_print_indent()
650 n->n_config_file, n->n_config_line); in node_print_indent()
653 free(path); in node_print_indent()
656 TAILQ_FOREACH(child, &n->n_children, n_next) in node_print_indent()
663 * others - usually those are the options passed by command line.
670 TAILQ_FOREACH(child, &n->n_children, n_next) in node_print()
675 node_find_x(struct node *node, const char *path) in node_find_x() argument
681 //log_debugx("looking up %s in %s", path, node_path(node)); in node_find_x()
686 if (strncmp(tmp, path, tmplen) != 0) { in node_find_x()
690 if (path[tmplen] != '/' && path[tmplen] != '\0') { in node_find_x()
692 * If we have two map entries like 'foo' and 'foobar', make in node_find_x()
701 TAILQ_FOREACH(child, &node->n_children, n_next) { in node_find_x()
702 found = node_find_x(child, path); in node_find_x()
707 if (node->n_parent == NULL || node_is_direct_key(node)) in node_find_x()
714 node_find(struct node *root, const char *path) in node_find() argument
718 assert(root->n_parent == NULL); in node_find()
720 node = node_find_x(root, path); in node_find()
728 * Canonical form of a map entry looks like this:
730 * key [-options] [ [/mountpoint] [-options2] location ... ]
733 * lack the 'key' field and are always single-line; the key field
736 * We parse it in such a way that a map always has two levels - first
740 parse_map_yyin(struct node *parent, const char *map, const char *executable_key) in parse_map_yyin() argument
756 * In case of executable map, the key is always in parse_map_yyin()
757 * non-NULL, even if the map is empty. So, make sure in parse_map_yyin()
763 map, lineno); in parse_map_yyin()
778 node_new(parent, key, NULL, NULL, map, lineno); in parse_map_yyin()
783 } else if (yytext[0] == '-') { in parse_map_yyin()
786 map, lineno); in parse_map_yyin()
789 * +1 to skip leading "-". in parse_map_yyin()
796 * We cannot properly handle a situation where the map key in parse_map_yyin()
805 log_warnx("nonsensical map key \"/\" at %s, line %d; " in parse_map_yyin()
806 "ignoring map entry ", map, lineno); in parse_map_yyin()
819 //log_debugx("adding map node, %s", key); in parse_map_yyin()
820 node = node_new(parent, key, options, NULL, map, lineno); in parse_map_yyin()
827 "in %s, line %d", map, lineno); in parse_map_yyin()
831 "in %s, line %d", map, lineno); in parse_map_yyin()
837 if (yytext[0] == '-') { in parse_map_yyin()
840 "in %s, line %d", map, lineno); in parse_map_yyin()
844 "in %s, line %d", map, lineno); in parse_map_yyin()
852 "in %s, line %d", map, lineno); in parse_map_yyin()
863 "line %d", map, lineno); in parse_map_yyin()
875 log_debugx("adding map node, %s %s %s", in parse_map_yyin()
879 map, lineno); in parse_map_yyin()
887 "in %s, line %d", map, lineno); in parse_map_yyin()
896 * Parse output of a special map called without argument. It is a list
901 parse_map_keys_yyin(struct node *parent, const char *map) in parse_map_keys_yyin() argument
925 * "-1" to strip the trailing newline. in parse_map_keys_yyin()
927 key = strndup(line, linelen - 1); in parse_map_keys_yyin()
930 node_new(parent, key, NULL, NULL, map, lineno); in parse_map_keys_yyin()
937 file_is_executable(const char *path) in file_is_executable() argument
942 error = stat(path, &sb); in file_is_executable()
944 log_err(1, "cannot stat %s", path); in file_is_executable()
952 * Parse a special map, e.g. "-hosts".
955 parse_special_map(struct node *parent, const char *map, const char *key) in parse_special_map() argument
957 char *path; in parse_special_map() local
960 assert(map[0] == '-'); in parse_special_map()
963 * +1 to skip leading "-" in map name. in parse_special_map()
965 ret = asprintf(&path, "%s/special_%s", AUTO_SPECIAL_PREFIX, map + 1); in parse_special_map()
969 yyin = auto_popen(path, key, NULL); in parse_special_map()
973 parse_map_keys_yyin(parent, map); in parse_special_map()
975 parse_map_yyin(parent, map, key); in parse_special_map()
981 log_errx(1, "failed to handle special map \"%s\"", map); in parse_special_map()
986 free(path); in parse_special_map()
990 * Retrieve and parse map from directory services, e.g. LDAP.
992 * the include script outputs the whole map to standard output
994 * entry, without the key), and it takes the map name as an
998 parse_included_map(struct node *parent, const char *map) in parse_included_map() argument
1002 assert(map[0] != '-'); in parse_included_map()
1003 assert(map[0] != '/'); in parse_included_map()
1011 yyin = auto_popen(AUTO_INCLUDE_PATH, map, NULL); in parse_included_map()
1014 parse_map_yyin(parent, map, NULL); in parse_included_map()
1019 log_errx(1, "failed to handle remote map \"%s\"", map); in parse_included_map()
1026 parse_map(struct node *parent, const char *map, const char *key, in parse_map() argument
1029 char *path = NULL; in parse_map() local
1033 assert(map != NULL); in parse_map()
1034 assert(map[0] != '\0'); in parse_map()
1036 log_debugx("parsing map \"%s\"", map); in parse_map()
1041 if (map[0] == '-') { in parse_map()
1044 return (parse_special_map(parent, map, key)); in parse_map()
1047 if (map[0] == '/') { in parse_map()
1048 path = checked_strdup(map); in parse_map()
1050 ret = asprintf(&path, "%s/%s", AUTO_MAP_PREFIX, map); in parse_map()
1053 log_debugx("map \"%s\" maps to \"%s\"", map, path); in parse_map()
1056 * See if the file exists. If not, try to obtain the map in parse_map()
1059 error = access(path, F_OK); in parse_map()
1061 log_debugx("map file \"%s\" does not exist; falling " in parse_map()
1062 "back to directory services", path); in parse_map()
1063 return (parse_included_map(parent, map)); in parse_map()
1067 executable = file_is_executable(path); in parse_map()
1070 log_debugx("map \"%s\" is executable", map); in parse_map()
1076 yyin = auto_popen(path, key, NULL); in parse_map()
1078 yyin = auto_popen(path, NULL); in parse_map()
1082 yyin = fopen(path, "r"); in parse_map()
1084 log_err(1, "unable to open \"%s\"", path); in parse_map()
1087 free(path); in parse_map()
1088 path = NULL; in parse_map()
1090 parse_map_yyin(parent, map, executable ? key : NULL); in parse_map()
1096 log_errx(1, "failed to handle executable map \"%s\"", in parse_map()
1097 map); in parse_map()
1104 log_debugx("done parsing map \"%s\"", map); in parse_map()
1113 char *mountpoint = NULL, *map = NULL, *options = NULL; in parse_master_yyin() local
1125 //log_debugx("adding map for %s", mountpoint); in parse_master_yyin()
1126 node_new_map(root, mountpoint, options, map, in parse_master_yyin()
1132 mountpoint = map = options = NULL; in parse_master_yyin()
1138 } else if (map == NULL) { in parse_master_yyin()
1139 map = checked_strdup(yytext); in parse_master_yyin()
1142 * +1 to skip leading "-". in parse_master_yyin()
1212 f = auto_popen("rpc.umntall", "-k", NULL); in rpc_umntall()