From: downsj Date: Sun, 26 Jan 1997 10:33:22 +0000 (+0000) Subject: Support lchown(). X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5962f7325a3755f5d455fd00305976bd17cac793;p=openbsd Support lchown(). --- 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,10 +478,18 @@ 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 @@ -762,6 +769,31 @@ set_ids(fnm, uid, gid) return(0); } +/* + * 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