diff options
| author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-01-24 12:05:29 -0600 |
|---|---|---|
| committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-01-24 12:05:29 -0600 |
| commit | 61dfcc04f73e45082f51945a7b98b7838da56da8 (patch) | |
| tree | 31ba95662c5972ef74abc64e4404e7e20e2f498e /servers/auth_server_lin/src/auth_conn.cpp | |
| parent | 941d8c3b969eae32b0945987f1d849930736f5bb (diff) | |
| download | ulab-61dfcc04f73e45082f51945a7b98b7838da56da8.tar.gz ulab-61dfcc04f73e45082f51945a7b98b7838da56da8.zip | |
User management console now functional
Diffstat (limited to 'servers/auth_server_lin/src/auth_conn.cpp')
| -rw-r--r-- | servers/auth_server_lin/src/auth_conn.cpp | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/servers/auth_server_lin/src/auth_conn.cpp b/servers/auth_server_lin/src/auth_conn.cpp index 42b6d2a..2833fc6 100644 --- a/servers/auth_server_lin/src/auth_conn.cpp +++ b/servers/auth_server_lin/src/auth_conn.cpp @@ -22,6 +22,9 @@ #include <stdlib.h> +#include <grp.h> +#include <pwd.h> + #include <tqtimer.h> #include <klocale.h> @@ -414,11 +417,42 @@ void AuthSocket::commandLoop() { while (m_databaseStationsCursor->next()) { bool authorized = false; bool in_use = false; - + + int ngroups = 0; + gid_t *groups; + struct passwd *pw; + struct group *gr; + groups = (gid_t*)malloc(ngroups*sizeof(gid_t)); + if (groups == NULL) { + printf("[ERROR] Unable to allocate memory\n\r"); fflush(stdout); + exit(EXIT_FAILURE); + } + + pw = getpwnam(m_authenticatedUserName.ascii()); + if (pw == NULL) { + printf("[WARNING] Unable to get detailed information for user '%s', ignoring\n\r", m_authenticatedUserName.ascii()); fflush(stdout); + continue; + } + + if (getgrouplist(m_authenticatedUserName.ascii(), pw->pw_gid, groups, &ngroups) == -1) { + free(groups); + groups = (gid_t*)malloc(ngroups*sizeof(gid_t)); + if (getgrouplist(m_authenticatedUserName.ascii(), pw->pw_gid, groups, &ngroups) == -1) { + printf("[WARNING] Unable to get groups for user '%s', ignoring\n\r", m_authenticatedUserName.ascii()); fflush(stdout); + continue; + } + } + + int i; m_databasePermissionsCursor->select(TQString("station=%1").arg(m_databaseStationsCursor->value("pk").toInt())); while (m_databasePermissionsCursor->next()) { - if (m_databasePermissionsCursor->value("username").toString() == m_authenticatedUserName) { - authorized = true; + for (i = 0; i < ngroups; i++) { + gr = getgrgid(groups[i]); + if (gr != NULL) { + if (m_databasePermissionsCursor->value("groupname").toString() == TQString(gr->gr_name)) { + authorized = true; + } + } } } m_databaseActivityCursor->select(TQString("station=%1").arg(m_databaseStationsCursor->value("pk").toInt())); |
