diff --git a/include/msgapi.h b/include/msgapi.h index 7b04b7b..85c575f 100644 --- a/include/msgapi.h +++ b/include/msgapi.h @@ -488,11 +488,6 @@ EXPORT unsigned long MsgGetAgentBindIPAddress(void); EXPORT const char *MsgGetUnprivilegedUser(void); -// TODO: Deprecate these functions in favour of nmlib -EXPORT void MsgNmapChallenge(const unsigned char *response, unsigned char *reply, size_t length); -EXPORT Connection *MsgNmapConnect(const char *authUser, const char *store, MDBValueStruct *optVs); -EXPORT Connection *MsgNmapConnectEx(const char *authUser, const char *store, MDBValueStruct *optVs, TraceDestination *dest); - EXPORT void MsgMakePath(unsigned char *path); EXPORT BOOL MsgCleanPath(unsigned char *path); diff --git a/include/nmlib.h b/include/nmlib.h index 9f5d66b..6f7f4e8 100644 --- a/include/nmlib.h +++ b/include/nmlib.h @@ -179,8 +179,8 @@ Connection *NMAPConnectQueue(unsigned char *address, struct sockaddr_in *addr); Connection *NMAPConnectQueueEx(unsigned char *address, struct sockaddr_in *addr, TraceDestination *destination); BOOL NMAPEncrypt(Connection *conn, unsigned char *response, int length, BOOL force); -BOOL NMAPAuthenticate(Connection *conn, unsigned char *response, int length); BOOL NMAPAuthenticateToStore(Connection *conn, unsigned char *response, int length); +BOOL NMAPAuthenticateToQueue(Connection *conn, unsigned char *response, int length); int NMAPAuthenticateWithCookie(Connection *conn, const char *user, const char *cookie, unsigned char *buffer, int length); diff --git a/src/agents/calcmd/calcmdd.c b/src/agents/calcmd/calcmdd.c index 92a1e67..b89bc7c 100644 --- a/src/agents/calcmd/calcmdd.c +++ b/src/agents/calcmd/calcmdd.c @@ -328,9 +328,9 @@ RunCommand(CalCmdClient *client) BongoStringBuilderInit(&sb); - conn = MsgNmapConnectEx(client->recipient, client->recipient, - NULL, client->conn->trace.destination); - if (!conn) { + // FIXME: don't assume localhost. + conn = NMAPConnect("127.0.0.1", NULL); + if (!conn || !NMAPAuthenticateThenUserAndStore(conn, client->recipient)) { StartMessage(client, &sb, "cal error"); BongoStringBuilderAppend(&sb, "Server error, unable to run command.\r\n"); goto done; diff --git a/src/agents/itip/itip.c b/src/agents/itip/itip.c index d1450fd..f22605f 100644 --- a/src/agents/itip/itip.c +++ b/src/agents/itip/itip.c @@ -241,8 +241,9 @@ ApplyObjects(ItipAgentClient *client, const char *user = l->data; Connection *conn; - conn = MsgNmapConnectEx(user, user, NULL, client->conn->trace.destination); - if (!conn) { + // FIXME: don't assume localhost. + conn = NMAPConnect("127.0.0.1", NULL); + if (!conn || !NMAPAuthenticateThenUserAndStore(conn, user)) { continue; } diff --git a/src/libs/msgapi/msgapi.c b/src/libs/msgapi/msgapi.c index 9e70f54..24df7fe 100644 --- a/src/libs/msgapi/msgapi.c +++ b/src/libs/msgapi/msgapi.c @@ -587,109 +587,6 @@ MsgDomainExists(const unsigned char *domain, unsigned char *domainObjectDN) return(FALSE); } -EXPORT void -MsgNmapChallenge(const unsigned char *response, unsigned char *reply, size_t length) -{ - unsigned char *ptr; - unsigned char *salt; - static unsigned char access[NMAP_HASH_SIZE] = { '\0' }; - MDBValueStruct *v; - xpl_hash_context ctx; - - if (access[0] == '\0') { - if (MsgGlobal.directoryHandle) { - v = MDBCreateValueStruct(MsgGlobal.directoryHandle, NULL); - if (v) { - MDBRead(MSGSRV_ROOT, MSGSRV_A_ACL, v); - if (v->Used) { - HashCredential(MsgGlobal.server.dn, v->Value[0], access); - } - - MDBDestroyValueStruct(v); - } - } - } - - if (access[0] && reply && (length > 32) && ((ptr = strchr(response, '<')) != NULL)) { - salt = ++ptr; - - if ((ptr = strchr(ptr, '>')) != NULL) { - *ptr = '\0'; - } - - XplHashNew(&ctx, XPLHASH_MD5); - XplHashWrite(&ctx, salt, strlen(salt)); - XplHashWrite(&ctx, access, NMAP_HASH_SIZE); - XplHashFinal(&ctx, XPLHASH_LOWERCASE, reply, XPLHASH_MD5_LENGTH); - } else if (reply) { - *reply = '\0'; - } - - return; -} - -Connection * -MsgNmapConnect(const char *authUser, const char *store, MDBValueStruct *optVs) -{ - return MsgNmapConnectEx(authUser, store, optVs, NULL); -} - -Connection * -MsgNmapConnectEx(const char *authUser, const char *store, MDBValueStruct *optVs, TraceDestination *dest) -{ - struct sockaddr_in saddr; - Connection *conn; - char buffer[CONN_BUFSIZE]; - MDBValueStruct *vs; - BOOL success; - - if (!store) { - return NULL; - } - - if (optVs) { - vs = optVs; - } else { - vs = MDBCreateValueStruct(MsgGlobal.directoryHandle, NULL); - } - - success = FALSE; - conn = NULL; - - if (MsgFindObject(store, NULL, NULL, &saddr, vs)) { - MDBFreeValues(vs); - - conn = NMAPConnectEx(NULL, &saddr, dest); - - if (conn) { - if (NMAPAuthenticate(conn, buffer, CONN_BUFSIZE)) { - success = TRUE; - if (authUser) { - if (NMAPRunCommandF(conn, buffer, CONN_BUFSIZE, "USER %s\r\n", authUser) != 1000) { - success = FALSE; - } - } - - if (NMAPRunCommandF(conn, buffer, CONN_BUFSIZE, "STORE %s\r\n", store) != 1000) { - success = FALSE; - } - } - } - } - - if (!success && conn) { - NMAPQuit(conn); - ConnFree(conn); - conn = NULL; - } - - if (!optVs) { - MDBDestroyValueStruct(vs); - } - - return conn; -} - EXPORT int MsgGetParentAttribute(const unsigned char *userDN, unsigned char *attribute, MDBValueStruct *vOut) { diff --git a/src/libs/nmap/nmap.c b/src/libs/nmap/nmap.c index 85e4957..3567457 100644 --- a/src/libs/nmap/nmap.c +++ b/src/libs/nmap/nmap.c @@ -1487,64 +1487,56 @@ NMAPAuthenticateWithCookie(Connection *conn, const char *user, const char *cooki } } - -BOOL -NMAPAuthenticateToStore(Connection *conn, unsigned char *response, int length) +/** + * AUTH SYSTEM with the Store agent, but then change to a user and + * go into their store. + * \param conn Connection to the Queue agent + * \param response Buffer to use talking to the agent + * \param length Size of the 'response' buffer + * \return Whether or not we succeeded + */ +BOOL +NMAPAuthenticateThenUserAndStore(Connection *conn, unsigned char *user) { - int ccode; + char buffer[CONN_BUFSIZE+1]; - ccode = NMAPReadAnswer(conn, response, length, TRUE); - switch (ccode) { - case 1000: { - NMAPEncrypt(conn, response, length, FALSE); - return(TRUE); - } + if (!NMAPAuthenticateToStore(conn, buffer, CONN_BUFSIZE)) + return FALSE; - case 4242: { - unsigned char *ptr; - unsigned char *salt; - unsigned char message[XPLHASH_MD5_LENGTH]; - xpl_hash_context ctx; + if (NMAPRunCommandF(conn, buffer, CONN_BUFSIZE, "USER %s\r\n", user) != 1000) + return FALSE; - ptr = strchr(response, '<'); - if (ptr) { - salt = ++ptr; + if (NMAPRunCommandF(conn, buffer, CONN_BUFSIZE, "STORE %s\r\n", user) != 1000) + return FALSE; - if ((ptr = strchr(ptr, '>')) != NULL) { - *ptr = '\0'; - } - - XplHashNew(&ctx, XPLHASH_MD5); - XplHashWrite(&ctx, salt, strlen(salt)); - XplHashWrite(&ctx, NMAPLibrary.access, NMAP_HASH_SIZE); - XplHashFinal(&ctx, XPLHASH_LOWERCASE, message, XPLHASH_MD5_LENGTH); - - NMAPEncrypt(conn, response, length, FALSE); - - ConnWrite(conn, "AUTH SYSTEM ", 12); - ConnWrite(conn, message, 32); - ConnWrite(conn, "\r\n", 2); - - if ((ccode = ConnFlush(conn)) == 46) { - if ((ccode = NMAPReadAnswer(conn, response, length, TRUE)) == 1000) { - return(TRUE); - } - } - } - - /* - Fall through to the default case statement. - */ - } - - default: { - break; - } - } - - return(FALSE); + return TRUE; } +/** + * AUTH SYSTEM with the Store agent. + * \param conn Connection to the Queue agent + * \param response Buffer to use talking to the agent + * \param length Size of the 'response' buffer + * \return Whether or not we succeeded + */ +BOOL +NMAPAuthenticateToStore(Connection *conn, unsigned char *response, int length) +{ + return NMAPAuthenticate(conn, response, length); +} + +/** + * AUTH SYSTEM with the Queue agent. + * \param conn Connection to the Queue agent + * \param response Buffer to use talking to the agent + * \param length Size of the 'response' buffer + * \return Whether or not we succeeded + */ +BOOL +NMAPAuthenticateToQueue(Connection *conn, unsigned char *response, int length) +{ + return NMAPAuthenticate(conn, response, length); +} BOOL NMAPAuthenticate(Connection *conn, unsigned char *response, int length) diff --git a/src/libs/python/bongo/msgapi.c b/src/libs/python/bongo/msgapi.c index 9f36b0b..5af87c6 100644 --- a/src/libs/python/bongo/msgapi.c +++ b/src/libs/python/bongo/msgapi.c @@ -551,28 +551,6 @@ msgapi_IcsSubscribe(PyObject *self, PyObject *args) return PyLong_FromUnsignedLong(guid); } -PyDoc_STRVAR(NmapChallenge_doc, -"NmapChallenge(s) -> string response\n\ -\n\ -Return the response string for an NMAP challenge string s.\n\ -s is of the format \"NMAP <40c0cbb0hostname441444a4>\"."); - -static PyObject * -msgapi_NmapChallenge(PyObject *self, PyObject *args) -{ - unsigned char *salt; - unsigned int len=33; - unsigned char buf[len]; - - if (!PyArg_ParseTuple(args, "s", &salt)) { - return NULL; - } - - MsgNmapChallenge(salt, buf, len); - - return Py_BuildValue("s", buf); -} - extern PyObject *msgapi_GetConfigProperty(PyObject *, PyObject *); PyMethodDef MsgApiMethods[] = { @@ -590,7 +568,6 @@ PyMethodDef MsgApiMethods[] = { {"ImportIcs", msgapi_ImportIcs, METH_VARARGS | METH_STATIC, ImportIcs_doc}, {"IcsSubscribe", msgapi_IcsSubscribe, METH_VARARGS | METH_STATIC, IcsSubscribe_doc}, {"IcsImport", msgapi_IcsImport, METH_VARARGS | METH_STATIC, IcsImport_doc}, - {"NmapChallenge", msgapi_NmapChallenge, METH_VARARGS | METH_STATIC, NmapChallenge_doc}, {"GetConfigProperty", msgapi_GetConfigProperty, METH_VARARGS | METH_STATIC, GetConfigProperty_doc}, {"GetUnprivilegedUser", msgapi_GetUnprivilegedUser, METH_VARARGS | METH_STATIC, GetUnprivilegedUser_doc}, {NULL, NULL, 0, NULL}