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@
24 #include <si_module.h>
34 #include <arpa/inet.h>
35 #include <sys/param.h>
36 #include <sys/mount.h>
39 #include <dispatch/dispatch.h>
40 #include <TargetConditionals.h>
43 uint32_t notify_peek(int token
, uint32_t *val
);
45 extern uint32_t gL1CacheEnabled
;
47 /* These really should be in netdb.h & etc. */
48 #define _PATH_RPCS "/etc/rpc"
49 #define _PATH_ALIASES "/etc/aliases"
50 #define _PATH_ETHERS "/etc/ethers"
51 #define _PATH_NETGROUP "/etc/netgroup"
53 static dispatch_once_t rootfs_once
;
54 static si_item_t
*rootfs
= NULL
;
57 #define FNG_MEM 0x00000010
58 #define FNG_GRP 0x00000020
60 #define forever for(;;)
62 #define VALIDATION_PASSWD 0
63 #define VALIDATION_MASTER_PASSWD 1
64 #define VALIDATION_GROUP 2
65 #define VALIDATION_NETGROUP 3
66 #define VALIDATION_ALIASES 4
67 #define VALIDATION_HOSTS 5
68 #define VALIDATION_NETWORKS 6
69 #define VALIDATION_SERVICES 7
70 #define VALIDATION_PROTOCOLS 8
71 #define VALIDATION_RPC 9
72 #define VALIDATION_FSTAB 10
73 #define VALIDATION_ETHERS 11
74 #define VALIDATION_COUNT 12
76 #define VALIDATION_MASK_PASSWD 0x00000001
77 #define VALIDATION_MASK_MASTER_PASSWD 0x00000002
78 #define VALIDATION_MASK_MASK_GROUP 0x00000004
79 #define VALIDATION_MASK_NETGROUP 0x00000008
80 #define VALIDATION_MASK_ALIASES 0x00000010
81 #define VALIDATION_MASK_HOSTS 0x00000020
82 #define VALIDATION_MASK_NETWORKS 0x00000040
83 #define VALIDATION_MASK_SERVICES 0x00000080
84 #define VALIDATION_MASK_PROTOCOLS 0x00000100
85 #define VALIDATION_MASK_RPC 0x00000200
86 #define VALIDATION_MASK_FSTAB 0x00000400
87 #define VALIDATION_MASK_ETHERS 0x00000800
89 typedef struct file_netgroup_member_s
95 struct file_netgroup_member_s
*next
;
96 } file_netgroup_member_t
;
98 typedef struct file_netgroup_s
102 file_netgroup_member_t
*members
;
103 struct file_netgroup_s
*next
;
108 uint32_t validation_notify_mask
;
109 int notify_token
[VALIDATION_COUNT
];
110 file_netgroup_t
*file_netgroup_cache
;
111 uint64_t netgroup_validation_a
;
112 uint64_t netgroup_validation_b
;
115 static pthread_mutex_t file_mutex
= PTHREAD_MUTEX_INITIALIZER
;
118 _fsi_copy_string(char *s
)
123 if (s
== NULL
) return NULL
;
127 if (t
== NULL
) return NULL
;
134 _fsi_append_string(char *s
, char **l
)
138 if (s
== NULL
) return l
;
140 for (i
= 0; l
[i
] != NULL
; i
++);
146 l
= (char **) reallocf(l
, (len
+ 2) * sizeof(char *));
147 if (l
== NULL
) return NULL
;
155 _fsi_tokenize(char *data
, const char *sep
, int trailing_empty
, int *ntokens
)
158 int p
, i
, start
, end
, more
, len
, end_on_sep
;
164 if (data
== NULL
) return NULL
;
166 if (ntokens
!= NULL
) *ntokens
= 0;
169 tokens
= _fsi_append_string(data
, tokens
);
170 if (ntokens
!= NULL
) *ntokens
= *ntokens
+ 1;
177 while (data
[p
] != '\0')
180 /* skip leading white space */
181 while ((data
[p
] == ' ') || (data
[p
] == '\t') || (data
[p
] == '\n')) p
++;
183 /* check for end of line */
184 if (data
[p
] == '\0') break;
186 /* scan for separator */
192 while (scanning
== 1)
194 if (data
[p
] == '\0') break;
196 for (i
= 0; i
< len
; i
++)
198 if (data
[p
] == sep
[i
])
206 /* end is last non-whitespace character */
207 if ((scanning
== 1) && (data
[p
] != ' ') && (data
[p
] != '\t') && (data
[p
] != '\n')) end
= p
;
212 /* see if there's data left after p */
214 if (data
[p
] != '\0') more
= 1;
216 /* set the character following the token to nul */
217 if (start
== p
) data
[p
] = '\0';
218 else data
[end
+ 1] = '\0';
220 tokens
= _fsi_append_string(data
+ start
, tokens
);
221 if (ntokens
!= NULL
) *ntokens
= *ntokens
+ 1;
225 if ((end_on_sep
== 1) && (trailing_empty
!= 0))
227 /* if the scan ended on an empty token, add a null string */
228 tokens
= _fsi_append_string(data
+ p
, tokens
);
229 if (ntokens
!= NULL
) *ntokens
= *ntokens
+ 1;
236 _fsi_get_line(FILE *fp
)
243 fgets(s
, sizeof(s
), fp
);
244 if ((s
== NULL
) || (s
[0] == '\0')) return NULL
;
246 if (s
[0] != '#') s
[strlen(s
) - 1] = '\0';
248 out
= _fsi_copy_string(s
);
253 _fsi_validation_path(int vtype
)
255 if (vtype
== VALIDATION_PASSWD
) return _PATH_PASSWD
;
256 else if (vtype
== VALIDATION_MASTER_PASSWD
) return _PATH_MASTERPASSWD
;
257 else if (vtype
== VALIDATION_GROUP
) return _PATH_GROUP
;
258 else if (vtype
== VALIDATION_NETGROUP
) return _PATH_NETGROUP
;
259 else if (vtype
== VALIDATION_ALIASES
) return _PATH_ALIASES
;
260 else if (vtype
== VALIDATION_HOSTS
) return _PATH_HOSTS
;
261 else if (vtype
== VALIDATION_NETWORKS
) return _PATH_NETWORKS
;
262 else if (vtype
== VALIDATION_SERVICES
) return _PATH_SERVICES
;
263 else if (vtype
== VALIDATION_PROTOCOLS
) return _PATH_PROTOCOLS
;
264 else if (vtype
== VALIDATION_RPC
) return _PATH_RPCS
;
265 else if (vtype
== VALIDATION_FSTAB
) return _PATH_FSTAB
;
266 else if (vtype
== VALIDATION_ETHERS
) return _PATH_ETHERS
;
272 _fsi_get_validation(si_mod_t
*si
, int vtype
, const char *path
, FILE *f
, uint64_t *a
, uint64_t *b
)
275 file_si_private_t
*pp
;
279 if (a
!= NULL
) *a
= 0;
280 if (b
!= NULL
) *b
= 0;
282 if (si
== NULL
) return;
283 if (path
== NULL
) return;
284 if (gL1CacheEnabled
== 0) return;
286 pp
= (file_si_private_t
*)si
->private;
287 if (pp
== NULL
) return;
289 if (vtype
>= VALIDATION_COUNT
) return;
292 if (bit
& pp
->validation_notify_mask
)
294 /* use notify validation for this type */
295 if (pp
->notify_token
[vtype
] < 0)
298 asprintf(&str
, "com.apple.system.info:%s", path
);
299 if (str
== NULL
) return;
301 status
= notify_register_check(str
, &(pp
->notify_token
[vtype
]));
307 status
= notify_peek(pp
->notify_token
[vtype
], &peek
);
308 if (status
== NOTIFY_STATUS_OK
) *a
= ntohl(peek
);
311 if (b
!= NULL
) *b
= vtype
;
315 /* use stat() and last mod time for this type */
316 memset(&sb
, 0, sizeof(struct stat
));
319 if (fstat(fileno(f
), &sb
) == 0)
321 if (a
!= NULL
) *a
= sb
.st_mtimespec
.tv_sec
;
322 if (b
!= NULL
) *b
= sb
.st_mtimespec
.tv_nsec
;
327 path
= _fsi_validation_path(vtype
);
330 memset(&sb
, 0, sizeof(struct stat
));
331 if (stat(path
, &sb
) == 0)
333 if (a
!= NULL
) *a
= sb
.st_mtimespec
.tv_sec
;
334 if (b
!= NULL
) *b
= sb
.st_mtimespec
.tv_nsec
;
342 _fsi_validate(si_mod_t
*si
, int cat
, uint64_t va
, uint64_t vb
)
346 uint32_t item_val
, curr_val
, vtype
;
347 file_si_private_t
*pp
;
350 if (si
== NULL
) return 0;
352 #if TARGET_OS_EMBEDDED
353 /* /etc is on a read-only filesystem, so no validation is required */
357 pp
= (file_si_private_t
*)si
->private;
358 if (pp
== NULL
) return 0;
365 if (geteuid() == 0) vtype
= VALIDATION_MASTER_PASSWD
;
366 else vtype
= VALIDATION_PASSWD
;
371 vtype
= VALIDATION_GROUP
;
374 case CATEGORY_GROUPLIST
:
376 vtype
= VALIDATION_GROUP
;
379 case CATEGORY_NETGROUP
:
381 vtype
= VALIDATION_NETGROUP
;
386 vtype
= VALIDATION_ALIASES
;
389 case CATEGORY_HOST_IPV4
:
391 vtype
= VALIDATION_HOSTS
;
394 case CATEGORY_HOST_IPV6
:
396 vtype
= VALIDATION_HOSTS
;
399 case CATEGORY_NETWORK
:
401 vtype
= VALIDATION_NETWORKS
;
404 case CATEGORY_SERVICE
:
406 vtype
= VALIDATION_SERVICES
;
409 case CATEGORY_PROTOCOL
:
411 vtype
= VALIDATION_PROTOCOLS
;
416 vtype
= VALIDATION_RPC
;
421 vtype
= VALIDATION_FSTAB
;
426 vtype
= VALIDATION_ETHERS
;
432 if (pp
->notify_token
[vtype
] < 0)
434 path
= _fsi_validation_path(vtype
);
435 if (path
== NULL
) return 0;
437 memset(&sb
, 0, sizeof(struct stat
));
438 if (stat(path
, &sb
) != 0) return 0;
439 if (va
!= sb
.st_mtimespec
.tv_sec
) return 0;
440 if (vb
!= sb
.st_mtimespec
.tv_nsec
) return 0;
446 status
= notify_peek(pp
->notify_token
[vtype
], &curr_val
);
447 if (status
!= NOTIFY_STATUS_OK
) return 0;
449 curr_val
= ntohl(curr_val
);
450 if (item_val
!= curr_val
) return 0;
456 /* netgroup support */
458 _fsi_append_char_to_line(char c
, char *buf
, size_t *x
)
460 if (x
== NULL
) return NULL
;
462 if (buf
== NULL
) *x
= 0;
464 if ((*x
% CHUNK
) == 0)
466 buf
= reallocf(buf
, *x
+ CHUNK
);
467 memset(buf
+ *x
, 0, CHUNK
);
477 _fsi_read_netgroup_line(FILE *f
)
484 if (f
== NULL
) return NULL
;
491 if (out
== NULL
) return NULL
;
492 return _fsi_append_char_to_line('\0', out
, &x
);
495 if (c
== '\n') return _fsi_append_char_to_line('\0', out
, &x
);
496 if (c
== '(') paren
= 1;
497 else if (c
== ')') paren
= 0;
499 if ((c
== ' ') || (c
== '\t'))
501 if ((white
== 0) && (paren
== 0)) out
= _fsi_append_char_to_line(' ', out
, &x
);
509 if (c
== EOF
) return _fsi_append_char_to_line('\0', out
, &x
);
510 if (c
== '\n') break;
515 out
= _fsi_append_char_to_line(c
, out
, &x
);
521 static file_netgroup_t
*
522 _fsi_find_netgroup(file_netgroup_t
**list
, const char *name
, int create
)
526 if (list
== NULL
) return NULL
;
528 for (n
= *list
; n
!= NULL
; n
= n
->next
)
530 if (!strcmp(name
, n
->name
)) return n
;
533 if (create
== 0) return NULL
;
535 n
= (file_netgroup_t
*)calloc(1, sizeof(file_netgroup_t
));
536 if (n
== NULL
) return NULL
;
538 n
->name
= strdup(name
);
546 _fsi_free_file_netgroup(file_netgroup_t
*n
)
548 file_netgroup_member_t
*m
;
550 if (n
== NULL
) return;
556 file_netgroup_member_t
*x
= m
;
568 _fsi_add_netgroup_group(file_netgroup_t
*n
, char *grp
)
570 file_netgroup_member_t
*g
;
572 if (n
== NULL
) return;
574 g
= (file_netgroup_member_t
*)calloc(1, sizeof(file_netgroup_member_t
));
575 if (g
== NULL
) return;
578 g
->host
= strdup(grp
);
580 g
->next
= n
->members
;
587 _fsi_add_netgroup_member(file_netgroup_t
*n
, char *mem
)
590 file_netgroup_member_t
*m
;
593 if (n
== NULL
) return;
595 m
= (file_netgroup_member_t
*)calloc(1, sizeof(file_netgroup_member_t
));
596 if (m
== NULL
) return;
598 tokens
= _fsi_tokenize(mem
+ 1, ",)", 0, &ntokens
);
606 if ((ntokens
> 0) && (tokens
[0][0] != '\0')) m
->host
= strdup(tokens
[0]);
607 if ((ntokens
> 1) && (tokens
[1][0] != '\0')) m
->user
= strdup(tokens
[1]);
608 if ((ntokens
> 2) && (tokens
[2][0] != '\0')) m
->domain
= strdup(tokens
[2]);
613 m
->next
= n
->members
;
617 static file_netgroup_t
*
618 _fsi_process_netgroup_line(file_netgroup_t
**pass1
, char *line
)
624 tokens
= _fsi_tokenize(line
, " ", 0, &ntokens
);
625 if (tokens
== NULL
) return NULL
;
626 if (tokens
[0] == NULL
)
632 n
= _fsi_find_netgroup(pass1
, tokens
[0], 1);
634 for (i
= 1; tokens
[i
] != NULL
; i
++)
636 if (tokens
[i
][0] == '(') _fsi_add_netgroup_member(n
, tokens
[i
]);
637 else if (tokens
[i
][0] != '\0') _fsi_add_netgroup_group(n
, tokens
[i
]);
645 _fsi_flatten_netgroup(file_netgroup_t
*pass1
, file_netgroup_t
**top
, file_netgroup_t
*n
, file_netgroup_member_t
*m
)
647 if (n
== NULL
) return;
649 if (n
->flags
== 1) return;
654 *top
= (file_netgroup_t
*)calloc(1, sizeof(file_netgroup_t
));
655 if (*top
== NULL
) return;
656 (*top
)->name
= strdup(n
->name
);
657 if ((*top
)->name
== NULL
)
667 if (m
->flags
& FNG_MEM
)
669 file_netgroup_member_t
*x
= (file_netgroup_member_t
*)calloc(1, sizeof(file_netgroup_member_t
));
670 if (x
== NULL
) return;
673 if (m
->host
!= NULL
) x
->host
= strdup(m
->host
);
674 if (m
->user
!= NULL
) x
->user
= strdup(m
->user
);
675 if (m
->domain
!= NULL
) x
->domain
= strdup(m
->domain
);
677 x
->next
= (*top
)->members
;
682 file_netgroup_t
*g
= _fsi_find_netgroup(&pass1
, m
->host
, 0);
683 if (g
== NULL
) continue;
685 _fsi_flatten_netgroup(pass1
, top
, g
, g
->members
);
693 _fsi_check_netgroup_cache(si_mod_t
*si
)
695 file_netgroup_t
*p1
, *n
, *x
, *a
;
698 file_si_private_t
*pp
;
700 if (si
== NULL
) return;
702 pp
= (file_si_private_t
*)si
->private;
703 if (pp
== NULL
) return;
705 pthread_mutex_lock(&file_mutex
);
707 if (_fsi_validate(si
, CATEGORY_NETGROUP
, pp
->netgroup_validation_a
, pp
->netgroup_validation_b
))
709 pthread_mutex_unlock(&file_mutex
);
713 n
= pp
->file_netgroup_cache
;
718 _fsi_free_file_netgroup(x
);
721 pp
->file_netgroup_cache
= NULL
;
723 f
= fopen(_PATH_NETGROUP
, "r");
726 pthread_mutex_unlock(&file_mutex
);
730 _fsi_get_validation(si
, VALIDATION_NETGROUP
, _PATH_NETGROUP
, f
, &(pp
->netgroup_validation_a
), &(pp
->netgroup_validation_b
));
734 line
= _fsi_read_netgroup_line(f
);
737 n
= _fsi_process_netgroup_line(&p1
, line
);
740 line
= _fsi_read_netgroup_line(f
);
745 for (n
= p1
; n
!= NULL
; n
= n
->next
)
748 _fsi_flatten_netgroup(p1
, &a
, n
, n
->members
);
749 for (x
= p1
; x
!= NULL
; x
= x
->next
) x
->flags
= 0;
753 a
->next
= pp
->file_netgroup_cache
;
754 pp
->file_netgroup_cache
= a
;
763 _fsi_free_file_netgroup(x
);
766 pthread_mutex_unlock(&file_mutex
);
772 _fsi_parse_user(si_mod_t
*si
, const char *name
, uid_t uid
, int which
, char *data
, int format
, uint64_t va
, uint64_t vb
)
776 time_t change
, expire
;
780 if (data
== NULL
) return NULL
;
783 tokens
= _fsi_tokenize(data
, ":", 1, &ntokens
);
784 if (((format
== 0) && (ntokens
!= 10)) || ((format
== 1) && (ntokens
!= 7)))
790 xuid
= atoi(tokens
[2]);
793 /* XXX MATCH GECOS? XXX*/
794 if (which
== SEL_ALL
) match
= 1;
795 else if ((which
== SEL_NAME
) && (string_equal(name
, tokens
[0]))) match
= 1;
796 else if ((which
== SEL_NUMBER
) && (uid
== xuid
)) match
= 1;
806 /* master.passwd: name[0] passwd[1] uid[2] gid[3] class[4] change[5] expire[6] gecos[7] dir[8] shell[9] */
807 /* struct pwd: name[0] passwd[1] uid[2] gid[3] change[5] class[4] gecos[7] dir[8] shell[9] expire[6] */
808 change
= atoi(tokens
[5]);
809 expire
= atoi(tokens
[6]);
810 item
= (si_item_t
*)LI_ils_create("L4488ss44LssssL", (unsigned long)si
, CATEGORY_USER
, 1, va
, vb
, tokens
[0], tokens
[1], xuid
, atoi(tokens
[3]), change
, tokens
[4], tokens
[7], tokens
[8], tokens
[9], expire
);
814 /* passwd: name[0] passwd[1] uid[2] gid[3] gecos[4] dir[5] shell[6] */
815 /* struct pwd: name[0] passwd[1] uid[2] gid[3] change[-] class[-] gecos[4] dir[5] shell[6] expire[-] */
816 item
= (si_item_t
*)LI_ils_create("L4488ss44LssssL", (unsigned long)si
, CATEGORY_USER
, 1, va
, vb
, tokens
[0], tokens
[1], xuid
, atoi(tokens
[3]), 0, "", tokens
[4], tokens
[5], tokens
[6], 0);
824 _fsi_get_user(si_mod_t
*si
, const char *name
, uid_t uid
, int which
)
833 if ((which
== SEL_NAME
) && (name
== NULL
)) return NULL
;
843 f
= fopen(_PATH_MASTERPASSWD
, "r");
844 _fsi_get_validation(si
, VALIDATION_MASTER_PASSWD
, _PATH_MASTERPASSWD
, f
, &va
, &vb
);
848 f
= fopen(_PATH_PASSWD
, "r");
849 _fsi_get_validation(si
, VALIDATION_PASSWD
, _PATH_PASSWD
, f
, &va
, &vb
);
853 if (f
== NULL
) return NULL
;
858 line
= _fsi_get_line(f
);
859 if (line
== NULL
) break;
868 item
= _fsi_parse_user(si
, name
, uid
, which
, line
, fmt
, va
, vb
);
872 if (item
== NULL
) continue;
874 if (which
== SEL_ALL
)
876 all
= si_list_add(all
, item
);
877 si_item_release(item
);
891 _fsi_parse_group(si_mod_t
*si
, const char *name
, gid_t gid
, int which
, char *data
, uint64_t va
, uint64_t vb
)
893 char **tokens
, **members
;
898 if (data
== NULL
) return NULL
;
901 tokens
= _fsi_tokenize(data
, ":", 1, &ntokens
);
908 xgid
= atoi(tokens
[2]);
911 if (which
== SEL_ALL
) match
= 1;
912 else if ((which
== SEL_NAME
) && (string_equal(name
, tokens
[0]))) match
= 1;
913 else if ((which
== SEL_NUMBER
) && (gid
== xgid
)) match
= 1;
922 members
= _fsi_tokenize(tokens
[3], ",", 1, &ntokens
);
924 item
= (si_item_t
*)LI_ils_create("L4488ss4*", (unsigned long)si
, CATEGORY_GROUP
, 1, va
, vb
, tokens
[0], tokens
[1], xgid
, members
);
933 _fsi_get_group(si_mod_t
*si
, const char *name
, gid_t gid
, int which
)
941 if ((which
== SEL_NAME
) && (name
== NULL
)) return NULL
;
946 f
= fopen(_PATH_GROUP
, "r");
947 if (f
== NULL
) return NULL
;
949 _fsi_get_validation(si
, VALIDATION_GROUP
, _PATH_GROUP
, f
, &va
, &vb
);
953 line
= _fsi_get_line(f
);
954 if (line
== NULL
) break;
963 item
= _fsi_parse_group(si
, name
, gid
, which
, line
, va
, vb
);
967 if (item
== NULL
) continue;
969 if (which
== SEL_ALL
)
971 all
= si_list_add(all
, item
);
972 si_item_release(item
);
985 _fsi_get_grouplist(si_mod_t
*si
, const char *user
)
987 char **tokens
, **members
;
988 int ntokens
, i
, match
, gidcount
;
997 if (user
== NULL
) return NULL
;
1004 item
= si
->vtable
->sim_user_byname(si
, user
);
1007 pw
= (struct passwd
*)((uintptr_t)item
+ sizeof(si_item_t
));
1008 basegid
= pw
->pw_gid
;
1009 si_item_release(item
);
1013 f
= fopen(_PATH_GROUP
, "r");
1014 if (f
== NULL
) return NULL
;
1016 _fsi_get_validation(si
, VALIDATION_GROUP
, _PATH_GROUP
, f
, &va
, &vb
);
1020 line
= _fsi_get_line(f
);
1021 if (line
== NULL
) break;
1031 tokens
= _fsi_tokenize(line
, ":", 1, &ntokens
);
1039 members
= _fsi_tokenize(tokens
[3], ",", 1, &ntokens
);
1044 for (i
= 0; i
< ntokens
; i
++)
1046 if (string_equal(user
, members
[i
]))
1048 gid
= atoi(tokens
[2]);
1061 gidlist
= (gid_t
*) reallocf(gidlist
, (gidcount
+ 1) * sizeof(gid_t
));
1062 if (gidlist
== NULL
)
1068 gidlist
[gidcount
++] = gid
;
1074 if (gidcount
!= 0) {
1075 item
= (si_item_t
*)LI_ils_create("L4488s4@", (unsigned long)si
, CATEGORY_GROUPLIST
, 1, va
, vb
, user
, gidcount
,
1076 gidcount
* sizeof(gid_t
), gidlist
);
1087 _fsi_parse_alias(si_mod_t
*si
, const char *name
, int which
, char *data
, uint64_t va
, uint64_t vb
)
1089 char **tokens
, **members
;
1093 if (data
== NULL
) return NULL
;
1096 tokens
= _fsi_tokenize(data
, ":", 1, &ntokens
);
1105 if (which
== SEL_ALL
) match
= 1;
1106 else if (string_equal(name
, tokens
[0])) match
= 1;
1115 members
= _fsi_tokenize(tokens
[1], ",", 1, &ntokens
);
1117 item
= (si_item_t
*)LI_ils_create("L4488s4*4", (unsigned long)si
, CATEGORY_ALIAS
, 1, va
, vb
, tokens
[0], ntokens
, members
, 1);
1126 _fsi_get_alias(si_mod_t
*si
, const char *name
, int which
)
1134 if ((which
== SEL_NAME
) && (name
== NULL
)) return NULL
;
1139 f
= fopen(_PATH_ALIASES
, "r");
1140 if (f
== NULL
) return NULL
;
1142 _fsi_get_validation(si
, VALIDATION_ALIASES
, _PATH_ALIASES
, f
, &va
, &vb
);
1146 line
= _fsi_get_line(f
);
1147 if (line
== NULL
) break;
1156 item
= _fsi_parse_alias(si
, name
, which
, line
, va
, vb
);
1160 if (item
== NULL
) continue;
1162 if (which
== SEL_ALL
)
1164 all
= si_list_add(all
, item
);
1165 si_item_release(item
);
1180 _fsi_parse_ether(si_mod_t
*si
, const char *name
, int which
, char *data
, uint64_t va
, uint64_t vb
)
1187 if (data
== NULL
) return NULL
;
1190 tokens
= _fsi_tokenize(data
, " \t", 1, &ntokens
);
1197 cmac
= si_standardize_mac_address(tokens
[0]);
1205 if (which
== SEL_ALL
) match
= 1;
1206 else if ((which
== SEL_NAME
) && (string_equal(name
, tokens
[1]))) match
= 1;
1207 else if ((which
== SEL_NUMBER
) && (string_equal(name
, cmac
))) match
= 1;
1216 item
= (si_item_t
*)LI_ils_create("L4488ss", (unsigned long)si
, CATEGORY_MAC
, 1, va
, vb
, tokens
[1], cmac
);
1225 _fsi_get_ether(si_mod_t
*si
, const char *name
, int which
)
1233 if ((which
!= SEL_ALL
) && (name
== NULL
)) return NULL
;
1236 if (which
== SEL_NUMBER
)
1238 cmac
= si_standardize_mac_address(name
);
1239 if (cmac
== NULL
) return NULL
;
1245 f
= fopen(_PATH_ETHERS
, "r");
1246 if (f
== NULL
) return NULL
;
1248 _fsi_get_validation(si
, VALIDATION_ETHERS
, _PATH_ETHERS
, f
, &va
, &vb
);
1252 line
= _fsi_get_line(f
);
1253 if (line
== NULL
) break;
1263 if (which
== SEL_NUMBER
) item
= _fsi_parse_ether(si
, cmac
, which
, line
, va
, vb
);
1264 else item
= _fsi_parse_ether(si
, name
, which
, line
, va
, vb
);
1269 if (item
== NULL
) continue;
1271 if (which
== SEL_ALL
)
1273 all
= si_list_add(all
, item
);
1274 si_item_release(item
);
1289 _fsi_parse_host(si_mod_t
*si
, const char *name
, const void *addr
, int af
, int which
, char *data
, uint64_t va
, uint64_t vb
)
1291 char **tokens
, **h_aliases
, *null_alias
;
1292 int i
, ntokens
, match
, h_addrtype
, h_length
;
1296 char *h_addr_list
[2];
1297 char h_addr_4
[4], h_addr_6
[16];
1299 if (data
== NULL
) return NULL
;
1304 tokens
= _fsi_tokenize(data
, " ", 0, &ntokens
);
1311 h_addr_list
[1] = NULL
;
1313 h_addrtype
= AF_UNSPEC
;
1314 if (inet_pton(AF_INET
, tokens
[0], &a4
) == 1)
1316 h_addrtype
= AF_INET
;
1317 h_length
= sizeof(struct in_addr
);
1318 memcpy(h_addr_4
, &a4
, 4);
1319 h_addr_list
[0] = h_addr_4
;
1321 else if (inet_pton(AF_INET6
, tokens
[0], &a6
) == 1)
1323 h_addrtype
= AF_INET6
;
1324 h_length
= sizeof(struct in6_addr
);
1325 memcpy(h_addr_6
, &a6
, 16);
1326 h_addr_list
[0] = h_addr_6
;
1329 if (h_addrtype
== AF_UNSPEC
)
1336 if (ntokens
> 2) h_aliases
= &(tokens
[2]);
1340 if (which
== SEL_ALL
) match
= 1;
1343 if (h_addrtype
== af
)
1345 if (which
== SEL_NAME
)
1347 if (string_equal(name
, tokens
[1])) match
= 1;
1348 else if (h_aliases
!= NULL
)
1350 for (i
= 0; (h_aliases
[i
] != NULL
) && (match
== 0); i
++)
1351 if (string_equal(name
, h_aliases
[i
])) match
= 1;
1354 else if (which
== SEL_NUMBER
)
1356 if (memcmp(addr
, h_addr_list
[0], h_length
) == 0) match
= 1;
1369 if (h_aliases
== NULL
) h_aliases
= &null_alias
;
1371 if (h_addrtype
== AF_INET
)
1373 item
= (si_item_t
*)LI_ils_create("L4488s*44a", (unsigned long)si
, CATEGORY_HOST_IPV4
, 1, va
, vb
, tokens
[1], h_aliases
, h_addrtype
, h_length
, h_addr_list
);
1377 item
= (si_item_t
*)LI_ils_create("L4488s*44c", (unsigned long)si
, CATEGORY_HOST_IPV6
, 1, va
, vb
, tokens
[1], h_aliases
, h_addrtype
, h_length
, h_addr_list
);
1386 _fsi_get_host(si_mod_t
*si
, const char *name
, const void *addr
, int af
, int which
, uint32_t *err
)
1394 if ((which
== SEL_NAME
) && (name
== NULL
))
1396 if (err
!= NULL
) *err
= NO_RECOVERY
;
1400 if ((which
== SEL_NUMBER
) && (addr
== NULL
))
1402 if (err
!= NULL
) *err
= NO_RECOVERY
;
1406 f
= fopen(_PATH_HOSTS
, "r");
1409 if (err
!= NULL
) *err
= NO_RECOVERY
;
1413 _fsi_get_validation(si
, VALIDATION_HOSTS
, _PATH_HOSTS
, f
, &va
, &vb
);
1419 line
= _fsi_get_line(f
);
1420 if (line
== NULL
) break;
1429 item
= _fsi_parse_host(si
, name
, addr
, af
, which
, line
, va
, vb
);
1433 if (item
== NULL
) continue;
1435 if (which
== SEL_ALL
)
1437 all
= si_list_add(all
, item
);
1438 si_item_release(item
);
1453 _fsi_parse_service(si_mod_t
*si
, const char *name
, const char *proto
, int port
, int which
, char *data
, uint64_t va
, uint64_t vb
)
1455 char **tokens
, **s_aliases
, *xproto
;
1456 int i
, ntokens
, match
;
1460 if (data
== NULL
) return NULL
;
1465 tokens
= _fsi_tokenize(data
, " ", 0, &ntokens
);
1473 if (ntokens
> 2) s_aliases
= &(tokens
[2]);
1475 xport
= atoi(tokens
[1]);
1477 xproto
= strchr(tokens
[1], '/');
1486 if ((proto
!= NULL
) && (string_not_equal(proto
, xproto
)))
1493 if (which
== SEL_ALL
) match
= 1;
1494 else if (which
== SEL_NAME
)
1496 if (string_equal(name
, tokens
[0])) match
= 1;
1497 else if (s_aliases
!= NULL
)
1499 for (i
= 0; (s_aliases
[i
] != NULL
) && (match
== 0); i
++)
1500 if (string_equal(name
, s_aliases
[i
])) match
= 1;
1503 else if ((which
== SEL_NUMBER
) && (port
== xport
)) match
= 1;
1511 /* strange but correct */
1512 xport
= htons(xport
);
1514 item
= (si_item_t
*)LI_ils_create("L4488s*4s", (unsigned long)si
, CATEGORY_SERVICE
, 1, va
, vb
, tokens
[0], s_aliases
, xport
, xproto
);
1522 _fsi_get_service(si_mod_t
*si
, const char *name
, const char *proto
, int port
, int which
)
1530 if ((which
== SEL_NAME
) && (name
== NULL
)) return NULL
;
1531 if ((which
== SEL_NUMBER
) && (port
== 0)) return NULL
;
1533 f
= fopen(_PATH_SERVICES
, "r");
1534 if (f
== NULL
) return NULL
;
1536 _fsi_get_validation(si
, VALIDATION_SERVICES
, _PATH_SERVICES
, f
, &va
, &vb
);
1542 line
= _fsi_get_line(f
);
1543 if (line
== NULL
) break;
1552 p
= strchr(line
, '#');
1553 if (p
!= NULL
) *p
= '\0';
1555 item
= _fsi_parse_service(si
, name
, proto
, port
, which
, line
, va
, vb
);
1559 if (item
== NULL
) continue;
1561 if (which
== SEL_ALL
)
1563 all
= si_list_add(all
, item
);
1564 si_item_release(item
);
1577 * Generic name/number/aliases lookup
1578 * Works for protocols, networks, and rpcs
1582 _fsi_parse_name_num_aliases(si_mod_t
*si
, const char *name
, int num
, int which
, char *data
, uint64_t va
, uint64_t vb
, int cat
)
1584 char **tokens
, **aliases
;
1585 int i
, ntokens
, match
, xnum
;
1588 if (data
== NULL
) return NULL
;
1591 tokens
= _fsi_tokenize(data
, " ", 0, &ntokens
);
1598 xnum
= atoi(tokens
[1]);
1601 if (ntokens
> 2) aliases
= &(tokens
[2]);
1605 if (which
== SEL_ALL
) match
= 1;
1606 else if (which
== SEL_NAME
)
1608 if (string_equal(name
, tokens
[0])) match
= 1;
1609 else if (aliases
!= NULL
)
1611 for (i
= 0; (aliases
[i
] != NULL
) && (match
== 0); i
++)
1612 if (string_equal(name
, aliases
[i
])) match
= 1;
1615 else if ((which
== SEL_NUMBER
) && (num
== xnum
)) match
= 1;
1624 case CATEGORY_NETWORK
:
1626 item
= (si_item_t
*)LI_ils_create("L4488s*44", (unsigned long)si
, cat
, 1, va
, vb
, tokens
[0], aliases
, AF_INET
, xnum
);
1628 case CATEGORY_PROTOCOL
:
1632 item
= (si_item_t
*)LI_ils_create("L4488s*4", (unsigned long)si
, cat
, 1, va
, vb
, tokens
[0], aliases
, xnum
);
1644 _fsi_get_name_number_aliases(si_mod_t
*si
, const char *name
, int num
, int which
, int cat
)
1655 case CATEGORY_NETWORK
:
1656 vtype
= VALIDATION_NETWORKS
;
1657 path
= _PATH_NETWORKS
;
1659 case CATEGORY_PROTOCOL
:
1660 vtype
= VALIDATION_PROTOCOLS
;
1661 path
= _PATH_PROTOCOLS
;
1664 vtype
= VALIDATION_RPC
;
1671 f
= fopen(path
, "r");
1672 if (f
== NULL
) return NULL
;
1674 _fsi_get_validation(si
, vtype
, path
, f
, &va
, &vb
);
1680 line
= _fsi_get_line(f
);
1681 if (line
== NULL
) break;
1690 p
= strchr(line
, '#');
1691 if (p
!= NULL
) *p
= '\0';
1693 item
= _fsi_parse_name_num_aliases(si
, name
, num
, which
, line
, va
, vb
, cat
);
1697 if (item
== NULL
) continue;
1699 if (which
== SEL_ALL
)
1701 all
= si_list_add(all
, item
);
1702 si_item_release(item
);
1717 _fsi_parse_fs(si_mod_t
*si
, const char *name
, int which
, char *data
, uint64_t va
, uint64_t vb
)
1719 char **tokens
, *tmp
, **opts
, *fstype
;
1720 int ntokens
, match
, i
, freq
, passno
;
1723 if (data
== NULL
) return NULL
;
1730 tokens
= _fsi_tokenize(data
, " ", 0, &ntokens
);
1731 if ((ntokens
< 4) || (ntokens
> 6))
1737 if (ntokens
>= 5) freq
= atoi(tokens
[4]);
1738 if (ntokens
== 6) passno
= atoi(tokens
[5]);
1740 tmp
= strdup(tokens
[3]);
1748 opts
= _fsi_tokenize(tmp
, ",", 0, &ntokens
);
1757 for (i
= 0; i
< ntokens
; i
++)
1759 if ((string_equal(opts
[i
], "rw")) || (string_equal(opts
[i
], "ro")) || (string_equal(opts
[i
], "sw")) || (string_equal(opts
[i
], "xx")))
1768 if (which
== SEL_ALL
) match
= 1;
1769 else if ((which
== SEL_NAME
) && (string_equal(name
, tokens
[0]))) match
= 1;
1770 else if ((which
== SEL_NUMBER
) && (string_equal(name
, tokens
[1]))) match
= 1;
1778 item
= (si_item_t
*)LI_ils_create("L4488sssss44", (unsigned long)si
, CATEGORY_FS
, 1, va
, vb
, tokens
[0], tokens
[1], tokens
[2], tokens
[3], (fstype
== NULL
) ? "rw" : fstype
, freq
, passno
);
1788 _fsi_get_device_path(dev_t target_dev
)
1793 char namebuf
[PATH_MAX
];
1797 strlcpy(dev
, _PATH_DEV
, sizeof(dev
));
1799 /* The root device in fstab should always be a block special device */
1800 name
= devname_r(target_dev
, S_IFBLK
, namebuf
, sizeof(namebuf
));
1805 struct dirent
*ent
, entbuf
;
1807 /* No _PATH_DEVDB. We have to search for it the slow way */
1808 dirp
= opendir(_PATH_DEV
);
1809 if (dirp
== NULL
) return NULL
;
1811 while (readdir_r(dirp
, &entbuf
, &ent
) == 0 && ent
!= NULL
)
1813 /* Look for a block special device */
1814 if (ent
->d_type
== DT_BLK
)
1816 strlcat(dev
, ent
->d_name
, sizeof(dev
));
1817 if (stat(dev
, &devst
) == 0)
1819 if (devst
.st_rdev
== target_dev
) {
1820 result
= strdup(dev
);
1826 /* reset dev to _PATH_DEV and try again */
1827 dev
[sizeof(_PATH_DEV
) - 1] = '\0';
1830 if (dirp
) closedir(dirp
);
1834 /* We found the _PATH_DEVDB entry */
1835 strlcat(dev
, name
, sizeof(dev
));
1836 result
= strdup(dev
);
1843 _fsi_fs_root(si_mod_t
*si
)
1845 dispatch_once(&rootfs_once
, ^{
1846 struct stat rootstat
;
1847 struct statfs rootfsinfo
;
1849 const char *root_path
= "/";
1851 if (stat(root_path
, &rootstat
) < 0) return;
1852 if (statfs(root_path
, &rootfsinfo
) < 0) return;
1854 // Check to make sure we're not looking at a synthetic root:
1855 if (string_equal(rootfsinfo
.f_fstypename
, "synthfs")) {
1856 root_path
= "/root";
1857 if (stat(root_path
, &rootstat
) < 0) return;
1858 if (statfs(root_path
, &rootfsinfo
) < 0) return;
1861 root_spec
= _fsi_get_device_path(rootstat
.st_dev
);
1863 rootfs
= (si_item_t
*)LI_ils_create("L4488sssss44", (unsigned long)si
, CATEGORY_FS
, 1, 0LL, 0LL, root_spec
, root_path
, rootfsinfo
.f_fstypename
, FSTAB_RW
, FSTAB_RW
, 0, 1);
1866 return si_item_retain(rootfs
);
1870 _fsi_get_fs(si_mod_t
*si
, const char *name
, int which
)
1877 int synthesize_root
;
1880 if ((which
!= SEL_ALL
) && (name
== NULL
)) return NULL
;
1885 synthesize_root
= 1;
1887 synthesize_root
= 0;
1890 f
= fopen(_PATH_FSTAB
, "r");
1891 if ((f
== NULL
) || (synthesize_root
== 1))
1893 item
= _fsi_fs_root(si
);
1896 if (item
!= NULL
) rfs
= (struct fstab
*)((uintptr_t)item
+ sizeof(si_item_t
));
1902 if ((rfs
!= NULL
) && (string_equal(name
, rfs
->fs_spec
)))
1904 if (f
!= NULL
) fclose(f
);
1913 if ((rfs
!= NULL
) && (string_equal(name
, rfs
->fs_file
)))
1915 if (f
!= NULL
) fclose(f
);
1924 all
= si_list_add(all
, item
);
1925 si_item_release(item
);
1931 if (f
== NULL
) return all
;
1933 _fsi_get_validation(si
, VALIDATION_FSTAB
, _PATH_FSTAB
, f
, &va
, &vb
);
1937 line
= _fsi_get_line(f
);
1938 if (line
== NULL
) break;
1947 item
= _fsi_parse_fs(si
, name
, which
, line
, va
, vb
);
1951 if (item
== NULL
) continue;
1953 if (which
== SEL_ALL
)
1955 all
= si_list_add(all
, item
);
1956 si_item_release(item
);
1969 file_is_valid(si_mod_t
*si
, si_item_t
*item
)
1973 if (si
== NULL
) return 0;
1974 if (item
== NULL
) return 0;
1975 if (si
->name
== NULL
) return 0;
1976 if (item
->src
== NULL
) return 0;
1978 src
= (si_mod_t
*)item
->src
;
1980 if (src
->name
== NULL
) return 0;
1981 if (string_not_equal(si
->name
, src
->name
)) return 0;
1983 if (item
== rootfs
) return 1;
1985 return _fsi_validate(si
, item
->type
, item
->validation_a
, item
->validation_b
);
1989 file_user_byname(si_mod_t
*si
, const char *name
)
1991 return _fsi_get_user(si
, name
, 0, SEL_NAME
);
1995 file_user_byuid(si_mod_t
*si
, uid_t uid
)
1997 return _fsi_get_user(si
, NULL
, uid
, SEL_NUMBER
);
2001 file_user_all(si_mod_t
*si
)
2003 return _fsi_get_user(si
, NULL
, 0, SEL_ALL
);
2007 file_group_byname(si_mod_t
*si
, const char *name
)
2009 return _fsi_get_group(si
, name
, 0, SEL_NAME
);
2013 file_group_bygid(si_mod_t
*si
, gid_t gid
)
2015 return _fsi_get_group(si
, NULL
, gid
, SEL_NUMBER
);
2019 file_group_all(si_mod_t
*si
)
2021 return _fsi_get_group(si
, NULL
, 0, SEL_ALL
);
2025 file_grouplist(si_mod_t
*si
, const char *name
, __unused
uint32_t ignored
)
2027 return _fsi_get_grouplist(si
, name
);
2031 file_netgroup_byname(si_mod_t
*si
, const char *name
)
2033 si_list_t
*list
= NULL
;
2035 uint64_t va
=0, vb
=0;
2037 file_si_private_t
*pp
;
2039 if (name
== NULL
) return NULL
;
2041 pp
= (file_si_private_t
*)si
->private;
2042 if (pp
== NULL
) return NULL
;
2044 _fsi_check_netgroup_cache(si
);
2046 pthread_mutex_lock(&file_mutex
);
2048 n
= _fsi_find_netgroup(&(pp
->file_netgroup_cache
), name
, 0);
2051 file_netgroup_member_t
*m
= n
->members
;
2054 item
= (si_item_t
*)LI_ils_create("L4488sss", (unsigned long)si
, CATEGORY_NETGROUP
, 1, va
, vb
, m
->host
, m
->user
, m
->domain
);
2055 list
= si_list_add(list
, item
);
2060 pthread_mutex_unlock(&file_mutex
);
2066 file_in_netgroup(si_mod_t
*si
, const char *group
, const char *host
, const char *user
, const char *domain
)
2069 file_netgroup_member_t
*m
;
2070 file_si_private_t
*pp
;
2072 if (group
== NULL
) return 0;
2074 pp
= (file_si_private_t
*)si
->private;
2075 if (pp
== NULL
) return 0;
2077 _fsi_check_netgroup_cache(si
);
2079 pthread_mutex_lock(&file_mutex
);
2081 n
= _fsi_find_netgroup(&(pp
->file_netgroup_cache
), group
, 0);
2084 pthread_mutex_unlock(&file_mutex
);
2091 file_netgroup_member_t
*x
= m
;
2096 if (x
->host
== NULL
) continue;
2097 if (strcmp(host
, x
->host
)) continue;
2102 if (x
->user
== NULL
) continue;
2103 if (strcmp(user
, x
->user
)) continue;
2108 if (x
->domain
== NULL
) continue;
2109 if (strcmp(domain
, x
->domain
)) continue;
2112 pthread_mutex_unlock(&file_mutex
);
2116 pthread_mutex_unlock(&file_mutex
);
2121 file_host_byname(si_mod_t
*si
, const char *name
, int af
, const char *ignored
, uint32_t *err
)
2125 if (err
!= NULL
) *err
= SI_STATUS_NO_ERROR
;
2127 item
= _fsi_get_host(si
, name
, NULL
, af
, SEL_NAME
, err
);
2128 if ((item
== NULL
) && (err
!= NULL
) && (*err
== 0)) *err
= SI_STATUS_H_ERRNO_HOST_NOT_FOUND
;
2134 file_host_byaddr(si_mod_t
*si
, const void *addr
, int af
, const char *ignored
, uint32_t *err
)
2138 if (err
!= NULL
) *err
= SI_STATUS_NO_ERROR
;
2140 item
= _fsi_get_host(si
, NULL
, addr
, af
, SEL_NUMBER
, err
);
2141 if ((item
== NULL
) && (err
!= NULL
) && (*err
== 0)) *err
= SI_STATUS_H_ERRNO_HOST_NOT_FOUND
;
2147 file_host_all(si_mod_t
*si
)
2149 return _fsi_get_host(si
, NULL
, NULL
, 0, SEL_ALL
, NULL
);
2153 file_network_byname(si_mod_t
*si
, const char *name
)
2155 if (name
== NULL
) return NULL
;
2156 return _fsi_get_name_number_aliases(si
, name
, 0, SEL_NAME
, CATEGORY_NETWORK
);
2160 file_network_byaddr(si_mod_t
*si
, uint32_t addr
)
2162 return _fsi_get_name_number_aliases(si
, NULL
, (int)addr
, SEL_NUMBER
, CATEGORY_NETWORK
);
2166 file_network_all(si_mod_t
*si
)
2168 return _fsi_get_name_number_aliases(si
, NULL
, 0, SEL_ALL
, CATEGORY_NETWORK
);
2172 file_service_byname(si_mod_t
*si
, const char *name
, const char *proto
)
2174 return _fsi_get_service(si
, name
, proto
, 0, SEL_NAME
);
2178 file_service_byport(si_mod_t
*si
, int port
, const char *proto
)
2180 return _fsi_get_service(si
, NULL
, proto
, port
, SEL_NUMBER
);
2184 file_service_all(si_mod_t
*si
)
2186 return _fsi_get_service(si
, NULL
, NULL
, 0, SEL_ALL
);
2190 file_protocol_byname(si_mod_t
*si
, const char *name
)
2192 if (name
== NULL
) return NULL
;
2193 return _fsi_get_name_number_aliases(si
, name
, 0, SEL_NAME
, CATEGORY_PROTOCOL
);
2197 file_protocol_bynumber(si_mod_t
*si
, int number
)
2199 return _fsi_get_name_number_aliases(si
, NULL
, number
, SEL_NUMBER
, CATEGORY_PROTOCOL
);
2203 file_protocol_all(si_mod_t
*si
)
2205 return _fsi_get_name_number_aliases(si
, NULL
, 0, SEL_ALL
, CATEGORY_PROTOCOL
);
2209 file_rpc_byname(si_mod_t
*si
, const char *name
)
2211 if (name
== NULL
) return NULL
;
2212 return _fsi_get_name_number_aliases(si
, name
, 0, SEL_NAME
, CATEGORY_RPC
);
2216 file_rpc_bynumber(si_mod_t
*si
, int number
)
2218 return _fsi_get_name_number_aliases(si
, NULL
, number
, SEL_NUMBER
, CATEGORY_RPC
);
2222 file_rpc_all(si_mod_t
*si
)
2224 return _fsi_get_name_number_aliases(si
, NULL
, 0, SEL_ALL
, CATEGORY_RPC
);
2228 file_fs_byspec(si_mod_t
*si
, const char *spec
)
2230 return _fsi_get_fs(si
, spec
, SEL_NAME
);
2234 file_fs_byfile(si_mod_t
*si
, const char *file
)
2236 return _fsi_get_fs(si
, file
, SEL_NUMBER
);
2240 file_fs_all(si_mod_t
*si
)
2242 return _fsi_get_fs(si
, NULL
, SEL_ALL
);
2246 file_alias_byname(si_mod_t
*si
, const char *name
)
2248 return _fsi_get_alias(si
, name
, SEL_NAME
);
2252 file_alias_all(si_mod_t
*si
)
2254 return _fsi_get_alias(si
, NULL
, SEL_ALL
);
2258 file_mac_byname(si_mod_t
*si
, const char *name
)
2260 return _fsi_get_ether(si
, name
, SEL_NAME
);
2264 file_mac_bymac(si_mod_t
*si
, const char *mac
)
2266 return _fsi_get_ether(si
, mac
, SEL_NUMBER
);
2270 file_mac_all(si_mod_t
*si
)
2272 return _fsi_get_ether(si
, NULL
, SEL_ALL
);
2276 file_addrinfo(si_mod_t
*si
, const void *node
, const void *serv
, uint32_t family
, uint32_t socktype
, uint32_t proto
, uint32_t flags
, const char *interface
, uint32_t *err
)
2278 if (err
!= NULL
) *err
= SI_STATUS_NO_ERROR
;
2279 return _gai_simple(si
, node
, serv
, family
, socktype
, proto
, flags
, interface
, err
);
2283 si_module_static_file(void)
2285 static const struct si_mod_vtable_s file_vtable
=
2287 .sim_is_valid
= &file_is_valid
,
2289 .sim_user_byname
= &file_user_byname
,
2290 .sim_user_byuid
= &file_user_byuid
,
2291 .sim_user_byuuid
= NULL
,
2292 .sim_user_all
= &file_user_all
,
2294 .sim_group_byname
= &file_group_byname
,
2295 .sim_group_bygid
= &file_group_bygid
,
2296 .sim_group_byuuid
= NULL
,
2297 .sim_group_all
= &file_group_all
,
2299 .sim_grouplist
= &file_grouplist
,
2301 .sim_netgroup_byname
= &file_netgroup_byname
,
2302 .sim_in_netgroup
= &file_in_netgroup
,
2304 .sim_alias_byname
= &file_alias_byname
,
2305 .sim_alias_all
= &file_alias_all
,
2307 .sim_host_byname
= &file_host_byname
,
2308 .sim_host_byaddr
= &file_host_byaddr
,
2309 .sim_host_all
= &file_host_all
,
2311 .sim_network_byname
= &file_network_byname
,
2312 .sim_network_byaddr
= &file_network_byaddr
,
2313 .sim_network_all
= &file_network_all
,
2315 .sim_service_byname
= &file_service_byname
,
2316 .sim_service_byport
= &file_service_byport
,
2317 .sim_service_all
= &file_service_all
,
2319 .sim_protocol_byname
= &file_protocol_byname
,
2320 .sim_protocol_bynumber
= &file_protocol_bynumber
,
2321 .sim_protocol_all
= &file_protocol_all
,
2323 .sim_rpc_byname
= &file_rpc_byname
,
2324 .sim_rpc_bynumber
= &file_rpc_bynumber
,
2325 .sim_rpc_all
= &file_rpc_all
,
2327 .sim_fs_byspec
= &file_fs_byspec
,
2328 .sim_fs_byfile
= &file_fs_byfile
,
2329 .sim_fs_all
= &file_fs_all
,
2331 .sim_mac_byname
= &file_mac_byname
,
2332 .sim_mac_bymac
= &file_mac_bymac
,
2333 .sim_mac_all
= &file_mac_all
,
2335 .sim_wants_addrinfo
= NULL
,
2336 .sim_addrinfo
= &file_addrinfo
,
2338 /* no nameinfo support */
2339 .sim_nameinfo
= NULL
,
2342 static si_mod_t si
=
2346 .flags
= SI_MOD_FLAG_STATIC
,
2349 .vtable
= &file_vtable
,
2352 static dispatch_once_t once
;
2354 dispatch_once(&once
, ^{
2355 si
.name
= strdup("file");
2356 file_si_private_t
*pp
= calloc(1, sizeof(file_si_private_t
));
2360 for (i
= 0; i
< VALIDATION_COUNT
; i
++) pp
->notify_token
[i
] = -1;
2362 /* hardwired for now, but we may want to make this configurable someday */
2363 pp
->validation_notify_mask
= VALIDATION_MASK_HOSTS
| VALIDATION_MASK_SERVICES
| VALIDATION_MASK_PROTOCOLS
;
2369 return (si_mod_t
*)&si
;