* libmisc/copydir.c, src/usermod.c, lib/prototypes.h: The uid and

gid parameters can be set to -1 to indicate that the original
  owners must be kept. Change the types from uid_t/gid_t to a
  long int (signed).
* libmisc/copydir.c: Change the copy_entry(), copy_dir(),
  copy_symlink(), copy_special(), and copy_file() prototypes
  accordingly.
* lib/prototypes.h: Add the parameters' name for the
  libmisc/copydir.c functions.
This commit is contained in:
nekral-guest 2008-01-01 14:31:00 +00:00
parent bb8af02978
commit b681e50ff2
4 changed files with 37 additions and 23 deletions

View File

@ -1,3 +1,15 @@
2008-01-01 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/copydir.c, src/usermod.c, lib/prototypes.h: The uid and
gid parameters can be set to -1 to indicate that the original
owners must be kept. Change the types from uid_t/gid_t to a
long int (signed).
* libmisc/copydir.c: Change the copy_entry(), copy_dir(),
copy_symlink(), copy_special(), and copy_file() prototypes
accordingly.
* lib/prototypes.h: Add the parameters' name for the
libmisc/copydir.c functions.
2008-01-01 Nicolas François <nicolas.francois@centraliens.net> 2008-01-01 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/limits.c, libmisc/obscure.c, src/login_nopam.c, * libmisc/limits.c, libmisc/obscure.c, src/login_nopam.c,

View File

@ -51,8 +51,9 @@ extern int console (const char *);
extern int is_listed (const char *, const char *, int); extern int is_listed (const char *, const char *, int);
/* copydir.c */ /* copydir.c */
extern int copy_tree (const char *, const char *, uid_t, gid_t); extern int copy_tree (const char *src_root, const char *dst_root,
extern int remove_tree (const char *); long int uid, long int gid);
extern int remove_tree (const char *root);
/* encrypt.c */ /* encrypt.c */
extern char *pw_encrypt (const char *, const char *); extern char *pw_encrypt (const char *, const char *);

View File

