const char * getsfssockdir (void) { static char *sockdir; char *runinplace; char *paths[] = { ETCDIR "/sfs_config", DATADIR "/sfs_config", NULL }; char **p; FILE *f = NULL; if (sockdir) return sockdir; #ifdef MAINTAINER if ((runinplace = getenv ("SFS_RUNINPLACE"))) { char suff[] = "/runinplace"; if (!suidsafe ()) { setgid (getgid ()); setuid (getuid ()); } sockdir = malloc (strlen (runinplace) + sizeof (suff)); if (!sockdir) { fprintf (stderr, "out of memory\n"); exit (1); } sprintf (sockdir, "%s%s", runinplace, suff); return sockdir; } #endif /* MAINTAINER */ for (p = paths; *p && !(f = fopen (*p, "r")); p++) ; if (f) { char *s, *t, buf[2048]; while ((s = fgets (buf, sizeof (buf), f))) { if (strlen (buf) >= sizeof (buf) - 1) break; t = strnnsep (&s, " \r\n"); if (strcasecmp (t, "sfsdir")) continue; t = strnnsep (&s, " \r\n"); if (t && *t == '/') { sockdir = malloc (strlen (t) + sizeof ("/sockets")); if (!sockdir) { fprintf (stderr, "out of memory\n"); exit (1); } sprintf (sockdir, "%s/sockets", t); break; } } fclose (f); } if (!sockdir) sockdir = SFSDIR "/sockets"; return sockdir; }
void sfs_hosttab_t::loadfd (int fd) { suio uio; int lineno = 0; sfs_sa sa; bzero (&sa, sizeof (sa)); sa.sa_in.sin_family = AF_INET; for (;;) { lineno++; size_t n; while (!(n = uio.linelen ())) if (uio.input (fd) <= 0) { if (uio.resid ()) errmsg (lineno, "incomplete last line"); return; } mstr m (n); uio.copyout (m, n - 1); m[n-1] = '\0'; uio.rembytes (n); if (m[0] == '#' || m[0] == '\n') continue; char *p = m; char *host = strnnsep (&p, " \t\r\n"); char *port = host; xstrsep (&port, "%"); if (inet_aton (host, &sa.sa_in.sin_addr) <= 0) { errmsg (lineno, "invalid IP address"); continue; } if (!port || !*port) sa.sa_in.sin_port = htons (SFS_PORT); else if (convertint (port, &sa.sa_in.sin_port)) sa.sa_in.sin_port = htons (sa.sa_in.sin_port); else { errmsg (lineno, "invalid port number"); continue; } while ((host = strnnsep (&p, " \t\r\n"))) { str h (mytolower (host)); if (sfs_host *hp = tab[h]) delete hp; tab.insert (New sfs_host (h, sa, sizeof (sa.sa_in))); } } }
static void do_host(char *host) { char *name = strnnsep(&host, " \t\n"); int j; if (name == NULL) return; for (j = KT_RSA1; j <= KT_ED25519; j *= 2) { if (get_keytypes & j) { while (ncon >= MAXCON) conloop(); conalloc(name, *host ? host : name, j); } } }