better submodules integration (hope =))

add --session support to the helper
This commit is contained in:
arcan1s
2014-08-27 17:23:12 +04:00
parent 0c7868536a
commit b909222db9
13 changed files with 68 additions and 24 deletions

View File

@ -25,6 +25,7 @@ _netctlgui_helper_arglist=(
'--nodaemon'
'--replace'
'--restore'
'--session'
'--system'
'-v'
'--version'

View File

@ -23,6 +23,8 @@ do not run as daemon
force replace the existing session
.IP "--restore"
force restore the existing session
.IP "--session"
force create user DBus session
.IP "--system"
do not read user configuration
.IP "-v, --version"

View File

@ -1,9 +1,12 @@
[Unit]
Description=netctlgui-helper daemon
Documentation=man:netctlgui-helper(1) man:netctl-gui.conf(5)
[Service]
Type=forking
ExecStart=/usr/bin/netctlgui-helper --system
Type=dbus
BusName=org.netctlgui.helper
ExecStart=/usr/bin/netctlgui-helper --nodaemon --system
Capabilities=CAP_SETUID
[Install]
WantedBy=multi-user.target

View File

@ -47,14 +47,14 @@ else ()
set (TRANSLATIONS_BINARY ${TRANSLATIONS_BINARY} ${QM})
add_custom_command (OUTPUT ${QM} COMMAND ${QT_LRELEASE_EXECUTABLE} ${TS} MAIN_DEPENDENCY ${TS})
endforeach ()
add_custom_target (translations-header COMMAND ${QT_LUPDATE_EXECUTABLE} ${HEADERS} ${SOURCES} -ts ${TRANSLATIONS})
add_custom_command (TARGET translations-header COMMAND ${QT_LRELEASE_EXECUTABLE} ${TRANSLATIONS})
add_custom_target (translations-helper COMMAND ${QT_LUPDATE_EXECUTABLE} ${HEADERS} ${SOURCES} -ts ${TRANSLATIONS})
add_custom_command (TARGET translations-helper COMMAND ${QT_LRELEASE_EXECUTABLE} ${TRANSLATIONS})
endif()
add_executable (${SUBPROJECT} ${SOURCES} ${HEADERS} ${MOC_SOURCES} ${QRC_SOURCES} ${TRANSLATIONS})
target_link_libraries (${SUBPROJECT} ${PROJECT_LIBRARY} ${QT_NEEDED_LIBS})
# install properties
install (TARGETS ${SUBPROJECT} DESTINATION bin)
if (USE_CAPABILITIES)
install (CODE "exec_program (setcap ARGS \"cap_setuid=ep\" \"$ENV{DESTDIR}/bin/${SUBPROJECT}\")")
endif ()
# if (USE_CAPABILITIES)
# install (CODE "exec_program (setcap ARGS \"cap_setuid=ep\" \"$ENV{DESTDIR}/bin/${SUBPROJECT}\")")
# endif ()

View File

@ -68,6 +68,9 @@ int main(int argc, char *argv[])
} else if (QString(argv[i]) == QString("--restore")) {
// restore
args[QString("state")] = (int) 2;
} else if (QString(argv[i]) == QString("--session")) {
// session
args[QString("session")] = true;
} else if (QString(argv[i]) == QString("--system")) {
// system
args[QString("system")] = true;
@ -96,6 +99,7 @@ int main(int argc, char *argv[])
.arg(QString::number(geteuid())).toUtf8().data() << endl;
cout << QCoreApplication::translate("NetctlHelper", "See security notes for more details.")
.toUtf8().data() << endl;
args[QString("session")] = true;
}
#if QT_VERSION >= 0x050000

View File

@ -37,6 +37,7 @@ QMap<QString, QVariant> getArgs()
args[QString("config")] = QString(QDir::homePath() + QString("/.config/netctl-gui.conf"));
args[QString("debug")] = false;
args[QString("nodaemon")] = false;
args[QString("session")] = false;
args[QString("state")] = (int) 0;
args[QString("system")] = false;
args[QString("help")] = false;
@ -65,6 +66,8 @@ QString helpMessage()
.arg(QCoreApplication::translate("NetctlHelper", "force replace the existing session"));
helpMessage += QString(" --restore - %1\n")
.arg(QCoreApplication::translate("NetctlHelper", "force restore the existing session"));
helpMessage += QString(" --session - %1\n")
.arg(QCoreApplication::translate("NetctlHelper", "force create user DBus session"));
helpMessage += QString(" --system - %1\n")
.arg(QCoreApplication::translate("NetctlHelper", "do not read user configuration, system-wide only"));
helpMessage += QString(" %1\n").arg(QCoreApplication::translate("NetctlHelper", "Show messages:"));

View File

@ -35,6 +35,7 @@ NetctlHelper::NetctlHelper(QObject *parent, QMap<QString, QVariant> args)
: QObject(parent),
configPath(args[QString("config")].toString()),
debug(args[QString("debug")].toBool()),
session(args[QString("session")].toBool()),
system(args[QString("system")].toBool())
{
updateConfiguration();
@ -88,6 +89,28 @@ void NetctlHelper::createInterface()
if (debug) qDebug() << PDEBUG << ":" << bus.lastError().message();
return quitHelper();
}
// session bus
if (!session) return;
QDBusConnection sessionBus = QDBusConnection::sessionBus();
if (!sessionBus.registerService(DBUS_HELPER_SERVICE)) {
if (debug) qDebug() << PDEBUG << ":" << "Could not register session service";
if (debug) qDebug() << PDEBUG << ":" << sessionBus.lastError().message();
return quitHelper();
}
if (!sessionBus.registerObject(DBUS_LIB_PATH,
new NetctlAdaptor(this, debug, configuration),
QDBusConnection::ExportAllContents)) {
if (debug) qDebug() << PDEBUG << ":" << "Could not register session library object";
if (debug) qDebug() << PDEBUG << ":" << sessionBus.lastError().message();
return quitHelper();
}
if (!sessionBus.registerObject(DBUS_CTRL_PATH,
new ControlAdaptor(this, debug, configuration),
QDBusConnection::ExportAllContents)) {
if (debug) qDebug() << PDEBUG << ":" << "Could not register session control object";
if (debug) qDebug() << PDEBUG << ":" << sessionBus.lastError().message();
return quitHelper();
}
}
@ -98,6 +121,11 @@ void NetctlHelper::deleteInterface()
QDBusConnection::systemBus().unregisterObject(DBUS_LIB_PATH);
QDBusConnection::systemBus().unregisterObject(DBUS_CTRL_PATH);
QDBusConnection::systemBus().unregisterService(DBUS_HELPER_SERVICE);
// session bus
if (!session) return;
QDBusConnection::sessionBus().unregisterObject(DBUS_LIB_PATH);
QDBusConnection::sessionBus().unregisterObject(DBUS_CTRL_PATH);
QDBusConnection::sessionBus().unregisterService(DBUS_HELPER_SERVICE);
}

View File

@ -41,6 +41,7 @@ private:
QString configPath;
QMap<QString, QString> configuration;
bool debug;
bool session;
bool system;
void createInterface();
void deleteInterface();

View File

@ -24,6 +24,7 @@ _netctlgui_helper_arglist=(
{'--nodaemon','--nodaemon'}'[do not start as daemon]'
{'--replace','--replace'}'[force replace the existing session]'
{'--restore','--restore'}'[force restore the existing session]'
{'--session','--session'}'[force create user DBus session]'
{'--system','--system'}'[do not read user configuration]'
{'(--version)-v','(-v)--version'}'[show version and exit]'
{'(--info)-i','(-i)--info'}'[show build information and exit]'