summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Downs <downsj@cvs.openbsd.org>1997-01-26 10:33:23 +0000
committerJason Downs <downsj@cvs.openbsd.org>1997-01-26 10:33:23 +0000
commit548397e999c318d25451bd1d3b09d6d897a620a7 (patch)
treec1e6b80d60238e393464727878d68938834ea4e1
parent0ea14c2e3bd21f4ba08bbb149521968398fe5b99 (diff)
Support lchown().
-rw-r--r--bin/pax/extern.h3
-rw-r--r--bin/pax/file_subs.c42
2 files changed, 39 insertions, 6 deletions
diff --git a/bin/pax/extern.h b/bin/pax/extern.h
index 1a00cf3f953..c417a13827c 100644
--- a/bin/pax/extern.h
+++ b/bin/pax/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.8 1997/01/24 19:41:20 millert Exp $ */
+/* $OpenBSD: extern.h,v 1.9 1997/01/26 10:33:22 downsj Exp $ */
/* $NetBSD: extern.h,v 1.5 1996/03/26 23:54:16 mrg Exp $ */
/*-
@@ -148,6 +148,7 @@ int unlnk_exist __P((register char *, register int));
int chk_path __P((register char *, uid_t, gid_t));
void set_ftime __P((char *fnm, time_t mtime, time_t atime, int frc));
int set_ids __P((char *, uid_t, gid_t));
+int set_lids __P((char *, uid_t, gid_t));
void set_pmode __P((char *, mode_t));
int file_write __P((int, char *, register int, int *, int *, int, char *));
void file_flush __P((int, char *, int));
diff --git a/bin/pax/file_subs.c b/bin/pax/file_subs.c
index b5451991f6d..6b9e80607d8 100644
--- a/bin/pax/file_subs.c
+++ b/bin/pax/file_subs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file_subs.c,v 1.3 1996/06/23 14:20:33 deraadt Exp $ */
+/* $OpenBSD: file_subs.c,v 1.4 1997/01/26 10:33:22 downsj Exp $ */
/* $NetBSD: file_subs.c,v 1.4 1995/03/21 09:07:18 cgd Exp $ */
/*-
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)file_subs.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: file_subs.c,v 1.3 1996/06/23 14:20:33 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: file_subs.c,v 1.4 1997/01/26 10:33:22 downsj Exp $";
#endif
#endif /* not lint */
@@ -435,8 +435,7 @@ node_creat(arcn)
arcn->name);
return(-1);
case PAX_SLK:
- if ((res = symlink(arcn->ln_name, arcn->name)) == 0)
- return(0);
+ res = symlink(arcn->ln_name, arcn->name);
break;
case PAX_CTG:
case PAX_HLK:
@@ -479,11 +478,19 @@ node_creat(arcn)
* we were able to create the node. set uid/gid, modes and times
*/
if (pids)
- res = set_ids(arcn->name, arcn->sb.st_uid, arcn->sb.st_gid);
+ res = ((arcn->type == PAX_SLK) ?
+ set_lids(arcn->name, arcn->sb.st_uid, arcn->sb.st_gid) :
+ set_ids(arcn->name, arcn->sb.st_uid, arcn->sb.st_gid));
else
res = 0;
/*
+ * symlinks are done now.
+ */
+ if (arcn->type == PAX_SLK)
+ return(0);
+
+ /*
* IMPORTANT SECURITY NOTE:
* if not preserving mode or we cannot set uid/gid, then PROHIBIT any
* set uid/gid bits
@@ -763,6 +770,31 @@ set_ids(fnm, uid, gid)
}
/*
+ * set_lids()
+ * set the uid and gid of a file system node
+ * Return:
+ * 0 when set, -1 on failure
+ */
+
+#if __STDC__
+int
+set_lids(char *fnm, uid_t uid, gid_t gid)
+#else
+int
+set_lids(fnm, uid, gid)
+ char *fnm;
+ uid_t uid;
+ gid_t gid;
+#endif
+{
+ if (lchown(fnm, uid, gid) < 0) {
+ syswarn(1, errno, "Unable to set file uid/gid of %s", fnm);
+ return(-1);
+ }
+ return(0);
+}
+
+/*
* set_pmode()
* Set file access mode
*/