Proposed feature and patch

Eduardo Diaz Comellas <[email protected]> Sat, 7 Jan 2017 19:14:08 +0100
Newsgroups gmane.mail.perdition.user
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------B0D5BD49175C33ED4F5506C2
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit

Hi,

In our company we are using perdition to proxy access to dovecot 
servers. It works great!

Due to historic reasons, our user's login can be different in the 
dovecot server than in the frontend proxy. We use mysql to store all 
this information, and have produced a patch that allows this 
functionality. This patch allows to add a new column called "realuser" 
that holds the username to show to backend dovecot servers. We have done 
it only in the mysql account storage, and also made sure that we don't 
break anything if this feature is not used. This patch applies cleanly 
to 2.1 and 2.2.

Please find attached the patch. If there are any contribution guidelines 
to follow, please let me know.

Best regards.

-- 
Eduardo Díaz Comellas
Ultreia Comunicaciones, S.L.


--------------B0D5BD49175C33ED4F5506C2
Content-Type: text/x-patch;
 name="perdition-add-realuser-column.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="perdition-add-realuser-column.patch"

diff -Nuar perdition-2.2.orig/perdition/db/mysql/perditiondb_mysql.c perdition-2.2/perdition/db/mysql/perditiondb_mysql.c
--- perdition-2.2.orig/perdition/db/mysql/perditiondb_mysql.c	2013-10-04 03:44:12.000000000 +0200
+++ perdition-2.2/perdition/db/mysql/perditiondb_mysql.c	2017-01-07 18:49:46.090340430 +0100
@@ -53,6 +53,7 @@
 static char *db_user_col     = PERDITIONDB_MYSQL_DEFAULT_DBUSERCOL;
 static char *db_srv_col      = PERDITIONDB_MYSQL_DEFAULT_DBSRVCOL;
 static char *db_port_col     = PERDITIONDB_MYSQL_DEFAULT_DBPORTCOL;
+static char *db_realuser_col     = PERDITIONDB_MYSQL_DEFAULT_DBREALUSERCOL;
 
 
 /**********************************************************************
@@ -94,7 +95,7 @@
  * dbserver_init
  * Parse options string.
  * pre: options_str: Options string. String is of the form
- * [dbhost1[,dbhost2[,...]][:port[:dbname[:dbtable[:dbuser[:dbpwd[:dbsrvcol[:dbusercol[:dbportcol]]]]]]]]]
+ * [dbhost1[,dbhost2[,...]][:port[:dbname[:dbtable[:dbuser[:dbpwd[:dbsrvcol[:dbusercol[:dbportcol[:dbrealuser]]]]]]]]]]
  * post: Options string is parsed if not null into 
  *       static vanessa_dynamic_array_t a and 
  *       static char *dbhosts, *dbname, *dbtable, *dbuser, *dbpwd are
@@ -175,7 +176,15 @@
 	 PERDITIONDB_MYSQL_DBPORTCOL
      ); 
    }
-
+   if(count>PERDITIONDB_MYSQL_DBREALUSERCOL){ 
+     db_realuser_col=vanessa_dynamic_array_get_element(a, 
+	 PERDITIONDB_MYSQL_DBREALUSERCOL
+     ); 
+   }
+   else {
+     db_realuser_col=db_user_col;
+   }
+ 
    free(tmp_str);
 
    return(0);
@@ -249,7 +258,7 @@
        sqlstr, 
        PERDITIONDB_MYSQL_QUERY_LENGTH, 
        "select %s,%s,%s from %s where %s='%s';",
-       db_user_col, 
+       db_realuser_col, 
        db_srv_col, 
        db_port_col,
        dbtable, 
@@ -265,7 +274,7 @@
        sqlstr, 
        PERDITIONDB_MYSQL_QUERY_LENGTH, 
        "select %s,%s from %s where %s='%s';",
-       db_user_col, db_srv_col,
+       db_realuser_col, db_srv_col,
        dbtable, db_user_col,
        key_str_escaped
      )<0){
diff -Nuar perdition-2.2.orig/perdition/db/mysql/perditiondb_mysql.h perdition-2.2/perdition/db/mysql/perditiondb_mysql.h
--- perdition-2.2.orig/perdition/db/mysql/perditiondb_mysql.h	2013-10-04 03:44:12.000000000 +0200
+++ perdition-2.2/perdition/db/mysql/perditiondb_mysql.h	2017-01-07 18:48:07.322340430 +0100
@@ -53,6 +53,7 @@
 #define PERDITIONDB_MYSQL_DEFAULT_DBUSERCOL "user"
 #define PERDITIONDB_MYSQL_DEFAULT_DBSRVCOL  "servername"
 #define PERDITIONDB_MYSQL_DEFAULT_DBPORTCOL "port"
+#define PERDITIONDB_MYSQL_DEFAULT_DBREALUSERCOL "realuser"
 
 #define PERDITIONDB_MYSQL_DBHOSTS   0
 #define PERDITIONDB_MYSQL_DBPORT    1
@@ -63,6 +64,7 @@
 #define PERDITIONDB_MYSQL_DBSRVCOL  6
 #define PERDITIONDB_MYSQL_DBUSERCOL 7
 #define PERDITIONDB_MYSQL_DBPORTCOL 8
+#define PERDITIONDB_MYSQL_DBREALUSERCOL 9
 
 #define PERDITIONDB_MYSQL_QUERY_LENGTH 256
 
diff -Nuar perdition-2.2.orig/perdition/perditiondb.5 perdition-2.2/perdition/perditiondb.5
--- perdition-2.2.orig/perdition/perditiondb.5	2013-10-04 03:44:12.000000000 +0200
+++ perdition-2.2/perdition/perditiondb.5	2017-01-07 18:57:31.778340430 +0100
@@ -297,6 +297,8 @@
 .br
 port column:       port
 .br
+real user column:  realuser
+.br
 .P
 A script, perditiondb_mysql_makedb, is provided to initialise such a
 database.  Alternate values can be set using the \-m|\--map_library_opt
@@ -306,13 +308,13 @@
 .P
 <dbhost>[:<dbport>[:<dbname>[:<dbtable>[:<dbuser>
 .br
-[:<dbpwd>[:<dbservercol>[:<dbusercol>[:<dbportcol>]]]]]]]]
+[:<dbpwd>[:<dbservercol>[:<dbusercol>[:<dbportcol>[:<dbrealuser>]]]]]]]]]
 .P
 E.g.
 .P
 perdition \-m "some.host.com:3306:aDb:bTable:cUser:"\\
 .br
-"dPassword:eSrvCol:fUserCol:gPortCol"
+"dPassword:eSrvCol:fUserCol:gPortCol:hRealUser"
 .P
 Arguments may be omitted from the end of the option string with no
 consequence other than that the default value for any omitted argument will

--------------B0D5BD49175C33ED4F5506C2
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fXwpQZXJkaXRpb24t
dXNlcnMgbWFpbGluZyBsaXN0ClBlcmRpdGlvbi11c2Vyc0B2ZXJnZW5ldC5uZXQKaHR0cHM6Ly9s
aXN0cy52ZXJnZW5ldC5uZXQvbGlzdGluZm8vcGVyZGl0aW9uLXVzZXJzCg==

--------------B0D5BD49175C33ED4F5506C2--