summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-02-13 00:00:05 +0100
committerMatthias Schiffer <matthias@gamezock.de>2009-02-13 00:00:05 +0100
commit04363ca342914ba75e693edb876cbe535839fa79 (patch)
treed1309d7b0f6288a8250e972e5cab2546f2a77609 /src
parent2ab1fbd763ad8692ea3ca29705a4fe821ccb1309 (diff)
downloadmad-04363ca342914ba75e693edb876cbe535839fa79.tar
mad-04363ca342914ba75e693edb876cbe535839fa79.zip
Einfache Abfrage der Benutzerdatenbank implementiert
Diffstat (limited to 'src')
-rw-r--r--src/Client/CommandManager.cpp26
-rw-r--r--src/Client/CommandManager.h2
-rw-r--r--src/Client/CommandParser.cpp22
-rw-r--r--src/Client/CommandParser.h1
-rw-r--r--src/Client/Makefile.in9
-rw-r--r--src/Client/Requests/Makefile.in9
-rw-r--r--src/Common/ActionManager.cpp2
-rw-r--r--src/Common/Makefile.am2
-rw-r--r--src/Common/Makefile.in11
-rw-r--r--src/Common/ModuleManager.cpp2
-rw-r--r--src/Common/Request.h2
-rw-r--r--src/Common/RequestHandlers/Makefile.in9
-rw-r--r--src/Common/Requests/Makefile.am4
-rw-r--r--src/Common/Requests/Makefile.in16
-rw-r--r--src/Common/Requests/UserListRequest.cpp42
-rw-r--r--src/Common/Requests/UserListRequest.h43
-rw-r--r--src/Common/UserInfo.h55
-rw-r--r--src/Core/Backends/Makefile.in7
-rw-r--r--src/Core/ConnectionManager.cpp2
-rw-r--r--src/Core/Makefile.in9
-rw-r--r--src/Core/RequestHandlers/Makefile.am4
-rw-r--r--src/Core/RequestHandlers/Makefile.in17
-rw-r--r--src/Core/RequestHandlers/UserListRequestHandler.cpp63
-rw-r--r--src/Core/RequestHandlers/UserListRequestHandler.h51
-rw-r--r--src/Core/Requests/Makefile.in9
-rw-r--r--src/Core/UserBackend.cpp4
-rw-r--r--src/Core/UserBackend.h21
-rw-r--r--src/Daemon/Backends/Makefile.in9
-rw-r--r--src/Daemon/Makefile.in9
-rw-r--r--src/Daemon/RequestHandlers/Makefile.in9
-rw-r--r--src/Daemon/Requests/Makefile.in9
-rw-r--r--src/Makefile.in9
-rw-r--r--src/Net/FdManager.cpp2
-rw-r--r--src/Net/Makefile.in9
-rw-r--r--src/Net/Packet.h3
-rw-r--r--src/Net/Packets/Makefile.am4
-rw-r--r--src/Net/Packets/Makefile.in16
-rw-r--r--src/Net/Packets/UserListPacket.cpp85
-rw-r--r--src/Net/Packets/UserListPacket.h79
-rw-r--r--src/mad-core.conf17
-rw-r--r--src/mad-core.cpp2
-rw-r--r--src/modules/Makefile.am2
-rw-r--r--src/modules/Makefile.in11
-rw-r--r--src/modules/SystemBackendPosix.h4
-rw-r--r--src/modules/UserBackendMysql.cpp96
-rw-r--r--src/modules/UserBackendMysql.h35
46 files changed, 718 insertions, 136 deletions
diff --git a/src/Client/CommandManager.cpp b/src/Client/CommandManager.cpp
index 4b24782..aacf939 100644
--- a/src/Client/CommandManager.cpp
+++ b/src/Client/CommandManager.cpp
@@ -23,6 +23,7 @@
#include <Net/Packets/FSInfoPacket.h>
#include <Net/Packets/HostListPacket.h>
#include <Net/Packets/HostStatusPacket.h>
+#include <Net/Packets/UserListPacket.h>
#include <cmath>
#include <iostream>
@@ -205,5 +206,30 @@ void CommandManager::statusRequestFinished(const Common::Request<Net::Packets::H
requestFinished();
}
+void CommandManager::userListRequestFinished(const Common::Request<Net::Packets::UserListPacket> &request) {
+ try {
+ const Net::Packets::UserListPacket &packet = request.getResult();
+
+ const std::vector<Common::UserInfo> &users = packet.getUserInfo();
+
+ if(users.empty()) {
+ std::cout << "User list is empty." << std::endl;
+ }
+ else {
+ std::cout << "Found " << packet.getUserInfo().size() << " users:" << std::endl;
+
+ for(std::vector<Common::UserInfo>::const_iterator user = users.begin(); user != users.end(); ++user)
+ std::cout << " " << user->getUid() << ", " << user->getGid() << ", " << user->getUsername() << ", " << user->getFullName() << std::endl;
+ }
+
+ std::cout << std::endl;
+ }
+ catch(Common::Exception &exception) {
+ Common::Logger::logf(Common::Logger::ERROR, "An error occurred during your request: %s.", exception.strerror().c_str());
+ }
+
+ requestFinished();
+}
+
}
}
diff --git a/src/Client/CommandManager.h b/src/Client/CommandManager.h
index ef20e8a..454c77e 100644
--- a/src/Client/CommandManager.h
+++ b/src/Client/CommandManager.h
@@ -29,6 +29,7 @@ namespace Packets {
class FSInfoPacket;
class HostStatusPacket;
class HostListPacket;
+class UserListPacket;
}
}
@@ -61,6 +62,7 @@ class CommandManager {
void disconnectRequestFinished(const Common::Request<> &request);
void fsInfoRequestFinished(const Common::Request<Net::Packets::FSInfoPacket> &request);
void statusRequestFinished(const Common::Request<Net::Packets::HostStatusPacket> &request);
+ void userListRequestFinished(const Common::Request<Net::Packets::UserListPacket> &request);
CommandManager() : activeRequests(0), disconnect(false) {}
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index efc9c4b..304a2ff 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -28,6 +28,7 @@
#include <Common/Requests/FSInfoRequest.h>
#include <Common/Requests/DisconnectRequest.h>
#include <Common/Requests/StatusRequest.h>
+#include <Common/Requests/UserListRequest.h>
#include <Common/Tokenizer.h>
#include <Net/Packets/HostListPacket.h>
#include <Net/Packets/HostStatusPacket.h>
@@ -40,13 +41,14 @@ namespace Mad {
namespace Client {
const CommandParser::Command CommandParser::commands[] = {
- {{"fsinfo", 0}, "fsinfo [host]", "Displays file system usage information", "Displays file system usage information of a host or the server (if no host is given).", &CommandParser::fsinfoCommand},
- {{"help", "?", 0}, "help [command]", "Displays usage information about commands", "Displays usage information about a command. If no command is given, a list of all available commands is displayed.", &CommandParser::helpCommand},
- {{"list_hosts", "hosts", 0}, "list_hosts [-a]", "Lists the currently active hosts", "Lists the currently active hosts.\n\n -a\tAlso list inactive hosts", &CommandParser::listHostsCommand},
- {{"reboot", 0}, "reboot *|host...", "Reboots host", "Reboots hosts. * will reboot all hosts.", &CommandParser::rebootCommand},
- {{"shutdown", "halt", 0}, "shutdown *|host...", "Shuts hosts down", "Shuts hosts down. * will shut down all hosts.", &CommandParser::shutdownCommand},
- {{"status", "st", 0}, "status [host]", "Displays status information", "Displays host status information. If no host is given, server status information is displayed.", &CommandParser::statusCommand},
- {{"exit", "quit", 0}, "exit", "Closes the connection and quits the client", "Closes the connection and quits the client.", &CommandParser::exitCommand},
+ {{"fsinfo", 0}, "fsinfo [host]", "Display file system usage information", "Display file system usage information of a host or the server (if no host is given).", &CommandParser::fsinfoCommand},
+ {{"help", "?", 0}, "help [command]", "Display usage information about commands", "Display usage information about a command. If no command is given, display a list of all available commands.", &CommandParser::helpCommand},
+ {{"list_hosts", "hosts", 0}, "list_hosts [-a]", "List the currently active hosts", "List the currently active hosts.\n\n -a\tAlso list inactive hosts", &CommandParser::listHostsCommand},
+ {{"reboot", 0}, "reboot *|host...", "Reboot host", "Reboot hosts. * will reboot all hosts.", &CommandParser::rebootCommand},
+ {{"shutdown", "halt", 0}, "shutdown *|host...", "Shut hosts down", "Shut hosts down. * will shut down all hosts.", &CommandParser::shutdownCommand},
+ {{"status", "st", 0}, "status [host]", "Display status information", "Display host status information. If no host is given, display server status information.", &CommandParser::statusCommand},
+ {{"list_users", "users", 0}, "list_users", "Show the user account database", "Show the user account database.", &CommandParser::listUsersCommand},
+ {{"exit", "quit", 0}, "exit", "Close the connection and quit the client", "Closes the connection and quits the client.", &CommandParser::exitCommand},
{{0}, 0, 0, 0, 0}
};
@@ -253,6 +255,12 @@ void CommandParser::statusCommand(const std::vector<std::string> &args) {
++CommandManager::get()->activeRequests;
}
+void CommandParser::listUsersCommand(const std::vector<std::string>&) {
+ ++CommandManager::get()->activeRequests;
+
+ Common::RequestManager::get()->sendRequest(connection, std::auto_ptr<Common::RequestBase>(new Common::Requests::UserListRequest(sigc::mem_fun(CommandManager::get(), &CommandManager::userListRequestFinished))));
+}
+
void CommandParser::exitCommand(const std::vector<std::string>&) {
++CommandManager::get()->activeRequests;
diff --git a/src/Client/CommandParser.h b/src/Client/CommandParser.h
index e01449a..de65788 100644
--- a/src/Client/CommandParser.h
+++ b/src/Client/CommandParser.h
@@ -66,6 +66,7 @@ class CommandParser {
void rebootCommand(const std::vector<std::string> &args);
void shutdownCommand(const std::vector<std::string> &args);
void statusCommand(const std::vector<std::string> &args);
+ void listUsersCommand(const std::vector<std::string> &args);
void exitCommand(const std::vector<std::string>&);
CommandParser() : connection(0) {}
diff --git a/src/Client/Makefile.in b/src/Client/Makefile.in
index 3d3ddda..20f85ee 100644
--- a/src/Client/Makefile.in
+++ b/src/Client/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -221,6 +221,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = Requests
@@ -236,8 +237,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -385,7 +386,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Client/Requests/Makefile.in b/src/Client/Requests/Makefile.in
index bba3c7f..842713e 100644
--- a/src/Client/Requests/Makefile.in
+++ b/src/Client/Requests/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -212,6 +212,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequests.la
@@ -225,8 +226,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -305,7 +306,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Common/ActionManager.cpp b/src/Common/ActionManager.cpp
index c6c4e41..fc2bd98 100644
--- a/src/Common/ActionManager.cpp
+++ b/src/Common/ActionManager.cpp
@@ -23,7 +23,7 @@
#include <fcntl.h>
#include <signal.h>
-#include <sigc++/hide.h>
+#include <sigc++/adaptors/hide.h>
namespace Mad {
namespace Common {
diff --git a/src/Common/Makefile.am b/src/Common/Makefile.am
index 0f2fb39..665c21a 100644
--- a/src/Common/Makefile.am
+++ b/src/Common/Makefile.am
@@ -9,4 +9,4 @@ libcommon_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandler
noinst_HEADERS = ActionManager.h ConfigEntry.h ConfigManager.h Configurable.h Exception.h HostInfo.h \
Initializable.h Logger.h LoggerBase.h LogManager.h ModuleManager.h \
RemoteLogger.h Request.h RequestBase.h RequestHandler.h RequestManager.h \
- SystemBackend.h Tokenizer.h
+ SystemBackend.h Tokenizer.h UserInfo.h
diff --git a/src/Common/Makefile.in b/src/Common/Makefile.in
index e787215..2fb869f 100644
--- a/src/Common/Makefile.in
+++ b/src/Common/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -224,6 +224,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = Requests RequestHandlers
@@ -236,7 +237,7 @@ libcommon_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandlers
noinst_HEADERS = ActionManager.h ConfigEntry.h ConfigManager.h Configurable.h Exception.h HostInfo.h \
Initializable.h Logger.h LoggerBase.h LogManager.h ModuleManager.h \
RemoteLogger.h Request.h RequestBase.h RequestHandler.h RequestManager.h \
- SystemBackend.h Tokenizer.h
+ SystemBackend.h Tokenizer.h UserInfo.h
all: all-recursive
@@ -246,8 +247,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -403,7 +404,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Common/ModuleManager.cpp b/src/Common/ModuleManager.cpp
index 06732a4..0e892c5 100644
--- a/src/Common/ModuleManager.cpp
+++ b/src/Common/ModuleManager.cpp
@@ -22,8 +22,6 @@
#include "ConfigEntry.h"
#include "Logger.h"
-#include <iostream>
-
extern const lt_dlsymlist lt_preloaded_symbols[];
diff --git a/src/Common/Request.h b/src/Common/Request.h
index 229b8b8..2317d5a 100644
--- a/src/Common/Request.h
+++ b/src/Common/Request.h
@@ -24,7 +24,7 @@
#include "Exception.h"
#include <memory>
-#include <sigc++/hide.h>
+#include <sigc++/adaptors/hide.h>
namespace Mad {
namespace Common {
diff --git a/src/Common/RequestHandlers/Makefile.in b/src/Common/RequestHandlers/Makefile.in
index 5b8b578..dc292e3 100644
--- a/src/Common/RequestHandlers/Makefile.in
+++ b/src/Common/RequestHandlers/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -211,6 +211,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequesthandlers.la
@@ -224,8 +225,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -303,7 +304,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Common/Requests/Makefile.am b/src/Common/Requests/Makefile.am
index ff116fc..eae8669 100644
--- a/src/Common/Requests/Makefile.am
+++ b/src/Common/Requests/Makefile.am
@@ -1,4 +1,4 @@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = DisconnectRequest.cpp FSInfoRequest.cpp GSSAPIAuthRequest.cpp StatusRequest.cpp
+librequests_la_SOURCES = DisconnectRequest.cpp FSInfoRequest.cpp GSSAPIAuthRequest.cpp StatusRequest.cpp UserListRequest.cpp
-noinst_HEADERS = DisconnectRequest.h FSInfoRequest.h GSSAPIAuthRequest.h StatusRequest.h
+noinst_HEADERS = DisconnectRequest.h FSInfoRequest.h GSSAPIAuthRequest.h StatusRequest.h UserListRequest.h
diff --git a/src/Common/Requests/Makefile.in b/src/Common/Requests/Makefile.in
index 631bb21..2c363eb 100644
--- a/src/Common/Requests/Makefile.in
+++ b/src/Common/Requests/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -51,7 +51,7 @@ CONFIG_CLEAN_FILES =
LTLIBRARIES = $(noinst_LTLIBRARIES)
librequests_la_LIBADD =
am_librequests_la_OBJECTS = DisconnectRequest.lo FSInfoRequest.lo \
- GSSAPIAuthRequest.lo StatusRequest.lo
+ GSSAPIAuthRequest.lo StatusRequest.lo UserListRequest.lo
librequests_la_OBJECTS = $(am_librequests_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
@@ -211,11 +211,12 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequests.la
-librequests_la_SOURCES = DisconnectRequest.cpp FSInfoRequest.cpp GSSAPIAuthRequest.cpp StatusRequest.cpp
-noinst_HEADERS = DisconnectRequest.h FSInfoRequest.h GSSAPIAuthRequest.h StatusRequest.h
+librequests_la_SOURCES = DisconnectRequest.cpp FSInfoRequest.cpp GSSAPIAuthRequest.cpp StatusRequest.cpp UserListRequest.cpp
+noinst_HEADERS = DisconnectRequest.h FSInfoRequest.h GSSAPIAuthRequest.h StatusRequest.h UserListRequest.h
all: all-am
.SUFFIXES:
@@ -224,8 +225,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -271,6 +272,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/FSInfoRequest.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GSSAPIAuthRequest.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StatusRequest.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UserListRequest.Plo@am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@@ -304,7 +306,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Common/Requests/UserListRequest.cpp b/src/Common/Requests/UserListRequest.cpp
new file mode 100644
index 0000000..cd9c760
--- /dev/null
+++ b/src/Common/Requests/UserListRequest.cpp
@@ -0,0 +1,42 @@
+/*
+ * UserListRequest.cpp
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "UserListRequest.h"
+#include <Net/Connection.h>
+
+namespace Mad {
+namespace Common {
+namespace Requests {
+
+void UserListRequest::sendRequest(Net::Connection *connection, uint16_t requestId) {
+ connection->send(Net::Packet(Net::Packet::USERS_LIST, requestId));
+}
+
+void UserListRequest::handlePacket(Net::Connection*, const Net::Packet &packet) {
+ if(packet.getType() != Net::Packet::OK) {
+ finishWithError(Exception(Exception::UNEXPECTED_PACKET));
+ return; // TODO Logging
+ }
+
+ finish(Net::Packets::UserListPacket(packet));
+}
+
+}
+}
+}
diff --git a/src/Common/Requests/UserListRequest.h b/src/Common/Requests/UserListRequest.h
new file mode 100644
index 0000000..c62e284
--- /dev/null
+++ b/src/Common/Requests/UserListRequest.h
@@ -0,0 +1,43 @@
+/*
+ * UserListRequest.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_COMMON_REQUESTS_USERLISTREQUEST_H_
+#define MAD_COMMON_REQUESTS_USERLISTREQUEST_H_
+
+#include "../Request.h"
+#include <Net/Packets/UserListPacket.h>
+
+namespace Mad {
+namespace Common {
+namespace Requests {
+
+class UserListRequest : public Request<Net::Packets::UserListPacket> {
+ protected:
+ virtual void sendRequest(Net::Connection *connection, uint16_t requestId);
+ virtual void handlePacket(Net::Connection *connection, const Net::Packet &packet);
+
+ public:
+ UserListRequest(slot_type slot) : Request<Net::Packets::UserListPacket>(slot) {}
+};
+
+}
+}
+}
+
+#endif /* MAD_COMMON_REQUESTS_USERLISTREQUEST_H_ */
diff --git a/src/Common/UserInfo.h b/src/Common/UserInfo.h
new file mode 100644
index 0000000..94c0c60
--- /dev/null
+++ b/src/Common/UserInfo.h
@@ -0,0 +1,55 @@
+/*
+ * UserInfo.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_COMMON_USERINFO_H_
+#define MAD_COMMON_USERINFO_H_
+
+#include <string>
+
+namespace Mad {
+namespace Common {
+
+class UserInfo {
+ private:
+ unsigned long uid;
+ unsigned long gid;
+
+ std::string username;
+ std::string fullName;
+
+ public:
+ UserInfo(unsigned long uid0 = 0, const std::string& username0 = std::string()) : uid(uid0), gid(0), username(username0) {}
+
+ void setUid(unsigned long newUid) {uid = newUid;}
+ unsigned long getUid() const {return uid;}
+
+ void setGid(unsigned long newUid) {uid = newUid;}
+ unsigned long getGid() const {return uid;}
+
+ void setUsername(const std::string& newUsername) {username = newUsername;}
+ const std::string& getUsername() const {return username;}
+
+ void setFullName(const std::string& newFullName) {fullName = newFullName;}
+ const std::string& getFullName() const {return fullName;}
+};
+
+}
+}
+
+#endif /* MAD_COMMON_USERINFO_H_ */
diff --git a/src/Core/Backends/Makefile.in b/src/Core/Backends/Makefile.in
index ba6fe71..0f181f4 100644
--- a/src/Core/Backends/Makefile.in
+++ b/src/Core/Backends/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -206,6 +206,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = libbackends.la
@@ -218,8 +219,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
diff --git a/src/Core/ConnectionManager.cpp b/src/Core/ConnectionManager.cpp
index c347e29..fde7e62 100644
--- a/src/Core/ConnectionManager.cpp
+++ b/src/Core/ConnectionManager.cpp
@@ -31,6 +31,7 @@
#include "RequestHandlers/GSSAPIAuthRequestHandler.h"
#include "RequestHandlers/IdentifyRequestHandler.h"
#include "RequestHandlers/LogRequestHandler.h"
+#include "RequestHandlers/UserListRequestHandler.h"
#include <Net/FdManager.h>
#include <Net/ServerConnection.h>
#include <Net/Packet.h>
@@ -144,6 +145,7 @@ void ConnectionManager::doInit() {
Common::RequestManager::get()->registerPacketType<RequestHandlers::GSSAPIAuthRequestHandler>(Net::Packet::GSSAPI_AUTH);
Common::RequestManager::get()->registerPacketType<RequestHandlers::IdentifyRequestHandler>(Net::Packet::IDENTIFY);
Common::RequestManager::get()->registerPacketType<RequestHandlers::LogRequestHandler>(Net::Packet::LOG);
+ Common::RequestManager::get()->registerPacketType<RequestHandlers::UserListRequestHandler>(Net::Packet::USERS_LIST);
}
void ConnectionManager::doDeinit() {
diff --git a/src/Core/Makefile.in b/src/Core/Makefile.in
index 0718c95..4745e1b 100644
--- a/src/Core/Makefile.in
+++ b/src/Core/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -221,6 +221,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = Backends Requests RequestHandlers
@@ -236,8 +237,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -384,7 +385,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Core/RequestHandlers/Makefile.am b/src/Core/RequestHandlers/Makefile.am
index 79aef5e..5a044c8 100644
--- a/src/Core/RequestHandlers/Makefile.am
+++ b/src/Core/RequestHandlers/Makefile.am
@@ -1,6 +1,6 @@
noinst_LTLIBRARIES = librequesthandlers.la
librequesthandlers_la_SOURCES = DaemonCommandRequestHandler.cpp DaemonFSInfoRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp \
- IdentifyRequestHandler.cpp LogRequestHandler.cpp
+ IdentifyRequestHandler.cpp LogRequestHandler.cpp UserListRequestHandler.cpp
noinst_HEADERS = DaemonCommandRequestHandler.h DaemonFSInfoRequestHandler.h DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h \
- IdentifyRequestHandler.h LogRequestHandler.h
+ IdentifyRequestHandler.h LogRequestHandler.h UserListRequestHandler.h
diff --git a/src/Core/RequestHandlers/Makefile.in b/src/Core/RequestHandlers/Makefile.in
index 980ffd4..18076c0 100644
--- a/src/Core/RequestHandlers/Makefile.in
+++ b/src/Core/RequestHandlers/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -53,7 +53,8 @@ librequesthandlers_la_LIBADD =
am_librequesthandlers_la_OBJECTS = DaemonCommandRequestHandler.lo \
DaemonFSInfoRequestHandler.lo DaemonListRequestHandler.lo \
DaemonStatusRequestHandler.lo GSSAPIAuthRequestHandler.lo \
- IdentifyRequestHandler.lo LogRequestHandler.lo
+ IdentifyRequestHandler.lo LogRequestHandler.lo \
+ UserListRequestHandler.lo
librequesthandlers_la_OBJECTS = $(am_librequesthandlers_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
@@ -213,14 +214,15 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequesthandlers.la
librequesthandlers_la_SOURCES = DaemonCommandRequestHandler.cpp DaemonFSInfoRequestHandler.cpp DaemonListRequestHandler.cpp DaemonStatusRequestHandler.cpp GSSAPIAuthRequestHandler.cpp \
- IdentifyRequestHandler.cpp LogRequestHandler.cpp
+ IdentifyRequestHandler.cpp LogRequestHandler.cpp UserListRequestHandler.cpp
noinst_HEADERS = DaemonCommandRequestHandler.h DaemonFSInfoRequestHandler.h DaemonListRequestHandler.h DaemonStatusRequestHandler.h GSSAPIAuthRequestHandler.h \
- IdentifyRequestHandler.h LogRequestHandler.h
+ IdentifyRequestHandler.h LogRequestHandler.h UserListRequestHandler.h
all: all-am
@@ -230,8 +232,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -280,6 +282,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/GSSAPIAuthRequestHandler.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/IdentifyRequestHandler.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LogRequestHandler.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UserListRequestHandler.Plo@am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@@ -313,7 +316,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Core/RequestHandlers/UserListRequestHandler.cpp b/src/Core/RequestHandlers/UserListRequestHandler.cpp
new file mode 100644
index 0000000..01c2eb3
--- /dev/null
+++ b/src/Core/RequestHandlers/UserListRequestHandler.cpp
@@ -0,0 +1,63 @@
+/*
+ * UserListRequestHandler.cpp
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "UserListRequestHandler.h"
+#include "../UserBackend.h"
+#include <Common/Logger.h>
+#include <Net/Connection.h>
+#include <Net/Packets/ErrorPacket.h>
+#include <Net/Packets/UserListPacket.h>
+
+namespace Mad {
+namespace Core {
+namespace RequestHandlers {
+
+void UserListRequestHandler::handlePacket(Net::Connection *con, const Net::Packet &packet) {
+ if(packet.getType() != Net::Packet::USERS_LIST) {
+ Common::Logger::log(Common::Logger::ERROR, "Received an unexpected packet.");
+ connection->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::UNEXPECTED_PACKET)));
+
+ signalFinished().emit();
+ return;
+ }
+
+ // TODO Require authentication
+
+ connection = con;
+ requestId = packet.getRequestId();
+
+ if(!UserBackend::getUserList(sigc::mem_fun(this, &UserListRequestHandler::userListHandler))) {
+ con->send(Net::Packets::ErrorPacket(Net::Packet::ERROR, packet.getRequestId(), Common::Exception(Common::Exception::NOT_IMPLEMENTED)));
+ signalFinished().emit();
+ }
+}
+
+void UserListRequestHandler::userListHandler(const std::map<unsigned long, Common::UserInfo> &info) {
+ std::vector<Common::UserInfo> userList;
+
+ for(std::map<unsigned long, Common::UserInfo>::const_iterator user = info.begin(); user != info.end(); ++user)
+ userList.push_back(user->second);
+
+ connection->send(Net::Packets::UserListPacket(Net::Packet::OK, requestId, userList));
+ signalFinished().emit();
+}
+
+}
+}
+}
diff --git a/src/Core/RequestHandlers/UserListRequestHandler.h b/src/Core/RequestHandlers/UserListRequestHandler.h
new file mode 100644
index 0000000..92eddb7
--- /dev/null
+++ b/src/Core/RequestHandlers/UserListRequestHandler.h
@@ -0,0 +1,51 @@
+/*
+ * UserListRequestHandler.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_CORE_REQUESTHANDLERS_USERLISTREQUESTHANDLER_H_
+#define MAD_CORE_REQUESTHANDLERS_USERLISTREQUESTHANDLER_H_
+
+#include <Common/RequestHandler.h>
+#include <Common/UserInfo.h>
+
+#include <map>
+#include <stdint.h>
+
+namespace Mad {
+namespace Core {
+namespace RequestHandlers {
+
+class UserListRequestHandler : public Common::RequestHandler {
+ private:
+ Net::Connection *connection;
+ uint16_t requestId;
+
+ void userListHandler(const std::map<unsigned long, Common::UserInfo> &info);
+
+ protected:
+ virtual void handlePacket(Net::Connection *con, const Net::Packet &packet);
+
+ public:
+ UserListRequestHandler() {}
+};
+
+}
+}
+}
+
+#endif /* MAD_CORE_REQUESTHANDLERS_USERLISTREQUESTHANDLER_H_ */
diff --git a/src/Core/Requests/Makefile.in b/src/Core/Requests/Makefile.in
index da413f4..8b2ad77 100644
--- a/src/Core/Requests/Makefile.in
+++ b/src/Core/Requests/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -211,6 +211,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequests.la
@@ -224,8 +225,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -302,7 +303,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Core/UserBackend.cpp b/src/Core/UserBackend.cpp
index ccb5e18..de8b943 100644
--- a/src/Core/UserBackend.cpp
+++ b/src/Core/UserBackend.cpp
@@ -25,7 +25,7 @@ namespace Core {
std::set<UserBackend*, UserBackend::Compare> UserBackend::backends;
-bool UserBackend::getUserList(const sigc::slot<void, const std::map<unsigned long, UserInfo>& > &callback) {
+bool UserBackend::getUserList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback) {
for(std::set<UserBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
if((*backend)->userList(callback))
return true;
@@ -34,7 +34,7 @@ bool UserBackend::getUserList(const sigc::slot<void, const std::map<unsigned lon
return false;
}
-bool UserBackend::getUserInfo(unsigned long uid, const sigc::slot<void, const UserInfo&> &callback) {
+bool UserBackend::getUserInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback) {
for(std::set<UserBackend*>::iterator backend = backends.begin(); backend != backends.end(); ++backend) {
if((*backend)->userInfo(uid, callback))
return true;
diff --git a/src/Core/UserBackend.h b/src/Core/UserBackend.h
index 6031d2f..aad9ace 100644
--- a/src/Core/UserBackend.h
+++ b/src/Core/UserBackend.h
@@ -20,6 +20,8 @@
#ifndef MAD_CORE_USERBACKEND_H_
#define MAD_CORE_USERBACKEND_H_
+#include <Common/UserInfo.h>
+
#include <map>
#include <set>
#include <string>
@@ -44,17 +46,6 @@ class UserBackend {
static std::set<UserBackend*, Compare> backends;
- public:
- struct UserInfo {
- unsigned long uid;
- unsigned long gid;
-
- std::vector<unsigned long> gids;
-
- std::string username;
- std::string fullName;
- };
-
protected:
UserBackend() {}
@@ -66,11 +57,11 @@ class UserBackend {
backends.erase(backend);
}
- virtual bool userList(const sigc::slot<void, const std::map<unsigned long, UserInfo>& >&) {
+ virtual bool userList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& >&) {
return false;
}
- virtual bool userInfo(unsigned long, const sigc::slot<void, const UserInfo&>&) {
+ virtual bool userInfo(unsigned long, const sigc::slot<void, const Common::UserInfo&>&) {
return false;
}
@@ -85,8 +76,8 @@ class UserBackend {
public:
virtual ~UserBackend() {}
- static bool getUserList(const sigc::slot<void, const std::map<unsigned long, UserInfo>& > &callback);
- static bool getUserInfo(unsigned long uid, const sigc::slot<void, const UserInfo&> &callback);
+ static bool getUserList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback);
+ static bool getUserInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback);
static bool setPassword(unsigned long uid, const std::string &password, const sigc::slot<void, bool> &callback);
};
diff --git a/src/Daemon/Backends/Makefile.in b/src/Daemon/Backends/Makefile.in
index 7ab8ef9..6f3c136 100644
--- a/src/Daemon/Backends/Makefile.in
+++ b/src/Daemon/Backends/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -193,6 +193,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_HEADERS = NetworkLogger.h
@@ -203,8 +204,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -240,7 +241,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Daemon/Makefile.in b/src/Daemon/Makefile.in
index 7b55449..fbaa98c 100644
--- a/src/Daemon/Makefile.in
+++ b/src/Daemon/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -219,6 +219,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = Backends Requests RequestHandlers
@@ -233,8 +234,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -357,7 +358,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Daemon/RequestHandlers/Makefile.in b/src/Daemon/RequestHandlers/Makefile.in
index 0030ecc..e4b4282 100644
--- a/src/Daemon/RequestHandlers/Makefile.in
+++ b/src/Daemon/RequestHandlers/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -210,6 +210,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequesthandlers.la
@@ -223,8 +224,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -300,7 +301,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Daemon/Requests/Makefile.in b/src/Daemon/Requests/Makefile.in
index 807904d..4cd6fe1 100644
--- a/src/Daemon/Requests/Makefile.in
+++ b/src/Daemon/Requests/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -210,6 +210,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = librequests.la
@@ -223,8 +224,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -301,7 +302,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Makefile.in b/src/Makefile.in
index 13da2ee..db34b93 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -254,6 +254,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = Common Client Core Daemon Net modules
@@ -283,8 +284,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -458,7 +459,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Net/FdManager.cpp b/src/Net/FdManager.cpp
index 5ff6647..ffa4d8b 100644
--- a/src/Net/FdManager.cpp
+++ b/src/Net/FdManager.cpp
@@ -22,7 +22,7 @@
#include <unistd.h>
#include <sys/fcntl.h>
-#include <sigc++/hide.h>
+#include <sigc++/adaptors/hide.h>
namespace Mad {
diff --git a/src/Net/Makefile.in b/src/Net/Makefile.in
index 8247f32..1fad631 100644
--- a/src/Net/Makefile.in
+++ b/src/Net/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -221,6 +221,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = Packets
@@ -236,8 +237,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -389,7 +390,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Net/Packet.h b/src/Net/Packet.h
index 2ec1634..daab921 100644
--- a/src/Net/Packet.h
+++ b/src/Net/Packet.h
@@ -37,7 +37,8 @@ class Packet {
STATUS = 0x0030, DAEMON_STATUS = 0x0031, FS_INFO = 0x0032, DAEMON_FS_INFO = 0x0033,
COMMAND_SHUTDOWN = 0x0040, COMMAND_REBOOT = 0x0041,
DAEMON_COMMAND_SHUTDOWN = 0x0050, DAEMON_COMMAND_REBOOT = 0x0051,
- DAEMON_STATE_UPDATE = 0x0060
+ DAEMON_STATE_UPDATE = 0x0060,
+ USERS_LIST = 0x0070
};
struct Data {
diff --git a/src/Net/Packets/Makefile.am b/src/Net/Packets/Makefile.am
index 311d9da..b8ebfc0 100644
--- a/src/Net/Packets/Makefile.am
+++ b/src/Net/Packets/Makefile.am
@@ -1,4 +1,4 @@
noinst_LTLIBRARIES = libpackets.la
-libpackets_la_SOURCES = ErrorPacket.cpp FSInfoPacket.cpp HostListPacket.cpp HostStatePacket.cpp HostStatusPacket.cpp LogPacket.cpp
+libpackets_la_SOURCES = ErrorPacket.cpp FSInfoPacket.cpp HostListPacket.cpp HostStatePacket.cpp HostStatusPacket.cpp LogPacket.cpp UserListPacket.cpp
-noinst_HEADERS = ErrorPacket.h FSInfoPacket.h HostListPacket.h HostStatePacket.h HostStatusPacket.h LogPacket.h
+noinst_HEADERS = ErrorPacket.h FSInfoPacket.h HostListPacket.h HostStatePacket.h HostStatusPacket.h LogPacket.h UserListPacket.h
diff --git a/src/Net/Packets/Makefile.in b/src/Net/Packets/Makefile.in
index b5c92c4..be59444 100644
--- a/src/Net/Packets/Makefile.in
+++ b/src/Net/Packets/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -52,7 +52,7 @@ LTLIBRARIES = $(noinst_LTLIBRARIES)
libpackets_la_LIBADD =
am_libpackets_la_OBJECTS = ErrorPacket.lo FSInfoPacket.lo \
HostListPacket.lo HostStatePacket.lo HostStatusPacket.lo \
- LogPacket.lo
+ LogPacket.lo UserListPacket.lo
libpackets_la_OBJECTS = $(am_libpackets_la_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/config/depcomp
@@ -212,11 +212,12 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
noinst_LTLIBRARIES = libpackets.la
-libpackets_la_SOURCES = ErrorPacket.cpp FSInfoPacket.cpp HostListPacket.cpp HostStatePacket.cpp HostStatusPacket.cpp LogPacket.cpp
-noinst_HEADERS = ErrorPacket.h FSInfoPacket.h HostListPacket.h HostStatePacket.h HostStatusPacket.h LogPacket.h
+libpackets_la_SOURCES = ErrorPacket.cpp FSInfoPacket.cpp HostListPacket.cpp HostStatePacket.cpp HostStatusPacket.cpp LogPacket.cpp UserListPacket.cpp
+noinst_HEADERS = ErrorPacket.h FSInfoPacket.h HostListPacket.h HostStatePacket.h HostStatusPacket.h LogPacket.h UserListPacket.h
all: all-am
.SUFFIXES:
@@ -225,8 +226,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -274,6 +275,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HostStatePacket.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/HostStatusPacket.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LogPacket.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/UserListPacket.Plo@am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@@ -307,7 +309,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/Net/Packets/UserListPacket.cpp b/src/Net/Packets/UserListPacket.cpp
new file mode 100644
index 0000000..d364522
--- /dev/null
+++ b/src/Net/Packets/UserListPacket.cpp
@@ -0,0 +1,85 @@
+/*
+ * UserListPacket.cpp
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "UserListPacket.h"
+#include <cstring>
+#include <sstream>
+
+namespace Mad {
+namespace Net {
+namespace Packets {
+
+void UserListPacket::assemblePacket() {
+ std::string str;
+
+ for(std::vector<Common::UserInfo>::iterator user = userList.begin(); user != userList.end(); ++user)
+ str += user->getUsername() + "\n" + user->getFullName() + "\n";
+
+ setLength(sizeof(uint16_t) + sizeof(UserData)*userList.size() + str.length());
+
+ nUsers = (uint16_t*)rawData->data;
+ userData = (UserData*)(rawData->data + sizeof(uint16_t));
+ charData = (char*)(rawData->data + sizeof(uint16_t) + sizeof(UserData)*userList.size());
+
+ std::memcpy(charData, str.c_str(), str.length());
+
+ *nUsers = htons(userList.size());
+
+ for(size_t i = 0; i < userList.size(); ++i) {
+ userData[i].uid = htons((uint32_t)userList[i].getUid());
+ userData[i].gid = htons((uint32_t)userList[i].getGid());
+ }
+}
+
+void UserListPacket::parsePacket() {
+ userList.clear();
+
+ if(getLength() < sizeof(uint16_t))
+ return;
+
+ nUsers = (uint16_t*)rawData->data;
+ userList.resize(ntohs(*nUsers));
+
+ if(getLength() < sizeof(uint16_t) + sizeof(UserData)*userList.size())
+ setLength(sizeof(uint16_t) + sizeof(UserData)*userList.size());
+
+ nUsers = (uint16_t*)rawData->data;
+ userData = (UserData*)(rawData->data + sizeof(uint16_t));
+ charData = (char*)(rawData->data + sizeof(uint16_t) + sizeof(UserData)*userList.size());
+
+ std::istringstream stream(std::string(charData, getLength() - (sizeof(uint16_t)+sizeof(UserData)*userList.size())));
+
+ for(size_t i = 0; i < userList.size(); ++i) {
+ userList[i].setUid(ntohs(userData[i].uid));
+ userList[i].setGid(ntohs(userData[i].gid));
+
+ if(!stream.eof()) {
+ std::string str;
+
+ std::getline(stream, str);
+ userList[i].setUsername(str);
+ std::getline(stream, str);
+ userList[i].setFullName(str);
+ }
+ }
+}
+
+}
+}
+}
diff --git a/src/Net/Packets/UserListPacket.h b/src/Net/Packets/UserListPacket.h
new file mode 100644
index 0000000..d099fab
--- /dev/null
+++ b/src/Net/Packets/UserListPacket.h
@@ -0,0 +1,79 @@
+/*
+ * UserListPacket.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_NET_PACKETS_USERLISTPACKET_H_
+#define MAD_NET_PACKETS_USERLISTPACKET_H_
+
+#include "../Packet.h"
+#include <Common/UserInfo.h>
+#include <vector>
+
+namespace Mad {
+namespace Net {
+namespace Packets {
+
+class UserListPacket : public Packet {
+ protected:
+ struct UserData {
+ uint32_t uid;
+ uint32_t gid;
+ };
+
+ uint16_t *nUsers;
+ UserData *userData;
+ char *charData;
+
+ std::vector<Common::UserInfo> userList;
+
+ void assemblePacket();
+ void parsePacket();
+
+ public:
+ UserListPacket(Type type, uint16_t requestId, const std::vector<Common::UserInfo> &users) : Packet(type, requestId), userList(users) {
+ assemblePacket();
+ }
+
+ UserListPacket(const Packet &p) : Packet(p) {
+ parsePacket();
+ }
+
+ UserListPacket& operator=(const Packet &p) {
+ Packet::operator=(p);
+ parsePacket();
+
+ return *this;
+ }
+
+ UserListPacket& operator=(const UserListPacket &p) {
+ Packet::operator=(p);
+ parsePacket();
+
+ return *this;
+ }
+
+ const std::vector<Common::UserInfo>& getUserInfo() const {
+ return userList;
+ }
+};
+
+}
+}
+}
+
+#endif /* MAD_NET_PACKETS_USERLISTPACKET_H_ */
diff --git a/src/mad-core.conf b/src/mad-core.conf
index 7a54a41..8f84278 100644
--- a/src/mad-core.conf
+++ b/src/mad-core.conf
@@ -10,6 +10,23 @@ X509TrustFile ../Cert/ca-cert.pem
X509CertFile ../Cert/cert.pem
X509KeyFile ../Cert/key.pem
+UserBackendMysql {
+ Username test
+ Password test
+ Database test
+
+ Queries {
+ ListUsers "SELECT id, gid, username, fullname FROM users"
+ #ListGroups
+ #ListUserGroups
+ #ListGroupUsers
+ #UserById
+ #UserByName
+ #GroupById
+ #GroupByName
+ }
+}
+
Daemon test {
IpAddress 127.0.0.1
}
diff --git a/src/mad-core.cpp b/src/mad-core.cpp
index 0bc8909..d5693ea 100644
--- a/src/mad-core.cpp
+++ b/src/mad-core.cpp
@@ -41,6 +41,8 @@ int main() {
Common::ModuleManager::get()->loadModule("SystemBackendPosix");
Common::ModuleManager::get()->loadModule("SystemBackendProc");
+ Common::ModuleManager::get()->loadModule("UserBackendMysql");
+
Common::ConfigManager::get()->loadFile("mad-core.conf");
Common::ConfigManager::get()->finish();
diff --git a/src/modules/Makefile.am b/src/modules/Makefile.am
index 67a82b8..ee11f5c 100644
--- a/src/modules/Makefile.am
+++ b/src/modules/Makefile.am
@@ -34,4 +34,4 @@ UserBackendMysql_la_SOURCES = UserBackendMysql.cpp
UserBackendMysql_la_LIBADD = $(MYSQL_LDFLAGS)
UserBackendMysql_la_LDFLAGS = $(default_ldflags) -export-symbols-regex '^UserBackendMysql_LTX_'
-noinst_HEADERS = SystemBackendPosix.h SystemBackendProc.h UserBackendMysql.h
+noinst_HEADERS = FileLogger.h SystemBackendPosix.h SystemBackendProc.h UserBackendMysql.h
diff --git a/src/modules/Makefile.in b/src/modules/Makefile.in
index f396b8d..294f1d3 100644
--- a/src/modules/Makefile.in
+++ b/src/modules/Makefile.in
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# Makefile.in generated by automake 1.10.2 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -250,6 +250,7 @@ srcdir = @srcdir@
sys_symbol_underscore = @sys_symbol_underscore@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
moddir = ${pkglibdir}/modules
@@ -268,7 +269,7 @@ SystemBackendProc_la_LDFLAGS = $(static_ldflags) -export-symbols-regex '^SystemB
UserBackendMysql_la_SOURCES = UserBackendMysql.cpp
UserBackendMysql_la_LIBADD = $(MYSQL_LDFLAGS)
UserBackendMysql_la_LDFLAGS = $(default_ldflags) -export-symbols-regex '^UserBackendMysql_LTX_'
-noinst_HEADERS = SystemBackendPosix.h SystemBackendProc.h UserBackendMysql.h
+noinst_HEADERS = FileLogger.h SystemBackendPosix.h SystemBackendProc.h UserBackendMysql.h
all: all-am
.SUFFIXES:
@@ -277,8 +278,8 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
- cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
- && exit 0; \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
@@ -390,7 +391,7 @@ ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
- $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in files) print i; }; }'`; \
mkid -fID $$unique
tags: TAGS
diff --git a/src/modules/SystemBackendPosix.h b/src/modules/SystemBackendPosix.h
index bbf1941..a307f22 100644
--- a/src/modules/SystemBackendPosix.h
+++ b/src/modules/SystemBackendPosix.h
@@ -27,8 +27,8 @@
#include <vector>
#include <sys/types.h>
-#include <sigc++/signal.h>
-#include <sigc++/hide.h>
+#include <sigc++/slot.h>
+#include <sigc++/adaptors/hide.h>
namespace Mad {
namespace Modules {
diff --git a/src/modules/UserBackendMysql.cpp b/src/modules/UserBackendMysql.cpp
index e5818c6..886f345 100644
--- a/src/modules/UserBackendMysql.cpp
+++ b/src/modules/UserBackendMysql.cpp
@@ -18,7 +18,13 @@
*/
#include "UserBackendMysql.h"
+#include <Common/ActionManager.h>
#include <Common/ConfigEntry.h>
+#include <Common/Logger.h>
+
+#include <sigc++/bind.h>
+
+#include <cstdlib>
#define init UserBackendMysql_LTX_init
#define deinit UserBackendMysql_LTX_deinit
@@ -44,12 +50,29 @@ bool UserBackendMysql::handleConfigEntry(const Common::ConfigEntry &entry, bool
}
else if(entry[1].getKey().matches("Password")) {
if(entry[2].empty())
- password = entry[1][0];
+ passwd = entry[1][0];
}
else if(entry[1].getKey().matches("Database")) {
if(entry[2].empty())
db = entry[1][0];
}
+ else if(entry[1].getKey().matches("Port")) {
+ if(entry[2].empty()) {
+ char *endptr;
+ long val;
+
+ val = std::strtol(entry[1][0].c_str(), &endptr, 10);
+
+ if(endptr != 0 || val < 0 || val > 65535)
+ Common::Logger::log(Common::Logger::WARNING, "UserBackendMysql: Invalid port");
+ else
+ port = val;
+ }
+ }
+ else if(entry[1].getKey().matches("UnixSocket")) {
+ if(entry[2].empty())
+ unixSocket = entry[1][0];
+ }
else if(entry[1].getKey().matches("Queries")) {
if(entry[2].getKey().matches("ListUsers")) {
if(entry[3].empty())
@@ -83,14 +106,85 @@ bool UserBackendMysql::handleConfigEntry(const Common::ConfigEntry &entry, bool
if(entry[3].empty())
queryGroupByName = entry[2][0];
}
+ else if(!entry[2].empty())
+ return false;
}
+ else if(!entry[1].empty())
+ return false;
+
+ return true;
}
+
+ return false;
}
void UserBackendMysql::configFinished() {
+ if(db.empty()) {
+ Common::Logger::log(Common::Logger::ERROR, "UserBackendMysql: No database name given");
+ return;
+ }
+
+ mysql = mysql_init(0);
+ mysql_real_connect(mysql, host.c_str(), username.c_str(), passwd.c_str(), db.c_str(), port, unixSocket.empty() ? 0 : unixSocket.c_str(), 0);
+
UserBackend::registerBackend(backend);
}
+
+bool UserBackendMysql::userList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback) {
+ mysql_ping(mysql);
+
+ mysql_real_query(mysql, queryListUsers.c_str(), queryListUsers.length());
+ MYSQL_RES *result = mysql_use_result(mysql);
+
+ if(mysql_num_fields(result) < 4)
+ return true; // TODO Error
+
+ std::map<unsigned long, Common::UserInfo> users;
+
+ MYSQL_ROW row;
+ while(MYSQL_ROW row = mysql_fetch_row(result)) {
+ Common::UserInfo user(std::strtoul(row[0], 0, 10), row[2]);
+
+ user.setGid(std::strtoul(row[1], 0, 10));
+ user.setFullName(row[3]);
+
+ users.insert(std::make_pair(user.getUid(), user));
+ }
+
+ Common::ActionManager::get()->add(sigc::bind(callback, users));
+
+ return true;
+}
+
+bool UserBackendMysql::userInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback) {
+ return false;
+}
+
+bool UserBackendMysql::password(unsigned long uid, const std::string &password, const sigc::slot<void, bool> &callback) {
+ return false;
+}
+
+
+void UserBackendMysql::registerBackend() {
+ if(backend)
+ return;
+
+ backend = new UserBackendMysql();
+ Common::ConfigManager::get()->registerConfigurable(backend);
+}
+
+void UserBackendMysql::unregisterBackend() {
+ if(!backend)
+ return;
+
+ Common::ConfigManager::get()->unregisterConfigurable(backend);
+ UserBackend::unregisterBackend(backend);
+
+ delete backend;
+ backend = 0;
+}
+
}
}
diff --git a/src/modules/UserBackendMysql.h b/src/modules/UserBackendMysql.h
index 85a25ee..60b2bd9 100644
--- a/src/modules/UserBackendMysql.h
+++ b/src/modules/UserBackendMysql.h
@@ -24,6 +24,8 @@
#include <Common/Configurable.h>
#include <Common/ConfigManager.h>
+#include <mysql/mysql.h>
+
namespace Mad {
namespace Modules {
@@ -32,37 +34,36 @@ class UserBackendMysql : private Core::UserBackend, private Common::Configurable
private:
static UserBackendMysql *backend;
- std::string host, username, password, db;
+ std::string host, username, passwd, db, unixSocket;
+ uint16_t port;
std::string queryListUsers, queryListGroups;
std::string queryListUserGroups, queryListGroupUsers;
std::string queryUserById, queryUserByName;
std::string queryGroupById, queryGroupByName;
- UserBackendMysql() {}
+ MYSQL *mysql;
+
+ UserBackendMysql() : port(0), mysql(0) {}
protected:
virtual bool handleConfigEntry(const Common::ConfigEntry &entry, bool);
virtual void configFinished();
- public:
- static void registerBackend() {
- if(backend)
- return;
+ virtual bool userList(const sigc::slot<void, const std::map<unsigned long, Common::UserInfo>& > &callback);
+ virtual bool userInfo(unsigned long uid, const sigc::slot<void, const Common::UserInfo&> &callback);
+ virtual bool password(unsigned long uid, const std::string &password, const sigc::slot<void, bool> &callback);
- backend = new UserBackendMysql();
- Common::ConfigManager::get()->registerConfigurable(backend);
+ public:
+ virtual ~UserBackendMysql() {
+ if(mysql) {
+ mysql_close(mysql);
+ mysql = 0;
+ }
}
- static void unregisterBackend() {
- if(!backend)
- return;
-
- Common::ConfigManager::get()->unregisterConfigurable(backend);
- UserBackend::unregisterBackend(backend);
- delete backend;
- backend = 0;
- }
+ static void registerBackend();
+ static void unregisterBackend();
};
}