2 * Routines to parse an inetd.conf or tlid.conf file. This would be a great
3 * job for a PERL script.
5 * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
22 * Network configuration files may live in unusual places. Here are some
23 * guesses. Shorter names follow longer ones.
25 char *inet_files[] = {
26 "/private/etc/inetd.conf", /* NEXT */
27 "/etc/inet/inetd.conf", /* SYSV4 */
28 "/usr/etc/inetd.conf", /* IRIX?? */
29 "/etc/inetd.conf", /* BSD */
30 "/etc/net/tlid.conf", /* SYSV4?? */
31 "/etc/saf/tlid.conf", /* SYSV4?? */
32 "/etc/tlid.conf", /* SYSV4?? */
36 static void inet_chk();
37 static char *base_name();
40 * Structure with everything we know about a service.
43 struct inet_ent *next;
48 static struct inet_ent *inet_list = 0;
50 static char whitespace[] = " \t\r\n";
52 /* inet_conf - read in and examine inetd.conf (or tlid.conf) entries */
65 struct tcpd_context saved_context;
70 saved_context = tcpd_context;
73 * The inetd.conf (or tlid.conf) information is so useful that we insist
74 * on its availability. When no file is given run a series of educated
78 if ((fp = fopen(conf, "r")) == 0) {
79 fprintf(stderr, percent_m(buf, "open %s: %m\n"), conf);
83 for (i = 0; inet_files[i] && (fp = fopen(inet_files[i], "r")) == 0; i++)
86 fprintf(stderr, "Cannot find your inetd.conf or tlid.conf file.\n");
87 fprintf(stderr, "Please specify its location.\n");
91 check_path(conf, &st);
95 * Process the file. After the 7.0 wrapper release it became clear that
96 * there are many more inetd.conf formats than the 8 systems that I had
97 * studied. EP/IX uses a two-line specification for rpc services; HP-UX
98 * permits long lines to be broken with backslash-newline.
100 tcpd_context.file = conf;
101 tcpd_context.line = 0;
102 while (xgets(buf, sizeof(buf), fp)) {
103 service = strtok(buf, whitespace); /* service */
104 if (service == 0 || *service == '#')
106 if (STR_NE(service, "stream") && STR_NE(service, "dgram"))
107 strtok((char *) 0, whitespace); /* endpoint */
108 protocol = strtok((char *) 0, whitespace);
109 (void) strtok((char *) 0, whitespace); /* wait */
110 if ((user = strtok((char *) 0, whitespace)) == 0)
112 if (user[0] == '/') { /* user */
115 if ((path = strtok((char *) 0, whitespace)) == 0)
118 if (path[0] == '?') /* IRIX optional service */
120 if (STR_EQ(path, "internal"))
122 if (path[strspn(path, "-0123456789")] == 0) {
125 * ConvexOS puts RPC version numbers before path names. Jukka
126 * Ukkonen <ukkonen@csc.fi>.
128 if ((path = strtok((char *) 0, whitespace)) == 0)
131 if ((arg0 = strtok((char *) 0, whitespace)) == 0) {
132 tcpd_warn("incomplete line");
135 if (arg0[strspn(arg0, "0123456789")] == 0) {
138 * We're reading a tlid.conf file, the format is:
140 * ...stuff... path arg_count arguments mod_count modules
142 if ((arg0 = strtok((char *) 0, whitespace)) == 0) {
143 tcpd_warn("incomplete line");
147 if ((arg1 = strtok((char *) 0, whitespace)) == 0)
150 inet_chk(protocol, path, arg0, arg1);
153 tcpd_context = saved_context;
157 /* inet_chk - examine one inetd.conf (tlid.conf?) entry */
159 static void inet_chk(protocol, path, arg0, arg1)
167 int wrap_status = WR_MAYBE;
168 char *base_name_path = base_name(path);
169 char *tcpd_proc_name = (arg0[0] == '/' ? base_name(arg0) : arg0);
172 * Always warn when the executable does not exist or when it is not
175 if (check_path(path, &st) < 0) {
176 tcpd_warn("%s: not found: %m", path);
177 } else if ((st.st_mode & 0100) == 0) {
178 tcpd_warn("%s: not executable", path);
182 * Cheat on the miscd tests, nobody uses it anymore.
184 if (STR_EQ(base_name_path, "miscd")) {
185 inet_set(arg0, WR_YES);
190 * While we are here...
192 if (STR_EQ(tcpd_proc_name, "rexd") || STR_EQ(tcpd_proc_name, "rpc.rexd"))
193 tcpd_warn("%s may be an insecure service", tcpd_proc_name);
196 * The tcpd program gets most of the attention.
198 if (STR_EQ(base_name_path, "tcpd")) {
200 if (STR_EQ(tcpd_proc_name, "tcpd"))
201 tcpd_warn("%s is recursively calling itself", tcpd_proc_name);
203 wrap_status = WR_YES;
206 * Check: some sites install the wrapper set-uid.
208 if ((st.st_mode & 06000) != 0)
209 tcpd_warn("%s: file is set-uid or set-gid", path);
212 * Check: some sites insert tcpd in inetd.conf, instead of replacing
213 * the daemon pathname.
215 if (arg0[0] == '/' && STR_EQ(tcpd_proc_name, base_name(arg1)))
216 tcpd_warn("%s inserted before %s", path, arg0);
219 * Check: make sure files exist and are executable. On some systems
220 * the network daemons are set-uid so we cannot complain. Note that
221 * tcpd takes the basename only in case of absolute pathnames.
223 if (arg0[0] == '/') { /* absolute path */
224 if (check_path(arg0, &st) < 0) {
225 tcpd_warn("%s: not found: %m", arg0);
226 } else if ((st.st_mode & 0100) == 0) {
227 tcpd_warn("%s: not executable", arg0);
229 } else { /* look in REAL_DAEMON_DIR */
230 sprintf(daemon, "%s/%s", REAL_DAEMON_DIR, arg0);
231 if (check_path(daemon, &st) < 0) {
232 tcpd_warn("%s: not found in %s: %m",
233 arg0, REAL_DAEMON_DIR);
234 } else if ((st.st_mode & 0100) == 0) {
235 tcpd_warn("%s: not executable", daemon);
242 * No tcpd program found. Perhaps they used the "simple installation"
243 * recipe. Look for a file with the same basename in REAL_DAEMON_DIR.
244 * Draw some conservative conclusions when a distinct file is found.
246 sprintf(daemon, "%s/%s", REAL_DAEMON_DIR, arg0);
247 if (STR_EQ(path, daemon)) {
249 wrap_status = WR_MAYBE;
251 wrap_status = WR_NOT;
253 } else if (check_path(daemon, &st) >= 0) {
254 wrap_status = WR_MAYBE;
255 } else if (errno == ENOENT) {
256 wrap_status = WR_NOT;
258 tcpd_warn("%s: file lookup: %m", daemon);
259 wrap_status = WR_MAYBE;
264 * Alas, we cannot wrap rpc/tcp services.
266 if (wrap_status == WR_YES && STR_EQ(protocol, "rpc/tcp"))
267 tcpd_warn("%s: cannot wrap rpc/tcp services", tcpd_proc_name);
269 inet_set(tcpd_proc_name, wrap_status);
272 /* inet_set - remember service status */
274 void inet_set(name, type)
278 struct inet_ent *ip =
279 (struct inet_ent *) malloc(sizeof(struct inet_ent) + strlen(name));
282 fprintf(stderr, "out of memory\n");
285 ip->next = inet_list;
286 strcpy(ip->name, name);
291 /* inet_get - look up service status */
301 for (ip = inet_list; ip; ip = ip->next)
302 if (STR_EQ(ip->name, name))
308 /* base_name - compute last pathname component */
310 static char *base_name(path)
315 if ((cp = strrchr(path, '/')) != 0)