home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / programs / internet / tcp / clients / rcp.lha / rcp / src / util.c < prev   
Encoding:
C/C++ Source or Header  |  1994-11-10  |  3.9 KB  |  166 lines

  1.  
  2. /*-
  3.  * Copyright (c) 1992, 1993
  4.  *  The Regents of the University of California.  All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms, with or without
  7.  * modification, are permitted provided that the following conditions
  8.  * are met:
  9.  * 1. Redistributions of source code must retain the above copyright
  10.  *    notice, this list of conditions and the following disclaimer.
  11.  * 2. Redistributions in binary form must reproduce the above copyright
  12.  *    notice, this list of conditions and the following disclaimer in the
  13.  *    documentation and/or other materials provided with the distribution.
  14.  * 3. All advertising materials mentioning features or use of this software
  15.  *    must display the following acknowledgement:
  16.  *  This product includes software developed by the University of
  17.  *  California, Berkeley and its contributors.
  18.  * 4. Neither the name of the University nor the names of its contributors
  19.  *    may be used to endorse or promote products derived from this software
  20.  *    without specific prior written permission.
  21.  *
  22.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32.  * SUCH DAMAGE.
  33.  *
  34.  *  $Id: util.c,v 1.2 1994/09/24 02:56:57 davidg Exp $
  35.  */
  36.  
  37. #ifndef lint
  38. static char sccsid[] = "@(#)util.c  8.2 (Berkeley) 4/2/94";
  39.  
  40. #endif /* not lint */
  41.  
  42. #include <sys/param.h>
  43. #include <sys/stat.h>
  44. #include <dos.h>                 /* mheinz */
  45.  
  46. #include <ctype.h>
  47. #include "err.h"
  48. #include <errno.h>
  49. #include "pathnames.h"
  50. #include <signal.h>
  51. #include <stdio.h>
  52. #include <stdlib.h>
  53. #include <string.h>
  54. #include <unistd.h>
  55.  
  56. #include "extern.h"
  57.  
  58. char *
  59. colon(cp)
  60.      char *cp;
  61. {
  62.     static char separator[2]="";
  63.  
  64.     if (separator[0]=='\0') {
  65.         if (GetVar("RCPSEPARATOR",separator,2,NULL)<=0)
  66.             strcpy(separator,"!");
  67.     }
  68.  
  69.     if (*cp == separator[0])
  70.         /* Leading colon is part of file name. */
  71.         return (0);
  72.  
  73.     for (; *cp; ++cp) {
  74.     if (*cp == separator[0])
  75.         return (cp);
  76.     if (*cp == '/')
  77.         return (0);
  78.     }
  79.     return (0);
  80. }
  81.  
  82. void
  83. verifydir(cp)
  84.      char *cp;
  85. {
  86.     struct stat stb;
  87.  
  88.     if (!stat(cp, &stb)) {
  89.     if (S_ISDIR(stb.st_mode))
  90.         return;
  91.     errno = ENOTDIR;
  92.     }
  93.     run_err("%s: %s", cp, strerror(errno));
  94.     exit(1);
  95. }
  96.  
  97. int
  98. okname(cp0)
  99.      char *cp0;
  100. {
  101.     int c;
  102.     char *cp;
  103.  
  104.     cp = cp0;
  105.     do {
  106.     c = *cp;
  107.     if (c & 0200)
  108.         goto bad;
  109.     if (!isalpha(c) && !isdigit(c) && c != '_' && c != '-')
  110.         goto bad;
  111.     } while (*++cp);
  112.     return (1);
  113.  
  114.   bad:warn("%s: invalid user name", cp0);
  115.     return (0);
  116. }
  117.  
  118. int
  119. susystem(s, userid)
  120.      int userid;
  121.      char *s;
  122. {
  123.     int error;
  124.  
  125.     error = system(s);
  126.     if (error)
  127.     err(stderr,"System Failed: %s\n", s);
  128.  
  129.     return error;
  130. }
  131.  
  132. BUF *
  133. allocbuf(bp, fd, blksize)
  134.      BUF *bp;
  135.      int fd, blksize;
  136. {
  137.     struct stat stb;
  138.     size_t size;
  139.  
  140.     if (fstat(fd, &stb) < 0) {
  141.     run_err("fstat: %s", strerror(errno));
  142.     return (0);
  143.     }
  144.     size = roundup(stb.st_blksize, blksize);
  145.     if (size == 0)
  146.     size = blksize;
  147.     if (bp->cnt >= size)
  148.     return (bp);
  149.     if ((bp->buf = realloc(bp->buf, size)) == NULL) {
  150.     bp->cnt = 0;
  151.     run_err("%s", strerror(errno));
  152.     return (0);
  153.     }
  154.     bp->cnt = size;
  155.     return (bp);
  156. }
  157.  
  158. void
  159. lostconn(signo)
  160.      int signo;
  161. {
  162.     if (!iamremote)
  163.     err(stderr,"lost connection\n");
  164.     exit(1);
  165. }
  166.