3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "configuration.h"
24 #include "interface.h"
26 #include <lib_internal/util.h>
27 #include <ensc_vector/vector.h>
28 #include <lib/internal.h>
34 getSingleInterface(struct Interface *res,
35 struct Interface const *tmpl,
36 PathInfo const *basedir, char const *d_entry)
38 PathInfo ent = { .d = d_entry, .l = strlen(d_entry) };
39 PathInfo path = *basedir;
40 char path_buf[ENSC_PI_APPSZ(path, ent)];
42 PathInfo_append(&path, &ent, path_buf);
43 if (!utilvserver_isDirectory(path.d, true))
44 return true; // skip non-directories
46 return Iface_read(res, &path, tmpl);
50 getInterfaces(struct Configuration *cfg)
52 ENSC_PI_DECLARE(iface_subdir, "interfaces");
53 PathInfo ifacepath = cfg->cfgdir;
54 char path_buf[ENSC_PI_APPSZ(ifacepath, iface_subdir)];
55 struct Interface iface_default;
59 PathInfo_append(&ifacepath, &iface_subdir, path_buf);
61 if (!utilvserver_isDirectory(ifacepath.d, true))
62 return true; // no interface configuration -> ok
64 Iface_init(&iface_default);
65 if (!Iface_read(&iface_default, &ifacepath, 0))
68 // iterate through dir-entries...
69 dir = opendir(ifacepath.d);
71 struct dirent *ent = readdir(dir);
72 struct Interface iface;
75 if (isDotfile(ent->d_name)) continue; // skip dot-files
78 if (!getSingleInterface(&iface, &iface_default, &ifacepath, ent->d_name))
80 else if (iface.addr.ipv4.ip!=0) { // HACK: non-directory entries would return true also
81 struct Interface *new_iface = Vector_pushback(&cfg->interfaces);
93 initVdir(char const **vdir, PathInfo const *cfgdir)
95 *vdir = vc_getVserverVdir(cfgdir->d, vcCFG_RECENT_FULL, true);
97 WRITE_MSG(2, "Can not find root-directory of the vserver");
105 getConfiguration(struct Configuration *cfg, PathInfo const *cfgdir)
107 cfg->cfgdir = *cfgdir;
109 return (initVdir(&cfg->vdir, cfgdir) &&