@ -55,23 +55,23 @@ struct link_name {
static struct link_name *links; static struct link_name *links;
static int copy_entry (const char *src, const char *dst, static int copy_entry (const char *src, const char *dst,
uid_t uid, gid_t gid); long int uid, long int gid);
static int copy_dir (const char *src, const char *dst, static int copy_dir (const char *src, const char *dst,
const struct stat *statp, const struct timeval mt[2], const struct stat *statp, const struct timeval mt[2],
uid_t uid, gid_t gid); long int uid, long int gid);
#ifdef S_IFLNK #ifdef S_IFLNK
static int copy_symlink (const char *src, const char *dst, static int copy_symlink (const char *src, const char *dst,
const struct stat *statp, const struct timeval mt[2], const struct stat *statp, const struct timeval mt[2],
uid_t uid, gid_t gid); long int uid, long int gid);
#endif #endif
static int copy_hardlink (const char *src, const char *dst, static int copy_hardlink (const char *src, const char *dst,
struct link_name *lp); struct link_name *lp);
static int copy_special (const char *src, const char *dst, static int copy_special (const char *src, const char *dst,
const struct stat *statp, const struct timeval mt[2], const struct stat *statp, const struct timeval mt[2],
uid_t uid, gid_t gid); long int uid, long int gid);
static int copy_file (const char *src, const char *dst, static int copy_file (const char *src, const char *dst,
const struct stat *statp, const struct timeval mt[2], const struct stat *statp, const struct timeval mt[2],
uid_t uid, gid_t gid); long int uid, long int gid);
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
/* /*
@ -180,7 +180,8 @@ static struct link_name *check_link (const char *name, const struct stat *sb)
* copy_tree() walks a directory tree and copies ordinary files * copy_tree() walks a directory tree and copies ordinary files
* as it goes. * as it goes.
*/ */
int copy_tree (const char *src_root, const char *dst_root, uid_t uid, gid_t gid) int copy_tree (const char *src_root, const char *dst_root,
long int uid, long int gid)
{ {
char src_name[1024]; char src_name[1024];
char dst_name[1024]; char dst_name[1024];
@ -271,7 +272,7 @@ int copy_tree (const char *src_root, const char *dst_root, uid_t uid, gid_t gid)
* not be modified. * not be modified.
*/ */
static int copy_entry (const char *src, const char *dst, static int copy_entry (const char *src, const char *dst,
uid_t uid, gid_t gid) long int uid, long int gid)
{ {
int err = 0; int err = 0;
struct stat sb; struct stat sb;
@ -350,7 +351,7 @@ static int copy_entry (const char *src, const char *dst,
*/ */
static int copy_dir (const char *src, const char *dst, static int copy_dir (const char *src, const char *dst,
const struct stat *statp, const struct timeval mt[2], const struct stat *statp, const struct timeval mt[2],
uid_t uid, gid_t gid) long int uid, long int gid)
{ {
int err = 0; int err = 0;
@ -364,8 +365,8 @@ static int copy_dir (const char *src, const char *dst,
#endif #endif
if ( (mkdir (dst, statp->st_mode) != 0) if ( (mkdir (dst, statp->st_mode) != 0)
|| (chown (dst, || (chown (dst,
(uid == (uid_t) - 1) ? statp->st_uid : uid, (uid == - 1) ? statp->st_uid : (uid_t) uid,
(gid == (gid_t) - 1) ? statp->st_gid : gid) != 0) (gid == - 1) ? statp->st_gid : (gid_t) gid) != 0)
|| (chmod (dst, statp->st_mode) != 0) || (chmod (dst, statp->st_mode) != 0)
|| (copy_tree (src, dst, uid, gid) != 0) || (copy_tree (src, dst, uid, gid) != 0)
|| (utimes (dst, mt) != 0)) { || (utimes (dst, mt) != 0)) {
@ -388,7 +389,7 @@ static int copy_dir (const char *src, const char *dst,
*/ */
static int copy_symlink (const char *src, const char *dst, static int copy_symlink (const char *src, const char *dst,
const struct stat *statp, const struct timeval mt[2], const struct stat *statp, const struct timeval mt[2],
uid_t uid, gid_t gid) long int uid, long int gid)
{ {
char oldlink[1024]; char oldlink[1024];
char dummy[1024]; char dummy[1024];
@ -419,8 +420,8 @@ static int copy_symlink (const char *src, const char *dst,
#endif #endif
if ( (symlink (oldlink, dst) != 0) if ( (symlink (oldlink, dst) != 0)
|| (lchown (dst, || (lchown (dst,
(uid == (uid_t) - 1) ? statp->st_uid : uid, (uid == -1) ? statp->st_uid : (uid_t) uid,
(gid == (gid_t) - 1) ? statp->st_gid : gid) != 0)) { (gid == -1) ? statp->st_gid : (gid_t) gid) != 0)) {
return -1; return -1;
} }
@ -476,7 +477,7 @@ static int copy_hardlink (const char *src, const char *dst,
*/ */
static int copy_special (const char *src, const char *dst, static int copy_special (const char *src, const char *dst,
const struct stat *statp, const struct timeval mt[2], const struct stat *statp, const struct timeval mt[2],
uid_t uid, gid_t gid) long int uid, long int gid)
{ {
int err = 0; int err = 0;
@ -486,8 +487,8 @@ static int copy_special (const char *src, const char *dst,
if ( (mknod (dst, statp->st_mode & ~07777, statp->st_rdev) != 0) if ( (mknod (dst, statp->st_mode & ~07777, statp->st_rdev) != 0)
|| (chown (dst, || (chown (dst,
(uid == (uid_t) - 1) ? statp->st_uid : uid, (uid == -1) ? statp->st_uid : (uid_t) uid,
(gid == (gid_t) - 1) ? statp->st_gid : gid) != 0) (gid == -1) ? statp->st_gid : (gid_t) gid) != 0)
|| (chmod (dst, statp->st_mode & 07777) != 0) || (chmod (dst, statp->st_mode & 07777) != 0)
|| (utimes (dst, mt) != 0)) { || (utimes (dst, mt) != 0)) {
err = -1; err = -1;
@ -508,7 +509,7 @@ static int copy_special (const char *src, const char *dst,
*/ */
static int copy_file (const char *src, const char *dst, static int copy_file (const char *src, const char *dst,
const struct stat *statp, const struct timeval mt[2], const struct stat *statp, const struct timeval mt[2],
uid_t uid, gid_t gid) long int uid, long int gid)
{ {
int err = 0; int err = 0;
int ifd; int ifd;
@ -526,8 +527,8 @@ static int copy_file (const char *src, const char *dst,
ofd = open (dst, O_WRONLY | O_CREAT | O_TRUNC, 0); ofd = open (dst, O_WRONLY | O_CREAT | O_TRUNC, 0);
if ( (ofd < 0) if ( (ofd < 0)
|| (chown (dst, || (chown (dst,
(uid == (uid_t) - 1) ? statp->st_uid : uid, (uid == -1) ? statp->st_uid : (uid_t) uid,
(gid == (gid_t) - 1) ? statp->st_gid : gid) != 0) (gid == -1) ? statp->st_gid : (gid_t) gid) != 0)
|| (chmod (dst, statp->st_mode & 07777) != 0)) { || (chmod (dst, statp->st_mode & 07777) != 0)) {
close (ifd); close (ifd);
return -1; return -1;

View File

@ -1328,8 +1328,8 @@ static void move_home (void)
fail_exit (E_HOMEDIR); fail_exit (E_HOMEDIR);
} }
if (copy_tree (user_home, user_newhome, if (copy_tree (user_home, user_newhome,
uflg ? user_newid : -1, uflg ? (long int)user_newid : -1,
gflg ? user_newgid : -1) == 0) { gflg ? (long int)user_newgid : -1) == 0) {
if (remove_tree (user_home) != 0 || if (remove_tree (user_home) != 0 ||
rmdir (user_home) != 0) rmdir (user_home) != 0)
fprintf (stderr, fprintf (stderr,