diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..b35b2c2 Binary files /dev/null and b/.DS_Store differ diff --git a/client/client.cpp b/client/client.cpp index d490030..1139562 100644 --- a/client/client.cpp +++ b/client/client.cpp @@ -18,7 +18,8 @@ /////////////////////////////////////////////////////////////////////////////// enum commands { - SEND = 1, + LOGIN = 1, + SEND, LIST, READ, DEL, @@ -108,7 +109,7 @@ int main(int argc, char **argv) */ do { - printf("Please specify a command (SEND, LIST, READ, DEL, QUIT): "); + printf("Please specify a command (SEND, LIST, READ, DEL, QUIT, LOGIN): "); if (fgets(buffer, BUF - 1, stdin) != NULL) { size = strlen(buffer); @@ -124,7 +125,8 @@ int main(int argc, char **argv) } enum commands cmd; - if (strcmp(buffer, "SEND") == 0) cmd = SEND; + if (strcmp(buffer, "LOGIN") == 0) cmd = LOGIN; + else if (strcmp(buffer, "SEND") == 0) cmd = SEND; else if (strcmp(buffer, "LIST") == 0) cmd = LIST; else if (strcmp(buffer, "READ") == 0) cmd = READ; else if (strcmp(buffer, "DEL") == 0) cmd = DEL; @@ -133,6 +135,15 @@ int main(int argc, char **argv) char username[BUF], msgNum[10]; switch (cmd) { + case LOGIN: + char ldapUsername[BUF], ldapPassword[BUF]; + printf("LDAP Username: "); + fgets(ldapUsername, BUF - 1, stdin); + printf("Password: "); + fgets(ldapPassword, BUF - 1, stdin); + snprintf(buffer, sizeof(buffer), "LOGIN\n%s%s", ldapUsername, ldapPassword); + break; + case SEND: char sender[BUF], receiver[BUF], subject[81], message[BUF * 10]; printf("Sender: "); diff --git a/server/server.cpp b/server/server.cpp index 175cbdc..24f6a18 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -3,6 +3,10 @@ #include "mail.h" + +#include + + #include #include #include @@ -32,6 +36,9 @@ #include #include #include +#include +#include +#include #define BUF 1024 @@ -385,8 +392,46 @@ inline void exiting() std::string cmdLOGIN(std::vector& received) { - // code - return ""; + if (received.size() < 3) { + return "ERR\n"; + } + + const char* ldapUri = "ldap://ldap.technikum-wien.at:389"; + const int ldapVersion = LDAP_VERSION3; + LDAP* ldapHandle; + int rc = ldap_initialize(&ldapHandle, ldapUri); + if (rc != LDAP_SUCCESS) { + return "ERR\n"; + } + + rc = ldap_set_option(ldapHandle, LDAP_OPT_PROTOCOL_VERSION, &ldapVersion); + if (rc != LDAP_OPT_SUCCESS) { + ldap_unbind_ext_s(ldapHandle, NULL, NULL); + return "ERR\n"; + } + + rc = ldap_start_tls_s(ldapHandle, NULL, NULL); + if (rc != LDAP_SUCCESS) { + ldap_unbind_ext_s(ldapHandle, NULL, NULL); + return "ERR\n"; + } + + std::string ldapBindUser = "uid=" + received[1] + ",ou=people,dc=technikum-wien,dc=at"; + std::string ldapBindPassword = received[2]; + + BerValue bindCredentials; + bindCredentials.bv_val = (char*)ldapBindPassword.c_str(); + bindCredentials.bv_len = ldapBindPassword.length(); + rc = ldap_sasl_bind_s(ldapHandle, ldapBindUser.c_str(), LDAP_SASL_SIMPLE, &bindCredentials, NULL, NULL, NULL); + if (rc != LDAP_SUCCESS) { + ldap_unbind_ext_s(ldapHandle, NULL, NULL); + return "ERR\n"; + } + + + ldap_unbind_ext_s(ldapHandle, NULL, NULL); + + return "OK\n"; } std::string cmdSEND(std::vector& received)