]> git.sur5r.net Git - ngadmin/commitdiff
Lib: fix login issue with switches that actually support encrypted passwords in read...
authordarkcoven <admin@darkcoven.tk>
Mon, 1 Sep 2014 10:36:45 +0000 (12:36 +0200)
committerdarkcoven <admin@darkcoven.tk>
Mon, 1 Sep 2014 10:38:20 +0000 (12:38 +0200)
lib/src/session.c

index a0357f3ba4a2d356a6639df90222ed937098c49f..d698dcdac937f1c0f92fced825551dcd27064245 100644 (file)
@@ -4,6 +4,7 @@
 #include <ngadmin.h>
 
 #include <nsdp/attr.h>
+#include <nsdp/str.h>
 #include <nsdp/protocol.h>
 
 #include "lib.h"
@@ -159,12 +160,22 @@ int ngadmin_login (struct ngadmin *nga, int id)
        }
        clearList(attr, (void(*)(void*))freeAttr);
        
-       /* strangely, passwords must never be encrypted inside a read request,
-        * or it will be rejected. Seems more to be a firmware bug
-        */
-       pushBackList(attr, newAttr(ATTR_PASSWORD, strlen(nga->password), strdup(nga->password)));
+       at = newAttr(ATTR_PASSWORD, strlen(nga->password), strdup(nga->password));
+       if (nga->encrypt_pass)
+               passwordEndecode(at->data, at->size);
+       pushBackList(attr, at);
        ret = readRequest(nga, attr);
        
+       if (nga->encrypt_pass && ret == ERR_BADPASS) {
+               /* strangely, with some switches, passwords must not be
+                * encrypted inside read requests or it will be rejected
+                * seems more to be a firmware bug
+                */
+               clearList(attr, (void(*)(void*))freeAttr);
+               pushBackList(attr, newAttr(ATTR_PASSWORD, strlen(nga->password), strdup(nga->password)));
+               ret = readRequest(nga, attr);
+       }
+       
        if (ret == ERR_INVOP) {
                /* it seems some switches do not support login with read request
                 * fallback to write request, even if it has the drawback of