|
|
1.1 ! root 1: /* locfil.c ! 2: Expand a file name on the local system. ! 3: ! 4: Copyright (C) 1991, 1992 Ian Lance Taylor ! 5: ! 6: This file is part of the Taylor UUCP package. ! 7: ! 8: This program is free software; you can redistribute it and/or ! 9: modify it under the terms of the GNU General Public License as ! 10: published by the Free Software Foundation; either version 2 of the ! 11: License, or (at your option) any later version. ! 12: ! 13: This program is distributed in the hope that it will be useful, but ! 14: WITHOUT ANY WARRANTY; without even the implied warranty of ! 15: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ! 16: General Public License for more details. ! 17: ! 18: You should have received a copy of the GNU General Public License ! 19: along with this program; if not, write to the Free Software ! 20: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ! 21: ! 22: The author of the program may be contacted at [email protected] or ! 23: c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254. ! 24: */ ! 25: ! 26: #include "uucp.h" ! 27: ! 28: #include "uudefs.h" ! 29: #include "sysdep.h" ! 30: #include "system.h" ! 31: ! 32: #include <pwd.h> ! 33: ! 34: #if GETPWNAM_DECLARATION_OK ! 35: #ifndef getpwnam ! 36: extern struct passwd *getpwnam (); ! 37: #endif ! 38: #endif ! 39: ! 40: /* Turn a file name into an absolute path, by doing tilde expansion ! 41: and moving any other type of file into the public directory. */ ! 42: ! 43: char * ! 44: zsysdep_local_file (zfile, zpubdir) ! 45: const char *zfile; ! 46: const char *zpubdir; ! 47: { ! 48: const char *zdir; ! 49: ! 50: if (*zfile == '/') ! 51: return zbufcpy (zfile); ! 52: ! 53: if (*zfile != '~') ! 54: zdir = zpubdir; ! 55: else ! 56: { ! 57: if (zfile[1] == '\0') ! 58: return zbufcpy (zpubdir); ! 59: ! 60: if (zfile[1] == '/') ! 61: { ! 62: zdir = zpubdir; ! 63: zfile += 2; ! 64: } ! 65: else ! 66: { ! 67: size_t cuserlen; ! 68: char *zcopy; ! 69: struct passwd *q; ! 70: ! 71: ++zfile; ! 72: cuserlen = strcspn ((char *) zfile, "/"); ! 73: zcopy = zbufalc (cuserlen + 1); ! 74: memcpy (zcopy, zfile, cuserlen); ! 75: zcopy[cuserlen] = '\0'; ! 76: ! 77: q = getpwnam (zcopy); ! 78: if (q == NULL) ! 79: { ! 80: ulog (LOG_ERROR, "User %s not found", zcopy); ! 81: ubuffree (zcopy); ! 82: return NULL; ! 83: } ! 84: ubuffree (zcopy); ! 85: ! 86: if (zfile[cuserlen] == '\0') ! 87: return zbufcpy (q->pw_dir); ! 88: ! 89: zdir = q->pw_dir; ! 90: zfile += cuserlen + 1; ! 91: } ! 92: } ! 93: ! 94: return zsysdep_in_dir (zdir, zfile); ! 95: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.