summaryrefslogtreecommitdiff
path: root/sysutils/rsnapshot/patches/patch-aa
blob: 8aff79aba77669141c39d1bc064dc4f689c1af11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
$NetBSD: patch-aa,v 1.3 2005/12/27 08:56:47 kim Exp $

--- rsnapshot-program.pl.orig	2005-04-10 01:22:29.000000000 +0300
+++ rsnapshot-program.pl	2005-12-25 11:16:47.000000000 +0200
@@ -32,6 +32,7 @@
 use File::Path;			# mkpath(), rmtree()
 use File::stat;			# stat(), lstat()
 use POSIX qw(locale_h);	# setlocale()
+use Lchown qw(lchown LCHOWN_AVAILABLE);
 
 ########################################
 ###     DECLARE GLOBAL VARIABLES     ###
@@ -3277,24 +3278,9 @@
 	
 	# CHOWN DEST (if root)
 	if (0 == $<) {
-		# make sure destination is not a symlink
-		if ( ! -l "$dest" ) {
-			# print and/or log this if necessary
-			if (($verbose > 4) or ($loglevel > 4)) {
-				my $cmd_string = "chown(" . $st->uid . ", " . $st->gid . ", \"$dest\")";
-			
-				if ($verbose > 4) {
-					print_cmd($cmd_string);
-				} elsif ($loglevel > 4) {
-					log_msg($cmd_string, 4);
-				}
-			}
-			
-			$result = chown($st->uid, $st->gid, "$dest");
-			if (! $result) {
-				print_err("Warning! Could not chown(" . $st->uid . ", " . $st->gid . ", \"$dest\");", 2);
-				return(0);
-			}
+		$result = safe_chown($st->uid, $st->gid, $dest);
+		if (! $result) {
+			return(0);
 		}
 	}
 	
@@ -3501,6 +3487,43 @@
 	return (1);
 }
 
+# choose between lchown or chown
+sub safe_chown {
+	my $uid = shift(@_);
+	my $gid = shift(@_);
+	my $dest = shift(@_);
+
+	my $result = 0;
+
+	# logging
+	if (LCHOWN_AVAILABLE || ! -l $dest) {
+		# print and/or log this if necessary
+		if (($verbose > 4) or ($loglevel > 4)) {
+			my $cmd_string = 'chown(' . $uid . ', ' . $gid . ', "' . $dest . '")';
+			if ($verbose > 4) {
+				print_cmd($cmd_string);
+			} elsif ($loglevel > 4) {
+				log_msg($cmd_string, 4);
+			}
+		}
+	}
+
+	if (LCHOWN_AVAILABLE) {
+		$result = lchown($uid, $gid, $dest);
+	} else {
+		# make sure destination is not a symlink
+		if ( ! -l $dest ) {
+			$result = chown($uid, $gid, $dest);
+		}
+	}
+
+	if (! $result) {
+		print_err('Warning! Could not safe_chown(' . $uid . ', ' . $gid . ', "' . $dest . '")', 2);
+	}
+
+	return($result);
+}
+
 # accepts a path
 # displays the rm command according to the config file
 sub display_rm_rf {
@@ -3777,13 +3800,9 @@
 	
 	# CHOWN DEST (if root)
 	if (0 == $<) {
-		# make sure dest is not a symlink
-		if ( ! -l "$dest" ) {
-			$result = chown($st->uid, $st->gid, "$dest");
-			if (! $result) {
-				print_err("Warning! Could not chown(" . $st->uid . ", " . $st->gid . ", \"$dest\");", 2);
-				return(0);
-			}
+		$result = safe_chown($st->uid, $st->gid, $dest);
+		if (! $result) {
+			return(0);
 		}
 	}
 	
@@ -3998,25 +4017,9 @@
 	# CHOWN DEST (if root)
 	if (0 == $<) {
 		if ( -e "$dest" ) {
-			# make sure destination is not a symlink
-			if ( ! -l "$dest" ) {
-				# print and/or log this if necessary
-				if (($verbose > 4) or ($loglevel > 4)) {
-					my $cmd_string = "chown(" . $st->uid . ", " . $st->gid . ", \"$dest\");";
-				
-					if ($verbose > 4) {
-						print_cmd($cmd_string);
-					} elsif ($loglevel > 4) {
-						log_msg($cmd_string, 4);
-					}
-				}
-				
-				$result = chown($st->uid, $st->gid, "$dest");
-				
-				if (! $result) {
-					print_err("Warning! Could not chown(" . $st->uid . ", " . $st->gid . ", \"$dest\")", 2);
-					return (0);
-				}
+			$result = safe_chown($st->uid, $st->gid, $dest);
+			if (! $result) {
+				return (0);
 			}
 		}
 	}