2 * Copyright (c) 2008-2011 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
33 #include <sys/param.h>
35 #include <arpa/inet.h>
36 #include <dispatch/dispatch.h>
37 #include "si_module.h"
39 #define _PATH_SI_CONF "/etc/sysinfo.conf"
41 #define SEARCH_FLAG_CACHE_ENABLED 0x00000001
42 #define SEARCH_MODULE_FLAG_DISABLED 0x00000001
47 uint32_t *module_flags
;
54 search_list_t search_list
[CATEGORY_COUNT
];
56 } search_si_private_t
;
58 extern void si_cache_add_item(si_mod_t
*si
, si_mod_t
*src
, si_item_t
*item
);
59 extern void si_cache_add_list(si_mod_t
*si
, si_mod_t
*src
, si_list_t
*list
);
61 extern char **_fsi_tokenize(char *data
, const char *sep
, int trailing_empty
, int *ntokens
);
62 extern char *_fsi_get_line(FILE *fp
);
64 static void si_module_config_parse_line(search_si_private_t
*pp
, char *line
);
65 static void si_module_config_modules_for_category(search_si_private_t
*pp
, int cat
, int ntokens
, const char * const *tokens
);
68 search_get_module(search_si_private_t
*pp
, int cat
, int *n
)
72 if ((pp
== NULL
) || (n
== NULL
)) return NULL
;
77 /* Use custom search list if available */
78 if (pp
->search_list
[cat
].count
> 0 && x
< pp
->search_list
[cat
].count
)
80 return pp
->search_list
[cat
].module[x
];
83 /* Otherwise use the default search list */
84 while (x
< pp
->search_list
[CATEGORY_DEFAULT
].count
)
86 if (pp
->search_list
[CATEGORY_DEFAULT
].module_flags
[x
] & SEARCH_MODULE_FLAG_DISABLED
)
93 return pp
->search_list
[CATEGORY_DEFAULT
].module[x
];
100 __private_extern__
void
101 search_set_flags(si_mod_t
*si
, const char *name
, uint32_t flag
)
103 search_si_private_t
*pp
;
106 if (si
== NULL
) return;
107 if (si
->private == NULL
) return;
109 pp
= (search_si_private_t
*)si
->private;
111 for (i
= 0; i
< pp
->search_list
[CATEGORY_DEFAULT
].count
; i
++)
113 si_mod_t
*mod
= pp
->search_list
[CATEGORY_DEFAULT
].module[i
];
114 if ((mod
== NULL
) || (mod
->name
== NULL
)) continue;
116 if (string_equal(name
, mod
->name
))
118 pp
->search_list
[CATEGORY_DEFAULT
].module_flags
[i
] = flag
;
125 search_cat_cache(search_si_private_t
*pp
, int cat
)
127 if (pp
== NULL
) return NULL
;
128 if (cat
< 0 || cat
> CATEGORY_COUNT
) return NULL
;
130 if (pp
->search_list
[cat
].count
== 0)
132 cat
= CATEGORY_DEFAULT
;
135 if ((pp
->search_list
[cat
].flags
& SEARCH_FLAG_CACHE_ENABLED
) != 0)
144 search_close(si_mod_t
*si
)
147 search_si_private_t
*pp
;
149 if (si
== NULL
) return;
150 if (si
->private == NULL
) return;
152 pp
= (search_si_private_t
*)si
->private;
154 for (i
= 0; i
< CATEGORY_COUNT
; i
++)
156 if (pp
->search_list
[i
].module != NULL
)
158 free(pp
->search_list
[i
].module);
159 pp
->search_list
[i
].module = NULL
;
160 pp
->search_list
[i
].count
= 0;
161 pp
->search_list
[i
].flags
= 0;
169 search_item_byname(si_mod_t
*si
, const char *name
, int cat
, si_item_t
*(*call
)(si_mod_t
*, const char *))
172 search_si_private_t
*pp
;
176 if (si
== NULL
) return NULL
;
177 if (call
== NULL
) return NULL
;
179 pp
= (search_si_private_t
*)si
->private;
180 if (pp
== NULL
) return NULL
;
184 while (NULL
!= (src
= search_get_module(pp
, cat
, &i
)))
186 item
= call(src
, name
);
189 si_cache_add_item(search_cat_cache(pp
, cat
), src
, item
);
198 search_item_bynumber(si_mod_t
*si
, uint32_t number
, int cat
, si_item_t
*(*call
)(si_mod_t
*, uint32_t))
201 search_si_private_t
*pp
;
205 if (si
== NULL
) return NULL
;
206 if (call
== NULL
) return NULL
;
208 pp
= (search_si_private_t
*)si
->private;
209 if (pp
== NULL
) return NULL
;
213 while (NULL
!= (src
= search_get_module(pp
, cat
, &i
)))
215 item
= call(src
, number
);
218 si_cache_add_item(search_cat_cache(pp
, cat
), src
, item
);
227 search_item_byuuid(si_mod_t
*si
, uuid_t uuid
, int cat
, si_item_t
*(*call
)(si_mod_t
*, uuid_t
))
230 search_si_private_t
*pp
;
234 if (si
== NULL
) return NULL
;
235 if (call
== NULL
) return NULL
;
237 pp
= (search_si_private_t
*)si
->private;
238 if (pp
== NULL
) return NULL
;
242 while (NULL
!= (src
= search_get_module(pp
, cat
, &i
)))
244 item
= call(src
, uuid
);
248 * N.B. item not added to cache, since the data does not
249 * contain the uuid that was used to find it.
258 search_list(si_mod_t
*si
, int cat
, si_list_t
*(*call
)(si_mod_t
*))
261 search_si_private_t
*pp
;
262 si_list_t
*list
, *all
;
263 si_mod_t
*cache
, *src
;
265 if (si
== NULL
) return NULL
;
266 if (call
== NULL
) return NULL
;
268 pp
= (search_si_private_t
*)si
->private;
269 if (pp
== NULL
) return NULL
;
271 cache
= search_cat_cache(pp
, cat
);
275 if (list
!= NULL
) return list
;
283 while (NULL
!= (src
= search_get_module(pp
, cat
, &i
)))
285 if (src
== pp
->cache
) continue;
294 all
= si_list_concat(all
, list
);
295 si_list_release(list
);
298 if ((all
!= NULL
) && (null_res
== 0)) si_cache_add_list(cache
, si
, all
);
303 search_user_byname(si_mod_t
*si
, const char *name
)
305 return search_item_byname(si
, name
, CATEGORY_USER
, si_user_byname
);
309 search_user_byuid(si_mod_t
*si
, uid_t uid
)
311 return search_item_bynumber(si
, (uint32_t)uid
, CATEGORY_USER
, si_user_byuid
);
315 search_user_byuuid(si_mod_t
*si
, uuid_t uuid
)
317 return search_item_byuuid(si
, uuid
, CATEGORY_USER
, si_user_byuuid
);
321 search_user_all(si_mod_t
*si
)
323 return search_list(si
, CATEGORY_USER
, si_user_all
);
327 search_group_byname(si_mod_t
*si
, const char *name
)
329 return search_item_byname(si
, name
, CATEGORY_GROUP
, si_group_byname
);
333 search_group_bygid(si_mod_t
*si
, gid_t gid
)
335 return search_item_bynumber(si
, (uint32_t)gid
, CATEGORY_GROUP
, si_group_bygid
);
339 search_group_byuuid(si_mod_t
*si
, uuid_t uuid
)
341 return search_item_byuuid(si
, uuid
, CATEGORY_GROUP
, si_group_byuuid
);
345 search_group_all(si_mod_t
*si
)
347 return search_list(si
, CATEGORY_GROUP
, si_group_all
);
351 search_groupist(si_mod_t
*si
, const char *name
, uint32_t count
)
354 search_si_private_t
*pp
;
355 si_item_t
*item
= NULL
;
358 if (si
== NULL
) return NULL
;
360 pp
= (search_si_private_t
*)si
->private;
361 if (pp
== NULL
) return NULL
;
365 while (NULL
!= (src
= search_get_module(pp
, CATEGORY_GROUPLIST
, &i
))) {
366 if (src
== pp
->cache
) continue;
368 if (src
->vtable
->sim_grouplist
!= NULL
) {
369 item
= src
->vtable
->sim_grouplist(si
, name
, count
);
370 if (item
!= NULL
) break;
378 search_netgroup_byname(si_mod_t
*si
, const char *name
)
380 int i
, cat
, null_res
;
381 search_si_private_t
*pp
;
382 si_list_t
*list
, *all
;
383 si_mod_t
*cache
, *src
;
385 if (si
== NULL
) return NULL
;
387 pp
= (search_si_private_t
*)si
->private;
388 if (pp
== NULL
) return NULL
;
390 cat
= CATEGORY_NETGROUP
;
392 cache
= search_cat_cache(pp
, cat
);
395 list
= si_netgroup_byname(cache
, name
);
396 if (list
!= NULL
) return list
;
403 while (NULL
!= (src
= search_get_module(pp
, cat
, &i
)))
405 if (src
== pp
->cache
) continue;
407 list
= si_netgroup_byname(src
, name
);
414 all
= si_list_concat(all
, list
);
415 si_list_release(list
);
418 if ((all
!= NULL
) && (null_res
== 0)) si_cache_add_list(cache
, si
, all
);
423 search_in_netgroup(si_mod_t
*si
, const char *group
, const char *host
, const char *user
, const char *domain
)
426 search_si_private_t
*pp
;
429 if (si
== NULL
) return 0;
431 pp
= (search_si_private_t
*)si
->private;
432 if (pp
== NULL
) return 0;
434 cat
= CATEGORY_NETGROUP
;
437 while (NULL
!= (src
= search_get_module(pp
, cat
, &i
)))
439 innetgr
= si_in_netgroup(src
, group
, host
, user
, domain
);
440 if (innetgr
!= 0) return 1;
447 search_alias_byname(si_mod_t
*si
, const char *name
)
449 return search_item_byname(si
, name
, CATEGORY_ALIAS
, si_alias_byname
);
453 search_alias_all(si_mod_t
*si
)
455 return search_list(si
, CATEGORY_ALIAS
, si_alias_all
);
459 search_host_byname(si_mod_t
*si
, const char *name
, int af
, const char *interface
, uint32_t *err
)
462 search_si_private_t
*pp
;
466 if (err
!= NULL
) *err
= SI_STATUS_NO_ERROR
;
468 if ((si
== NULL
) || (name
== NULL
))
470 if (err
!= NULL
) *err
= SI_STATUS_H_ERRNO_NO_RECOVERY
;
474 pp
= (search_si_private_t
*)si
->private;
477 if (err
!= NULL
) *err
= SI_STATUS_H_ERRNO_NO_RECOVERY
;
481 cat
= CATEGORY_HOST_IPV4
;
482 if (af
== AF_INET6
) cat
= CATEGORY_HOST_IPV6
;
486 while (NULL
!= (src
= search_get_module(pp
, cat
, &i
)))
488 item
= si_host_byname(src
, name
, af
, interface
, err
);
491 si_cache_add_item(search_cat_cache(pp
, cat
), src
, item
);
496 if (err
!= NULL
) *err
= SI_STATUS_H_ERRNO_HOST_NOT_FOUND
;
501 search_host_byaddr(si_mod_t
*si
, const void *addr
, int af
, const char *interface
, uint32_t *err
)
504 search_si_private_t
*pp
;
508 if (err
!= NULL
) *err
= SI_STATUS_NO_ERROR
;
510 if ((si
== NULL
) || (addr
== NULL
))
512 if (err
!= NULL
) *err
= SI_STATUS_H_ERRNO_NO_RECOVERY
;
516 pp
= (search_si_private_t
*)si
->private;
519 if (err
!= NULL
) *err
= SI_STATUS_H_ERRNO_NO_RECOVERY
;
523 cat
= CATEGORY_HOST_IPV4
;
524 if (af
== AF_INET6
) cat
= CATEGORY_HOST_IPV6
;
528 while (NULL
!= (src
= search_get_module(pp
, cat
, &i
)))
530 item
= si_host_byaddr(src
, addr
, af
, interface
, err
);
533 si_cache_add_item(search_cat_cache(pp
, cat
), src
, item
);
538 if (err
!= NULL
) *err
= SI_STATUS_H_ERRNO_HOST_NOT_FOUND
;
543 search_host_all(si_mod_t
*si
)
545 return search_list(si
, CATEGORY_HOST
, si_host_all
);
549 search_network_byname(si_mod_t
*si
, const char *name
)
551 return search_item_byname(si
, name
, CATEGORY_NETWORK
, si_network_byname
);
555 search_network_byaddr(si_mod_t
*si
, uint32_t addr
)
557 return search_item_bynumber(si
, addr
, CATEGORY_NETWORK
, si_network_byaddr
);
561 search_network_all(si_mod_t
*si
)
563 return search_list(si
, CATEGORY_NETWORK
, si_network_all
);
567 search_service_byname(si_mod_t
*si
, const char *name
, const char *proto
)
571 search_si_private_t
*pp
;
574 if (si
== NULL
) return NULL
;
575 if (name
== NULL
) return NULL
;
577 pp
= (search_si_private_t
*)si
->private;
578 if (pp
== NULL
) return NULL
;
580 cat
= CATEGORY_SERVICE
;
583 while (NULL
!= (src
= search_get_module(pp
, cat
, &i
)))
585 item
= si_service_byname(src
, name
, proto
);
588 si_cache_add_item(search_cat_cache(pp
, cat
), src
, item
);
597 search_service_byport(si_mod_t
*si
, int port
, const char *proto
)
600 search_si_private_t
*pp
;
604 if (si
== NULL
) return NULL
;
606 pp
= (search_si_private_t
*)si
->private;
607 if (pp
== NULL
) return NULL
;
609 cat
= CATEGORY_SERVICE
;
612 while (NULL
!= (src
= search_get_module(pp
, cat
, &i
)))
614 item
= si_service_byport(src
, port
, proto
);
617 si_cache_add_item(search_cat_cache(pp
, cat
), src
, item
);
626 search_service_all(si_mod_t
*si
)
628 return search_list(si
, CATEGORY_SERVICE
, si_service_all
);
632 search_protocol_byname(si_mod_t
*si
, const char *name
)
634 return search_item_byname(si
, name
, CATEGORY_PROTOCOL
, si_protocol_byname
);
638 search_protocol_bynumber(si_mod_t
*si
, int number
)
640 return search_item_bynumber(si
, (uint32_t)number
, CATEGORY_PROTOCOL
, si_protocol_bynumber
);
644 search_protocol_all(si_mod_t
*si
)
646 return search_list(si
, CATEGORY_PROTOCOL
, si_protocol_all
);
650 search_rpc_byname(si_mod_t
*si
, const char *name
)
652 return search_item_byname(si
, name
, CATEGORY_RPC
, si_rpc_byname
);
656 search_rpc_bynumber(si_mod_t
*si
, int number
)
659 search_si_private_t
*pp
;
663 if (si
== NULL
) return NULL
;
665 pp
= (search_si_private_t
*)si
->private;
666 if (pp
== NULL
) return NULL
;
671 while (NULL
!= (src
= search_get_module(pp
, cat
, &i
)))
673 item
= si_rpc_bynumber(src
, number
);
676 si_cache_add_item(search_cat_cache(pp
, cat
), src
, item
);
685 search_rpc_all(si_mod_t
*si
)
687 return search_list(si
, CATEGORY_RPC
, si_rpc_all
);
691 search_fs_byspec(si_mod_t
*si
, const char *name
)
693 return search_item_byname(si
, name
, CATEGORY_FS
, si_fs_byspec
);
697 search_fs_byfile(si_mod_t
*si
, const char *name
)
699 return search_item_byname(si
, name
, CATEGORY_FS
, si_fs_byfile
);
703 search_fs_all(si_mod_t
*si
)
705 return search_list(si
, CATEGORY_FS
, si_fs_all
);
709 search_mac_byname(si_mod_t
*si
, const char *name
)
711 return search_item_byname(si
, name
, CATEGORY_MAC
, si_mac_byname
);
715 search_mac_bymac(si_mod_t
*si
, const char *mac
)
717 return search_item_byname(si
, mac
, CATEGORY_MAC
, si_mac_bymac
);
721 search_mac_all(si_mod_t
*si
)
723 return search_list(si
, CATEGORY_MAC
, si_mac_all
);
727 search_srv_byname(si_mod_t
*si
, const char* qname
, const char *interface
, uint32_t *err
)
730 si_list_t
*list
= NULL
;
732 search_si_private_t
*pp
;
734 if (si
== NULL
) return NULL
;
736 pp
= (search_si_private_t
*)si
->private;
737 if (pp
== NULL
) return NULL
;
742 while (NULL
!= (src
= search_get_module(pp
, cat
, &i
)))
744 if (src
== pp
->cache
) continue;
746 if (src
->vtable
->sim_srv_byname
!= NULL
)
748 list
= src
->vtable
->sim_srv_byname(src
, qname
, interface
, err
);
749 if (list
!= NULL
) return list
;
753 if ((i
> 0) && (err
!= NULL
)) *err
= SI_STATUS_EAI_NONAME
;
758 search_wants_addrinfo(si_mod_t
*si
)
762 search_si_private_t
*pp
;
764 if (si
== NULL
) return 0;
766 pp
= (search_si_private_t
*)si
->private;
767 if (pp
== NULL
) return 0;
769 cat
= CATEGORY_ADDRINFO
;
772 while (NULL
!= (src
= search_get_module(pp
, cat
, &i
)))
774 if (src
== pp
->cache
) continue;
775 if (src
->vtable
->sim_addrinfo
!= NULL
) return 1;
782 search_addrinfo(si_mod_t
*si
, const void *node
, const void *serv
, uint32_t family
, uint32_t socktype
, uint32_t protocol
, uint32_t flags
, const char *interface
, uint32_t *err
)
785 search_si_private_t
*pp
;
786 si_list_t
*list
= NULL
;
789 if (err
!= NULL
) *err
= SI_STATUS_EAI_FAIL
;
791 if (si
== NULL
) return NULL
;
793 pp
= (search_si_private_t
*)si
->private;
794 if (pp
== NULL
) return NULL
;
796 cat
= CATEGORY_ADDRINFO
;
799 while (NULL
!= (src
= search_get_module(pp
, cat
, &i
)))
801 if (src
== pp
->cache
) continue;
803 if (src
->vtable
->sim_addrinfo
!= NULL
)
805 list
= src
->vtable
->sim_addrinfo(src
, node
, serv
, family
, socktype
, protocol
, flags
, interface
, err
);
806 if (list
!= NULL
) return list
;
810 if ((i
> 0) && (err
!= NULL
)) *err
= SI_STATUS_EAI_NONAME
;
815 search_nameinfo(si_mod_t
*si
, const struct sockaddr
*sa
, int flags
, const char *interface
, uint32_t *err
)
818 search_si_private_t
*pp
;
822 if (err
!= NULL
) *err
= SI_STATUS_EAI_FAIL
;
824 if (si
== NULL
) return NULL
;
826 pp
= (search_si_private_t
*)si
->private;
827 if (pp
== NULL
) return NULL
;
829 cat
= CATEGORY_NAMEINFO
;
832 while (NULL
!= (src
= search_get_module(pp
, cat
, &i
)))
834 item
= si_nameinfo(src
, sa
, flags
, interface
, err
);
837 si_cache_add_item(search_cat_cache(pp
, cat
), src
, item
);
838 if (err
!= NULL
) *err
= SI_STATUS_NO_ERROR
;
843 if ((i
> 0) && (err
!= NULL
)) *err
= SI_STATUS_EAI_NONAME
;
848 search_is_valid(si_mod_t
*si
, si_item_t
*item
)
852 if (si
== NULL
) return 0;
853 if (item
== NULL
) return 0;
854 if (si
->name
== NULL
) return 0;
855 if (item
->src
== NULL
) return 0;
857 src
= (si_mod_t
*)item
->src
;
859 if (src
->name
== NULL
) return 0;
860 if (string_not_equal(si
->name
, src
->name
)) return 0;
865 si_module_static_search(void)
867 static const struct si_mod_vtable_s search_vtable
=
869 .sim_close
= &search_close
,
871 .sim_is_valid
= &search_is_valid
,
873 .sim_user_byname
= &search_user_byname
,
874 .sim_user_byuid
= &search_user_byuid
,
875 .sim_user_byuuid
= &search_user_byuuid
,
876 .sim_user_all
= &search_user_all
,
878 .sim_group_byname
= &search_group_byname
,
879 .sim_group_bygid
= &search_group_bygid
,
880 .sim_group_byuuid
= &search_group_byuuid
,
881 .sim_group_all
= &search_group_all
,
883 .sim_grouplist
= &search_groupist
,
885 .sim_netgroup_byname
= &search_netgroup_byname
,
886 .sim_in_netgroup
= &search_in_netgroup
,
888 .sim_alias_byname
= &search_alias_byname
,
889 .sim_alias_all
= &search_alias_all
,
891 .sim_host_byname
= &search_host_byname
,
892 .sim_host_byaddr
= &search_host_byaddr
,
893 .sim_host_all
= &search_host_all
,
895 .sim_network_byname
= &search_network_byname
,
896 .sim_network_byaddr
= &search_network_byaddr
,
897 .sim_network_all
= &search_network_all
,
899 .sim_service_byname
= &search_service_byname
,
900 .sim_service_byport
= &search_service_byport
,
901 .sim_service_all
= &search_service_all
,
903 .sim_protocol_byname
= &search_protocol_byname
,
904 .sim_protocol_bynumber
= &search_protocol_bynumber
,
905 .sim_protocol_all
= &search_protocol_all
,
907 .sim_rpc_byname
= &search_rpc_byname
,
908 .sim_rpc_bynumber
= &search_rpc_bynumber
,
909 .sim_rpc_all
= &search_rpc_all
,
911 .sim_fs_byspec
= &search_fs_byspec
,
912 .sim_fs_byfile
= &search_fs_byfile
,
913 .sim_fs_all
= &search_fs_all
,
915 .sim_mac_byname
= &search_mac_byname
,
916 .sim_mac_bymac
= &search_mac_bymac
,
917 .sim_mac_all
= &search_mac_all
,
919 .sim_addrinfo
= &search_addrinfo
,
920 .sim_wants_addrinfo
= &search_wants_addrinfo
,
921 .sim_nameinfo
= &search_nameinfo
,
923 .sim_srv_byname
= &search_srv_byname
,
930 .flags
= SI_MOD_FLAG_STATIC
,
933 .vtable
= &search_vtable
,
936 static dispatch_once_t once
;
938 dispatch_once(&once
, ^{
939 si
.name
= strdup("search");
940 search_si_private_t
*pp
= calloc(1, sizeof(search_si_private_t
));
944 * Default search order:
946 * 2) DirectoryService/OpenDirectory (where available)
951 const char * const modules
[] =
953 "default", // CATEGORY_DEFAULT
962 int count
= sizeof(modules
) / sizeof(char *);
963 si_module_config_modules_for_category(pp
, CATEGORY_DEFAULT
, count
, modules
);
964 pp
->cache
= pp
->search_list
[CATEGORY_DEFAULT
].module[0];
966 char *check
= getenv("SYSINFO_CONF_ENABLE");
967 if ((check
!= NULL
) && (!strcmp(check
, "1")))
969 FILE *conf
= fopen(_PATH_SI_CONF
, "r");
975 char *line
= _fsi_get_line(conf
);
976 if (line
== NULL
) break;
978 si_module_config_parse_line(pp
, line
);
991 si_module_config_parse_line(search_si_private_t
*pp
, char *line
)
993 if (line
== NULL
|| line
[0] == '#') {
998 char **tokens
= _fsi_tokenize(line
, " : ", 0, &ntokens
);
1000 int cat
= CATEGORY_INVALID
;
1002 if (string_equal(tokens
[0], "default")) cat
= CATEGORY_DEFAULT
;
1003 else if (string_equal(tokens
[0], "user")) cat
= CATEGORY_USER
;
1004 else if (string_equal(tokens
[0], "group")) cat
= CATEGORY_GROUP
;
1005 else if (string_equal(tokens
[0], "grouplist")) cat
= CATEGORY_GROUPLIST
;
1006 else if (string_equal(tokens
[0], "netgroup")) cat
= CATEGORY_NETGROUP
;
1007 else if (string_equal(tokens
[0], "alias")) cat
= CATEGORY_ALIAS
;
1008 else if (string_equal(tokens
[0], "host")) cat
= CATEGORY_HOST_IPV4
;
1009 else if (string_equal(tokens
[0], "network")) cat
= CATEGORY_NETWORK
;
1010 else if (string_equal(tokens
[0], "service")) cat
= CATEGORY_SERVICE
;
1011 else if (string_equal(tokens
[0], "protocol")) cat
= CATEGORY_PROTOCOL
;
1012 else if (string_equal(tokens
[0], "rpc")) cat
= CATEGORY_RPC
;
1013 else if (string_equal(tokens
[0], "fs")) cat
= CATEGORY_FS
;
1014 else if (string_equal(tokens
[0], "mac")) cat
= CATEGORY_MAC
;
1015 else if (string_equal(tokens
[0], "addrinfo")) cat
= CATEGORY_ADDRINFO
;
1016 else if (string_equal(tokens
[0], "nameinfo")) cat
= CATEGORY_NAMEINFO
;
1018 if (cat
!= CATEGORY_INVALID
)
1020 si_module_config_modules_for_category(pp
, cat
, ntokens
, (const char * const *)tokens
);
1027 si_module_config_modules_for_category(search_si_private_t
*pp
, int cat
, int ntokens
, const char * const *tokens
)
1029 int count
= ntokens
- 1;
1030 pp
->search_list
[cat
].count
= count
;
1036 pp
->search_list
[cat
].module = (si_mod_t
**)calloc(pp
->search_list
[cat
].count
, sizeof(si_mod_t
*));
1037 pp
->search_list
[cat
].module_flags
= (uint32_t *)calloc(pp
->search_list
[cat
].count
, sizeof(uint32_t));
1038 if ((pp
->search_list
[cat
].module == NULL
) || (pp
->search_list
[cat
].module_flags
== NULL
))
1040 free(pp
->search_list
[cat
].module);
1041 free(pp
->search_list
[cat
].module_flags
);
1046 for (i
= 1, j
= 0; i
< ntokens
; i
++)
1048 si_mod_t
*mod
= si_module_with_name(tokens
[i
]);
1051 pp
->search_list
[cat
].module[j
] = mod
;
1054 if (string_equal(tokens
[i
], "cache"))
1056 pp
->search_list
[cat
].flags
|= SEARCH_FLAG_CACHE_ENABLED
;