diff -x rmt-command.h -x aclocal.m4 -x config.h.in -x configure -x Makefile.in -ur cpio-2.9.old/configure.ac cpio-2.9/configure.ac --- cpio-2.9.old/configure.ac 2007-06-29 12:14:40.000000000 +0200 +++ cpio-2.9/configure.ac 2007-09-23 12:27:30.000000000 +0200 @@ -45,7 +45,7 @@ AC_HEADER_STDC AC_HEADER_DIRENT -AC_CHECK_FUNCS([fchmod fchown]) +AC_CHECK_FUNCS([fchmod fchown chown link symlink getuid geteuid mknod makedev pipe]) # gnulib modules gl_INIT @@ -61,7 +61,7 @@ no) ;; esac]) -AC_CHECK_HEADERS(unistd.h stdlib.h string.h fcntl.h sys/io/trioctl.h utmp.h getopt.h locale.h libintl.h sys/wait.h utime.h locale.h) +AC_CHECK_HEADERS(unistd.h stdlib.h string.h fcntl.h sys/io/trioctl.h utmp.h getopt.h locale.h libintl.h sys/wait.h utime.h locale.h process.h pwd.h grp.h sys/ioctl.h) AC_MSG_CHECKING(for sys_errlist and sys_nerr) AC_TRY_RUN( diff -x rmt-command.h -x aclocal.m4 -x config.h.in -x configure -x Makefile.in -ur cpio-2.9.old/lib/chown.c cpio-2.9/lib/chown.c --- cpio-2.9.old/lib/chown.c 2007-03-21 07:55:17.000000000 +0100 +++ cpio-2.9/lib/chown.c 2007-09-23 12:23:34.000000000 +0200 @@ -30,6 +30,8 @@ #include #include +#include "system.h" /* unimplemented_stub */ + /* Below we refer to the system's chown(). */ #undef chown @@ -47,6 +49,9 @@ int rpl_chown (const char *file, uid_t uid, gid_t gid) { +#ifndef HAVE_CHOWN + return unimplemented_stub (); +#else #if CHOWN_FAILS_TO_HONOR_ID_OF_NEGATIVE_ONE if (gid == (gid_t) -1 || uid == (uid_t) -1) { @@ -101,4 +106,5 @@ #endif return chown (file, uid, gid); +#endif } diff -x rmt-command.h -x aclocal.m4 -x config.h.in -x configure -x Makefile.in -ur cpio-2.9.old/lib/rtapelib.c cpio-2.9/lib/rtapelib.c --- cpio-2.9.old/lib/rtapelib.c 2007-06-27 15:49:45.000000000 +0200 +++ cpio-2.9/lib/rtapelib.c 2007-09-23 12:24:25.000000000 +0200 @@ -118,6 +118,9 @@ static int do_command (int handle, const char *buffer) { +#ifndef HAVE_PIPE + return unimplemented_stub (); +#else /* Save the current pipe handler and try to make the request. */ size_t length = strlen (buffer); @@ -132,6 +135,7 @@ _rmt_shutdown (handle, EIO); return -1; +#endif } static char * @@ -361,6 +365,9 @@ rmt_open__ (const char *file_name, int open_mode, int bias, const char *remote_shell) { +#ifndef HAVE_PIPE + return unimplemented_stub (); +#else int remote_pipe_number; /* pseudo, biased file descriptor */ char *file_name_copy; /* copy of file_name string */ char *remote_host; /* remote host name */ @@ -541,6 +548,7 @@ free (file_name_copy); return remote_pipe_number + bias; +#endif } /* Close remote tape connection HANDLE and shut down. Return 0 if @@ -591,6 +599,9 @@ size_t rmt_write__ (int handle, char *buffer, size_t length) { +#ifndef HAVE_PIPE + return unimplemented_stub (); +#else char command_buffer[COMMAND_BUFFER_SIZE]; RETSIGTYPE (*pipe_handler) (); size_t written; @@ -616,6 +627,7 @@ _rmt_shutdown (handle, EIO); return written; +#endif } /* Perform an imitation lseek operation on remote tape connection diff -x rmt-command.h -x aclocal.m4 -x config.h.in -x configure -x Makefile.in -ur cpio-2.9.old/lib/system.h cpio-2.9/lib/system.h --- cpio-2.9.old/lib/system.h 2007-06-27 15:49:45.000000000 +0200 +++ cpio-2.9/lib/system.h 2007-09-23 12:11:36.000000000 +0200 @@ -453,16 +453,26 @@ #define _(msgid) gettext (msgid) #define N_(msgid) msgid -#if MSDOS +/* msdos (and win32?) */ +#ifdef HAVE_PROCESS_H # include +#endif + +/* Everyone else */ +#ifdef HAVE_PWD_H +# include +#endif +#ifdef HAVE_GRP_H +# include +#endif + +#if MSDOS # define SET_BINARY_MODE(arc) setmode(arc, O_BINARY) # define ERRNO_IS_EACCES errno == EACCES # define mkdir(file, mode) (mkdir) (file) # define TTY_NAME "con" # define sys_reset_uid_gid() #else -# include -# include # define SET_BINARY_MODE(arc) # define ERRNO_IS_EACCES 0 # define TTY_NAME "/dev/tty" @@ -470,6 +480,21 @@ do { setuid (getuid ()); setgid (getgid ()); } while (0) #endif +static inline int +unimplemented_stub () +{ + errno = ENOSYS; + return -1; +} + +#if !defined(HAVE_SYMLINK) +# define UMASKED_SYMLINK(name1,name2,mode) unimplemented_stub() +#elif defined(SYMLINK_USES_UMASK) +# define UMASKED_SYMLINK(name1,name2,mode) symlink(name1,name2) +#else +# define UMASKED_SYMLINK(name1,name2,mode) umasked_symlink(name1,name2,mode) +#endif /* SYMLINK_USES_UMASK */ + #if XENIX # include #endif diff -x rmt-command.h -x aclocal.m4 -x config.h.in -x configure -x Makefile.in -ur cpio-2.9.old/src/copyin.c cpio-2.9/src/copyin.c --- cpio-2.9.old/src/copyin.c 2007-06-28 12:51:09.000000000 +0200 +++ cpio-2.9/src/copyin.c 2007-09-23 12:13:24.000000000 +0200 @@ -651,6 +651,9 @@ static void copyin_device (struct cpio_file_stat* file_hdr) { +#if !defined(HAVE_MKNOD) || !defined(HAVE_MAKEDEV) + return; +#else int res; /* Result of various function calls. */ if (to_stdout_option) @@ -719,6 +722,7 @@ if (retain_time_flag) set_file_times (-1, file_hdr->c_name, file_hdr->c_mtime, file_hdr->c_mtime); +#endif } static void diff -x rmt-command.h -x aclocal.m4 -x config.h.in -x configure -x Makefile.in -ur cpio-2.9.old/src/copypass.c cpio-2.9/src/copypass.c --- cpio-2.9.old/src/copypass.c 2007-06-28 14:10:01.000000000 +0200 +++ cpio-2.9/src/copypass.c 2007-09-23 12:25:02.000000000 +0200 @@ -276,6 +276,11 @@ #endif 0) { +#ifndef HAVE_MKNOD + errno = ENOSYS; + mknod_error (output_name.ds_string); + continue; +#else /* Can the current file be linked to a another file? Set link_name to the original file name. */ if (link_flag) @@ -305,6 +310,7 @@ } set_copypass_perms (-1, output_name.ds_string, &in_file_stat); } +#endif } #ifdef S_ISLNK @@ -416,6 +422,9 @@ int link_to_name (char *link_name, char *link_target) { +#ifndef HAVE_LINK + return unimplemented_stub (); +#else int res = link (link_target, link_name); if (res < 0 && create_dir_flag) { @@ -434,4 +443,5 @@ link_target, link_name); } return res; +#endif } diff -x rmt-command.h -x aclocal.m4 -x config.h.in -x configure -x Makefile.in -ur cpio-2.9.old/src/extern.h cpio-2.9/src/extern.h --- cpio-2.9.old/src/extern.h 2007-06-28 14:59:38.000000000 +0200 +++ cpio-2.9/src/extern.h 2007-09-23 12:09:42.000000000 +0200 @@ -186,13 +186,6 @@ int out_des, off_t num_bytes)); #define DISK_IO_BLOCK_SIZE 512 -/* FIXME: Move to system.h? */ -#ifndef SYMLINK_USES_UMASK -# define UMASKED_SYMLINK(name1,name2,mode) symlink(name1,name2) -#else -# define UMASKED_SYMLINK(name1,name2,mode) umasked_symlink(name1,name2,mode) -#endif /* SYMLINK_USES_UMASK */ - void set_perms (int fd, struct cpio_file_stat *header); void set_file_times (int fd, const char *name, unsigned long atime, unsigned long mtime); diff -x rmt-command.h -x aclocal.m4 -x config.h.in -x configure -x Makefile.in -ur cpio-2.9.old/src/idcache.c cpio-2.9/src/idcache.c --- cpio-2.9.old/src/idcache.c 2007-06-28 12:45:35.000000000 +0200 +++ cpio-2.9/src/idcache.c 2007-09-23 10:52:14.000000000 +0200 @@ -23,10 +23,15 @@ #include #include -#include -#include #include +#ifdef HAVE_PWD_H +# include +#endif +#ifdef HAVE_GRP_H +# include +#endif + #if defined(STDC_HEADERS) || defined(HAVE_STRING_H) #include #else @@ -65,16 +70,20 @@ if (tail->id.u == uid) return tail->name; - pwent = getpwuid (uid); tail = (struct userid *) xmalloc (sizeof (struct userid)); tail->id.u = uid; +#ifdef HAVE_PWD_H + pwent = getpwuid (uid); if (pwent == 0) { +#endif sprintf (usernum_string, "%u", (unsigned) uid); tail->name = xstrdup (usernum_string); +#ifdef HAVE_PWD_H } else tail->name = xstrdup (pwent->pw_name); +#endif /* Add to the head of the list, so most recently used is first. */ tail->next = user_alist; @@ -103,11 +112,12 @@ if (*tail->name == *user && !strcmp (tail->name, user)) return 0; - pwent = getpwnam (user); - tail = (struct userid *) xmalloc (sizeof (struct userid)); tail->name = xstrdup (user); +#ifdef HAVE_PWD_H + pwent = getpwnam (user); + /* Add to the head of the list, so most recently used is first. */ if (pwent) { @@ -116,6 +126,7 @@ user_alist = tail; return &tail->id.u; } +#endif tail->next = nouser_alist; nouser_alist = tail; @@ -140,16 +151,21 @@ if (tail->id.g == gid) return tail->name; - grent = getgrgid (gid); tail = (struct userid *) xmalloc (sizeof (struct userid)); tail->id.g = gid; + +#ifdef HAVE_GRP_H + grent = getgrgid (gid); if (grent == 0) { +#endif sprintf (groupnum_string, "%u", (unsigned int) gid); tail->name = xstrdup (groupnum_string); +#ifdef HAVE_GRP_H } else tail->name = xstrdup (grent->gr_name); +#endif /* Add to the head of the list, so most recently used is first. */ tail->next = group_alist; @@ -178,11 +194,12 @@ if (*tail->name == *group && !strcmp (tail->name, group)) return 0; - grent = getgrnam (group); - tail = (struct userid *) xmalloc (sizeof (struct userid)); tail->name = xstrdup (group); +#ifdef HAVE_GRP_H + grent = getgrnam (group); + /* Add to the head of the list, so most recently used is first. */ if (grent) { @@ -191,6 +208,7 @@ group_alist = tail; return &tail->id.g; } +#endif tail->next = nogroup_alist; nogroup_alist = tail; diff -x rmt-command.h -x aclocal.m4 -x config.h.in -x configure -x Makefile.in -ur cpio-2.9.old/src/main.c cpio-2.9/src/main.c --- cpio-2.9.old/src/main.c 2007-06-28 12:46:41.000000000 +0200 +++ cpio-2.9/src/main.c 2007-09-23 12:27:23.000000000 +0200 @@ -727,11 +727,13 @@ quotearg_colon (archive_name)); } +#ifdef HAVE_GETEUID /* Prevent SysV non-root users from giving away files inadvertantly. This happens automatically on BSD, where only root can give away files. */ if (set_owner_flag == false && set_group_flag == false && geteuid ()) no_chown_flag = true; +#endif } /* Initialize the input and output buffers to their proper size and diff -x rmt-command.h -x aclocal.m4 -x config.h.in -x configure -x Makefile.in -ur cpio-2.9.old/src/makepath.c cpio-2.9/src/makepath.c --- cpio-2.9.old/src/makepath.c 2007-06-28 15:09:47.000000000 +0200 +++ cpio-2.9/src/makepath.c 2007-09-23 12:12:27.000000000 +0200 @@ -58,7 +58,12 @@ int retval = 0; mode_t tmpmode; mode_t invert_permissions; - int we_are_root = getuid () == 0; + int we_are_root = +#ifdef HAVE_GETUID + getuid () == 0; +#else + 1; +#endif dirpath = alloca (strlen (argpath) + 1); strcpy (dirpath, argpath); diff -x rmt-command.h -x aclocal.m4 -x config.h.in -x configure -x Makefile.in -ur cpio-2.9.old/src/userspec.c cpio-2.9/src/userspec.c --- cpio-2.9.old/src/userspec.c 2007-06-27 16:00:13.000000000 +0200 +++ cpio-2.9/src/userspec.c 2007-09-23 10:52:14.000000000 +0200 @@ -38,17 +38,22 @@ #include #include #include -#include -#include -#if !HAVE_DECL_GETPWNAM +#ifdef HAVE_PWD_H +# include +# if !HAVE_DECL_GETPWNAM extern struct passwd *getpwnam (const char *name); +# endif #endif -#if !HAVE_DECL_GETGRNAM + +#ifdef HAVE_GRP_H +# include +# if !HAVE_DECL_GETGRNAM extern struct group *getgrnam (const char *name); -#endif -#if !HAVE_DECL_GETGRGID +# endif +# if !HAVE_DECL_GETGRGID extern struct group *getgrgid (gid_t gid); +# endif #endif #ifndef HAVE_ENDPWENT @@ -134,9 +139,11 @@ if (u != NULL) { +#ifdef HAVE_PWD_H pwd = getpwnam (u); if (pwd == NULL) { +#endif if (!isnumber_p (u)) error_msg = _("invalid user"); @@ -149,6 +156,7 @@ else *uid = atoi (u); } +#ifdef HAVE_PWD_H } else { @@ -175,22 +183,27 @@ endgrent (); } } +#endif endpwent (); } if (g != NULL && error_msg == NULL) { /* Explicit group. */ +#ifdef HAVE_GRP_H grp = getgrnam (g); if (grp == NULL) { +#endif if (!isnumber_p (g)) error_msg = _("invalid group"); else *gid = atoi (g); +#ifdef HAVE_GRP_H } else *gid = grp->gr_gid; +#endif endgrent (); /* Save a file descriptor. */ if (error_msg == NULL) diff -x rmt-command.h -x aclocal.m4 -x config.h.in -x configure -x Makefile.in -ur cpio-2.9.old/src/util.c cpio-2.9/src/util.c --- cpio-2.9.old/src/util.c 2007-06-28 15:04:51.000000000 +0200 +++ cpio-2.9/src/util.c 2007-09-23 10:52:30.000000000 +0200 @@ -33,7 +33,9 @@ #include #include -#include +#ifdef HAVE_SYS_IOCTL_H +# include +#endif #ifdef HAVE_SYS_MTIO_H # ifdef HAVE_SYS_IO_TRIOCTL_H @@ -1266,7 +1268,10 @@ } #ifndef HAVE_FCHOWN -# define fchown(fd, uid, gid) (-1) +# define HAVE_FCHOWN 0 +#endif +#ifndef HAVE_FCHMOD +# define HAVE_FCHMOD 0 #endif int