From 44bf635e97f3053b97f7485e3206d5501cc88c57 Mon Sep 17 00:00:00 2001 From: darkcoven Date: Mon, 1 Sep 2014 12:36:45 +0200 Subject: [PATCH] Lib: fix login issue with switches that actually support encrypted passwords in read requests --- lib/src/session.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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 -- 2.39.5