On Wed, 23 Jan 2008, Robert Hardy wrote:
We have recently discovered an incompatibility exists between rssh and rsync
protocol 30 (i.e. the protocol used in rsync versions later than 2.6.9.)
Can someone help fix rssh?
Please find attached and included below a patch that fixes rssh
compatibility with rsync protocol 30. This works for me and should be
backwards compatible. It assumes the Posix regex libraries are present.
Regards,
Rob
--
---------------------"Happiness is understanding."----------------------
Robert Hardy, B.Eng Computer Systems C.E.O. Webcon Inc.
rhardy <at> webcon <dot> ca GPG Key available
diff -urNp rssh-2.3.2-dist/util.h rssh-2.3.2/util.h
--- rssh-2.3.2-dist/util.h 2006-01-03 12:37:55.000000000 -0500
+++ rssh-2.3.2/util.h 2008-01-23 17:01:43.000000000 -0500
@@ -40,5 +40,6 @@ int validate_access( const char *temp, b
bool *allow_cvs, bool *allow_rdist, bool *allow_rsync );
bool opt_exist( char *cl, char opt );
char *get_username( void );
+int regexmatch(const char *string, char *pattern);
#endif /* _util_h */
diff -urNp rssh-2.3.2-dist/util.c rssh-2.3.2/util.c
--- rssh-2.3.2-dist/util.c 2006-01-03 12:37:39.000000000 -0500
+++ rssh-2.3.2/util.c 2008-01-23 17:58:51.000000000 -0500
@@ -56,6 +56,7 @@
#ifdef HAVE_LIBGEN_H
#include <libgen.h>
#endif /* HAVE_LIBGEN_H */
+#include <regex.h>
/* LOCAL INCLUDES */
#include "pathnames.h"
@@ -134,7 +135,7 @@ bool opt_exist(char *cl, char opt)
{
int i = 0;
int len;
- char *token;
+// char *token;
bool optstring = FALSE;
@@ -187,6 +188,31 @@ bool check_command( char *cl, ShellOptio
}
/*
+ * regexmatch() - given an string and a regex pattern return 1
+ * if it matches without error, else return 0.
+ *
+ */
+
+int regexmatch(const char *string, char *pattern)
+{
+ int status;
+ regex_t re;
+
+ if(regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0) {
+ return 0;
+ }
+
+ status = regexec(&re, string, (size_t)0, 0, 0);
+
+ regfree(&re);
+
+ if(status != 0) {
+ return 0;
+ }
+ return 1;
+}
+
+/*
* check_command_line() - take the command line passed to rssh, and verify
* that the specified command is one the user is
* allowed to run. Return the path of the command
@@ -195,6 +221,7 @@ bool check_command( char *cl, ShellOptio
*/
char *check_command_line( char *cl, ShellOptions_t *opts )
{
+ char *cl_epattern = "e[0123456789]+.[0123456789]+";
if ( check_command(cl, opts, PATH_SFTP_SERVER, RSSH_ALLOW_SFTP) )
return PATH_SFTP_SERVER;
@@ -230,10 +257,25 @@ char *check_command_line( char *cl, Shel
if ( check_command(cl, opts, PATH_RSYNC, RSSH_ALLOW_RSYNC) ){
/* filter -e option */
- if ( opt_exist(cl, 'e') ){
- fprintf(stderr, "\ninsecure -e option not allowed.");
- log_msg("insecure -e option in rdist command line!");
- return NULL;
+ // Under rsync 3.x, when --server is present, -e is used to
convey subprotocol info.
+ // We want to allow -e then and ensure the argument to -e is
%d+\.%d+
+ if ( strstr(cl, "--server" ) ){
+ if ( opt_exist(cl, 'e') ){
+ if( regexmatch(cl, cl_epattern) ) {
+// fprintf(stderr, "\ncl matches cl_eparttern
allowing access with -e argument");
+// log_msg("cl matches cl_eparttern allowing
access with -e arg");
+ } else {
+ fprintf(stderr, "\ninsecure -e option not
allowed.");
+ log_msg("insecure -e option in rsync command
line!");
+ return NULL;
+ }
+ }
+ } else {
+ if ( opt_exist(cl, 'e') ){
+ fprintf(stderr, "\ninsecure -e option not
allowed.");
+ log_msg("insecure -e option in rsync command
line!");
+ return NULL;
+ }
}
if ( strstr(cl, "--rsh=" ) ){diff -urNp rssh-2.3.2-dist/util.h rssh-2.3.2/util.h
--- rssh-2.3.2-dist/util.h 2006-01-03 12:37:55.000000000 -0500
+++ rssh-2.3.2/util.h 2008-01-23 17:01:43.000000000 -0500
@@ -40,5 +40,6 @@ int validate_access( const char *temp, b
bool *allow_cvs, bool *allow_rdist, bool *allow_rsync );
bool opt_exist( char *cl, char opt );
char *get_username( void );
+int regexmatch(const char *string, char *pattern);
#endif /* _util_h */
diff -urNp rssh-2.3.2-dist/util.c rssh-2.3.2/util.c
--- rssh-2.3.2-dist/util.c 2006-01-03 12:37:39.000000000 -0500
+++ rssh-2.3.2/util.c 2008-01-23 17:58:51.000000000 -0500
@@ -56,6 +56,7 @@
#ifdef HAVE_LIBGEN_H
#include <libgen.h>
#endif /* HAVE_LIBGEN_H */
+#include <regex.h>
/* LOCAL INCLUDES */
#include "pathnames.h"
@@ -134,7 +135,7 @@ bool opt_exist(char *cl, char opt)
{
int i = 0;
int len;
- char *token;
+// char *token;
bool optstring = FALSE;
@@ -187,6 +188,31 @@ bool check_command( char *cl, ShellOptio
}
/*
+ * regexmatch() - given an string and a regex pattern return 1
+ * if it matches without error, else return 0.
+ *
+ */
+
+int regexmatch(const char *string, char *pattern)
+{
+ int status;
+ regex_t re;
+
+ if(regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0) {
+ return 0;
+ }
+
+ status = regexec(&re, string, (size_t)0, 0, 0);
+
+ regfree(&re);
+
+ if(status != 0) {
+ return 0;
+ }
+ return 1;
+}
+
+/*
* check_command_line() - take the command line passed to rssh, and verify
* that the specified command is one the user is
* allowed to run. Return the path of the command
@@ -195,6 +221,7 @@ bool check_command( char *cl, ShellOptio
*/
char *check_command_line( char *cl, ShellOptions_t *opts )
{
+ char *cl_epattern = "e[0123456789]+.[0123456789]+";
if ( check_command(cl, opts, PATH_SFTP_SERVER, RSSH_ALLOW_SFTP) )
return PATH_SFTP_SERVER;
@@ -230,10 +257,25 @@ char *check_command_line( char *cl, Shel
if ( check_command(cl, opts, PATH_RSYNC, RSSH_ALLOW_RSYNC) ){
/* filter -e option */
- if ( opt_exist(cl, 'e') ){
- fprintf(stderr, "\ninsecure -e option not allowed.");
- log_msg("insecure -e option in rdist command line!");
- return NULL;
+ // Under rsync 3.x, when --server is present, -e is used to
convey subprotocol info.
+ // We want to allow -e then and ensure the argument to -e is
%d+\.%d+
+ if ( strstr(cl, "--server" ) ){
+ if ( opt_exist(cl, 'e') ){
+ if( regexmatch(cl, cl_epattern) ) {
+// fprintf(stderr, "\ncl matches
cl_eparttern allowing access with -e argument");
+// log_msg("cl matches cl_eparttern
allowing access with -e arg");
+ } else {
+ fprintf(stderr, "\ninsecure -e option
not allowed.");
+ log_msg("insecure -e option in rsync
command line!");
+ return NULL;
+ }
+ }
+ } else {
+ if ( opt_exist(cl, 'e') ){
+ fprintf(stderr, "\ninsecure -e option not
allowed.");
+ log_msg("insecure -e option in rsync command
line!");
+ return NULL;
+ }
}
if ( strstr(cl, "--rsh=" ) ){
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
rssh-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rssh-discuss