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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
/* util.c
A couple of UUCP utility functions.
Copyright (C) 1991, 1992, 1993, 2002 Ian Lance Taylor
This file is part of the Taylor UUCP package.
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 of the
License, 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.
The author of the program may be contacted at ian@airs.com.
*/
#include "uucp.h"
#if USE_RCS_ID
const char util_rcsid[] = "$Id: util.c,v 1.11 2002/03/05 19:10:42 ian Rel $";
#endif
#include <ctype.h>
#include "uudefs.h"
#include "uuconf.h"
#include "system.h"
/* Get information for an unknown system. This will leave the name
allocated on the heap. We could fix this by breaking the
abstraction and adding the name to qsys->palloc. It makes sure the
name is not too long, but takes no other useful action. */
boolean
funknown_system (puuconf, zsystem, qsys)
pointer puuconf;
const char *zsystem;
struct uuconf_system *qsys;
{
char *z;
int iuuconf;
if (strlen (zsystem) <= cSysdep_max_name_len)
z = zbufcpy (zsystem);
else
{
char **pznames, **pz;
boolean ffound;
z = zbufalc (cSysdep_max_name_len + 1);
memcpy (z, zsystem, cSysdep_max_name_len);
z[cSysdep_max_name_len] = '\0';
iuuconf = uuconf_system_names (puuconf, &pznames, TRUE);
if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
ffound = FALSE;
for (pz = pznames; *pz != NULL; pz++)
{
if (strcmp (*pz, z) == 0)
ffound = TRUE;
xfree ((pointer) *pz);
}
xfree ((pointer) pznames);
if (ffound)
{
ubuffree (z);
return FALSE;
}
}
iuuconf = uuconf_system_unknown (puuconf, qsys);
if (iuuconf == UUCONF_NOT_FOUND)
{
ubuffree (z);
return FALSE;
}
else if (iuuconf != UUCONF_SUCCESS)
ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
for (; qsys != NULL; qsys = qsys->uuconf_qalternate)
qsys->uuconf_zname = z;
return TRUE;
}
/* Remove all occurrences of the local system name followed by an
exclamation point from the front of a string, returning the new
string. This is used by uucp and uux. */
char *
zremove_local_sys (qlocalsys, z)
struct uuconf_system *qlocalsys;
char *z;
{
size_t clen;
char *zexclam;
clen = strlen (qlocalsys->uuconf_zname);
zexclam = strchr (z, '!');
while (zexclam != NULL)
{
if (z == zexclam
|| ((size_t) (zexclam - z) == clen
&& strncmp (z, qlocalsys->uuconf_zname, clen) == 0))
;
else if (qlocalsys->uuconf_pzalias == NULL)
break;
else
{
char **pzal;
for (pzal = qlocalsys->uuconf_pzalias; *pzal != NULL; pzal++)
if (strlen (*pzal) == (size_t) (zexclam - z)
&& strncmp (z, *pzal, (size_t) (zexclam - z)) == 0)
break;
if (*pzal == NULL)
break;
}
z = zexclam + 1;
zexclam = strchr (z, '!');
}
return z;
}
/* See whether a file is in a directory list, and make sure the user
has appropriate access. */
boolean
fin_directory_list (zfile, pzdirs, zpubdir, fcheck, freadable, zuser)
const char *zfile;
char **pzdirs;
const char *zpubdir;
boolean fcheck;
boolean freadable;
const char *zuser;
{
boolean fmatch;
char **pz;
fmatch = FALSE;
for (pz = pzdirs; *pz != NULL; pz++)
{
char *zuse;
if (pz[0][0] == '!')
{
zuse = zsysdep_local_file (*pz + 1, zpubdir, (boolean *) NULL);
if (zuse == NULL)
return FALSE;
if (fsysdep_in_directory (zfile, zuse, FALSE,
FALSE, (const char *) NULL))
fmatch = FALSE;
}
else
{
zuse = zsysdep_local_file (*pz, zpubdir, (boolean *) NULL);
if (zuse == NULL)
return FALSE;
if (fsysdep_in_directory (zfile, zuse, fcheck,
freadable, zuser))
fmatch = TRUE;
}
ubuffree (zuse);
}
return fmatch;
}
|