1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
/* $Id: sfspaths.c,v 1.4 2001/08/20 01:54:50 dm Exp $ */
/*
*
* Copyright (C) 2001 David Mazieres (dm@uun.org)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
*/
#include "sfs-internal.h"
/* This is a strsep function that returns a null field for adjacent
* separators. This is the same as the 4.4BSD strsep, but different
* from the one in the GNU libc. */
char *
xstrsep(char **str, const char *delim)
{
char *s, *e;
if (!**str)
return (NULL);
s = *str;
e = s + strcspn (s, delim);
if (*e != '\0')
*e++ = '\0';
*str = e;
return (s);
}
/* Get the next non-null token (like GNU strsep). Strsep() will
* return a null token for two adjacent separators, so we may have to
* loop. */
char *
strnnsep (char **stringp, const char *delim)
{
char *tok;
do {
tok = xstrsep (stringp, delim);
} while (tok && *tok == '\0');
return (tok);
}
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;
}
|