From 386fc7d4c764912447906324b77d83223052ac9e Mon Sep 17 00:00:00 2001 From: ben Date: Sat, 10 Aug 2002 00:43:04 +0000 Subject: Fixed bad high bit permissions mode in cmodule.c, and assorted changes to make --windows-mode work. git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@180 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109 --- rdiff-backup/rdiff_backup/FilenameMapping.py | 4 +-- rdiff-backup/rdiff_backup/SetConnections.py | 9 ++++++- rdiff-backup/rdiff_backup/cmodule.c | 2 +- rdiff-backup/rdiff_backup/librsync.py | 39 +++++++++++++++++++++++++++- rdiff-backup/rdiff_backup/rpath.py | 3 ++- rdiff-backup/rdiff_backup/selection.py | 1 + rdiff-backup/src/FilenameMapping.py | 4 +-- rdiff-backup/src/SetConnections.py | 9 ++++++- rdiff-backup/src/cmodule.c | 2 +- rdiff-backup/src/librsync.py | 39 +++++++++++++++++++++++++++- rdiff-backup/src/rpath.py | 3 ++- rdiff-backup/src/selection.py | 1 + 12 files changed, 104 insertions(+), 12 deletions(-) diff --git a/rdiff-backup/rdiff_backup/FilenameMapping.py b/rdiff-backup/rdiff_backup/FilenameMapping.py index fda203e..76cb273 100644 --- a/rdiff-backup/rdiff_backup/FilenameMapping.py +++ b/rdiff-backup/rdiff_backup/FilenameMapping.py @@ -19,9 +19,9 @@ them over the usual 255 character limit. import re from log import * +from robust import * import Globals - max_filename_length = 255 # If true, enable character quoting, and set characters making @@ -43,7 +43,7 @@ def set_init_quote_vals(): def set_init_quote_vals_local(): """Set value on local connection, initialize regexps""" - global chars_to_quote + global chars_to_quote, quoting_char chars_to_quote = Globals.chars_to_quote if len(Globals.quoting_char) != 1: Log.FatalError("Expected single character for quoting char," diff --git a/rdiff-backup/rdiff_backup/SetConnections.py b/rdiff-backup/rdiff_backup/SetConnections.py index 8d763a1..073c652 100644 --- a/rdiff-backup/rdiff_backup/SetConnections.py +++ b/rdiff-backup/rdiff_backup/SetConnections.py @@ -163,6 +163,7 @@ def init_connection_settings(conn): conn.Log.setterm_verbosity(Log.term_verbosity) for setting_name in Globals.changed_settings: conn.Globals.set(setting_name, Globals.get(setting_name)) + FilenameMapping.set_init_quote_vals() def init_connection_remote(conn_number): """Run on server side to tell self that have given conn_number""" @@ -187,6 +188,11 @@ def BackupInitConnections(reading_conn, writing_conn): writing_conn.Globals.set("isbackup_writer", 1) UpdateGlobal("backup_reader", reading_conn) UpdateGlobal("backup_writer", writing_conn) + if (Globals.change_source_perms and + reading_conn.Globals.get("process_uid") == 0): + Log("Warning: --change_source_perms should usually not be used when\n" + "the reading connection is running as root, because root can\n" + "read all files regardless of their permissions.", 2) def CloseConnections(): """Close all connections. Run by client""" @@ -224,4 +230,5 @@ Remote version: %s""" % (Globals.version, version) from log import * from rpath import * from connection import * -import Globals +import Globals, FilenameMapping + diff --git a/rdiff-backup/rdiff_backup/cmodule.c b/rdiff-backup/rdiff_backup/cmodule.c index 6a55ab4..9d8c62b 100644 --- a/rdiff-backup/rdiff_backup/cmodule.c +++ b/rdiff-backup/rdiff_backup/cmodule.c @@ -53,7 +53,7 @@ static PyObject *c_make_file_dict(self, args) inode = PyInt_FromLong((long)sbuf.st_ino); #endif mode = (long)sbuf.st_mode; - perms = mode & (S_IRWXU | S_IRWXG | S_IRWXO); + perms = mode & 07777; #if defined(HAVE_LONG_LONG) && !defined(MS_WINDOWS) devloc = PyLong_FromLongLong((LONG_LONG)sbuf.st_dev); #else diff --git a/rdiff-backup/rdiff_backup/librsync.py b/rdiff-backup/rdiff_backup/librsync.py index 8535532..207d6a9 100644 --- a/rdiff-backup/rdiff_backup/librsync.py +++ b/rdiff-backup/rdiff_backup/librsync.py @@ -110,7 +110,6 @@ class SigFile(LikeFile): try: self.maker = _librsync.new_sigmaker() except _librsync.librsyncError, e: raise librsyncError(str(e)) - class DeltaFile(LikeFile): """File-like object which incrementally generates a librsync delta""" def __init__(self, signature, new_file): @@ -147,3 +146,41 @@ class PatchedFile(LikeFile): try: self.maker = _librsync.new_patchmaker(basis_file) except _librsync.librsyncError, e: raise librsyncError(str(e)) + +class SigGenerator: + """Calculate signature. + + Input and output is same as SigFile, but the interface is like md5 + module, not filelike object + + """ + def __init__(self): + """Return new signature instance""" + try: self.sig_maker = _librsync.new_sigmaker() + except _librsync.librsyncError, e: raise librsyncError(str(e)) + self.gotsig = None + self.buffer = "" + self.sig_string = "" + + def update(self, buf): + """Add buf to data that signature will be calculated over""" + if self.gotsig: + raise librsyncError("SigGenerator already provided signature") + self.buffer += buf + while len(self.buffer) >= blocksize: + if self.process_buffer(): + raise librsyncError("Premature EOF received from sig_maker") + + def process_buffer(self): + """Run self.buffer through sig_maker, add to self.sig_string""" + try: eof, len_buf_read, cycle_out = self.sig_maker.cycle(self.buffer) + except _librsync.librsyncError, e: raise librsyncError(str(e)) + self.buffer = self.buffer[len_buf_read:] + self.sig_string += cycle_out + return eof + + def getsig(self): + """Return signature over given data""" + while not self.process_buffer(): pass # keep running until eof + return self.sig_string + diff --git a/rdiff-backup/rdiff_backup/rpath.py b/rdiff-backup/rdiff_backup/rpath.py index bfe613d..4fffcfb 100644 --- a/rdiff-backup/rdiff_backup/rpath.py +++ b/rdiff-backup/rdiff_backup/rpath.py @@ -803,12 +803,13 @@ class RPathFileHook: self.closing_thunk() return result + # Import these late to avoid circular dependencies +import FilenameMapping from lazy import * from selection import * from destructive_stepping import * - class RpathDeleter(ITRBranch): """Delete a directory. Called by RPath.delete()""" def start_process(self, index, dsrp): diff --git a/rdiff-backup/rdiff_backup/selection.py b/rdiff-backup/rdiff_backup/selection.py index c70857c..20a7fa3 100644 --- a/rdiff-backup/rdiff_backup/selection.py +++ b/rdiff-backup/rdiff_backup/selection.py @@ -20,6 +20,7 @@ import re from log import * from robust import * from destructive_stepping import * +import FilenameMapping class SelectError(Exception): diff --git a/rdiff-backup/src/FilenameMapping.py b/rdiff-backup/src/FilenameMapping.py index fda203e..76cb273 100644 --- a/rdiff-backup/src/FilenameMapping.py +++ b/rdiff-backup/src/FilenameMapping.py @@ -19,9 +19,9 @@ them over the usual 255 character limit. import re from log import * +from robust import * import Globals - max_filename_length = 255 # If true, enable character quoting, and set characters making @@ -43,7 +43,7 @@ def set_init_quote_vals(): def set_init_quote_vals_local(): """Set value on local connection, initialize regexps""" - global chars_to_quote + global chars_to_quote, quoting_char chars_to_quote = Globals.chars_to_quote if len(Globals.quoting_char) != 1: Log.FatalError("Expected single character for quoting char," diff --git a/rdiff-backup/src/SetConnections.py b/rdiff-backup/src/SetConnections.py index 8d763a1..073c652 100644 --- a/rdiff-backup/src/SetConnections.py +++ b/rdiff-backup/src/SetConnections.py @@ -163,6 +163,7 @@ def init_connection_settings(conn): conn.Log.setterm_verbosity(Log.term_verbosity) for setting_name in Globals.changed_settings: conn.Globals.set(setting_name, Globals.get(setting_name)) + FilenameMapping.set_init_quote_vals() def init_connection_remote(conn_number): """Run on server side to tell self that have given conn_number""" @@ -187,6 +188,11 @@ def BackupInitConnections(reading_conn, writing_conn): writing_conn.Globals.set("isbackup_writer", 1) UpdateGlobal("backup_reader", reading_conn) UpdateGlobal("backup_writer", writing_conn) + if (Globals.change_source_perms and + reading_conn.Globals.get("process_uid") == 0): + Log("Warning: --change_source_perms should usually not be used when\n" + "the reading connection is running as root, because root can\n" + "read all files regardless of their permissions.", 2) def CloseConnections(): """Close all connections. Run by client""" @@ -224,4 +230,5 @@ Remote version: %s""" % (Globals.version, version) from log import * from rpath import * from connection import * -import Globals +import Globals, FilenameMapping + diff --git a/rdiff-backup/src/cmodule.c b/rdiff-backup/src/cmodule.c index 6a55ab4..9d8c62b 100644 --- a/rdiff-backup/src/cmodule.c +++ b/rdiff-backup/src/cmodule.c @@ -53,7 +53,7 @@ static PyObject *c_make_file_dict(self, args) inode = PyInt_FromLong((long)sbuf.st_ino); #endif mode = (long)sbuf.st_mode; - perms = mode & (S_IRWXU | S_IRWXG | S_IRWXO); + perms = mode & 07777; #if defined(HAVE_LONG_LONG) && !defined(MS_WINDOWS) devloc = PyLong_FromLongLong((LONG_LONG)sbuf.st_dev); #else diff --git a/rdiff-backup/src/librsync.py b/rdiff-backup/src/librsync.py index 8535532..207d6a9 100644 --- a/rdiff-backup/src/librsync.py +++ b/rdiff-backup/src/librsync.py @@ -110,7 +110,6 @@ class SigFile(LikeFile): try: self.maker = _librsync.new_sigmaker() except _librsync.librsyncError, e: raise librsyncError(str(e)) - class DeltaFile(LikeFile): """File-like object which incrementally generates a librsync delta""" def __init__(self, signature, new_file): @@ -147,3 +146,41 @@ class PatchedFile(LikeFile): try: self.maker = _librsync.new_patchmaker(basis_file) except _librsync.librsyncError, e: raise librsyncError(str(e)) + +class SigGenerator: + """Calculate signature. + + Input and output is same as SigFile, but the interface is like md5 + module, not filelike object + + """ + def __init__(self): + """Return new signature instance""" + try: self.sig_maker = _librsync.new_sigmaker() + except _librsync.librsyncError, e: raise librsyncError(str(e)) + self.gotsig = None + self.buffer = "" + self.sig_string = "" + + def update(self, buf): + """Add buf to data that signature will be calculated over""" + if self.gotsig: + raise librsyncError("SigGenerator already provided signature") + self.buffer += buf + while len(self.buffer) >= blocksize: + if self.process_buffer(): + raise librsyncError("Premature EOF received from sig_maker") + + def process_buffer(self): + """Run self.buffer through sig_maker, add to self.sig_string""" + try: eof, len_buf_read, cycle_out = self.sig_maker.cycle(self.buffer) + except _librsync.librsyncError, e: raise librsyncError(str(e)) + self.buffer = self.buffer[len_buf_read:] + self.sig_string += cycle_out + return eof + + def getsig(self): + """Return signature over given data""" + while not self.process_buffer(): pass # keep running until eof + return self.sig_string + diff --git a/rdiff-backup/src/rpath.py b/rdiff-backup/src/rpath.py index bfe613d..4fffcfb 100644 --- a/rdiff-backup/src/rpath.py +++ b/rdiff-backup/src/rpath.py @@ -803,12 +803,13 @@ class RPathFileHook: self.closing_thunk() return result + # Import these late to avoid circular dependencies +import FilenameMapping from lazy import * from selection import * from destructive_stepping import * - class RpathDeleter(ITRBranch): """Delete a directory. Called by RPath.delete()""" def start_process(self, index, dsrp): diff --git a/rdiff-backup/src/selection.py b/rdiff-backup/src/selection.py index c70857c..20a7fa3 100644 --- a/rdiff-backup/src/selection.py +++ b/rdiff-backup/src/selection.py @@ -20,6 +20,7 @@ import re from log import * from robust import * from destructive_stepping import * +import FilenameMapping class SelectError(Exception): -- cgit v1.2.1