From: darkcoven Date: Mon, 1 Sep 2014 10:36:45 +0000 (+0200) Subject: Lib: fix login issue with switches that actually support encrypted passwords in read... X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=44bf635e97f3053b97f7485e3206d5501cc88c57;hp=-c;p=ngadmin Lib: fix login issue with switches that actually support encrypted passwords in read requests --- 44bf635e97f3053b97f7485e3206d5501cc88c57 diff --git a/lib/src/session.c b/lib/src/session.c index a0357f3..d698dcd 100644 --- a/lib/src/session.c +++ b/lib/src/session.c @@ -4,6 +4,7 @@ #include #include +#include #include #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