diff options
author | Michael Biebl <biebl@debian.org> | 2009-07-14 17:40:43 +0200 |
---|---|---|
committer | Michael Biebl <biebl@debian.org> | 2009-07-14 17:40:43 +0200 |
commit | b4c56fb4b5f0c496b544080c5dd38d3cf93c10e8 (patch) | |
tree | a042dc877254104c83167421a65a61bf7492885c /libck-connector | |
download | consolekit-b4c56fb4b5f0c496b544080c5dd38d3cf93c10e8.tar.gz |
Imported Upstream version 0.2.1upstream/0.2.1
Diffstat (limited to 'libck-connector')
-rw-r--r-- | libck-connector/Makefile.am | 62 | ||||
-rw-r--r-- | libck-connector/Makefile.in | 634 | ||||
-rw-r--r-- | libck-connector/ck-connector.c | 691 | ||||
-rw-r--r-- | libck-connector/ck-connector.h | 64 | ||||
-rw-r--r-- | libck-connector/ck-connector.pc.in | 11 | ||||
-rw-r--r-- | libck-connector/test-connector.c | 101 |
6 files changed, 1563 insertions, 0 deletions
diff --git a/libck-connector/Makefile.am b/libck-connector/Makefile.am new file mode 100644 index 0000000..757c41e --- /dev/null +++ b/libck-connector/Makefile.am @@ -0,0 +1,62 @@ +NULL = + +INCLUDES = \ + -I. \ + $(LIBDBUS_CFLAGS) \ + $(NULL) + +lib_LTLIBRARIES = \ + libck-connector.la \ + $(NULL) + +libck_connectorincludedir = $(includedir)/ConsoleKit/ck-connector + +libck_connectorinclude_HEADERS = \ + ck-connector.h \ + $(NULL) + +libck_connector_la_SOURCES = \ + ck-connector.c \ + ck-connector.h \ + $(NULL) + +noinst_PROGRAMS = \ + test-connector \ + $(NULL) + +test_connector_SOURCES = \ + test-connector.c \ + $(NULL) + + +test_connector_LDADD = \ + $(top_builddir)/libck-connector/libck-connector.la \ + $(LIBDBUS_LIBS) \ + $(NULL) + +# soname management for libck-connector +LIBCKCON_LT_CURRENT=0 +LIBCKCON_LT_REVISION=0 +LIBCKCON_LT_AGE=0 + +libck_connector_la_LIBADD = \ + $(LIBDBUS_LIBS) \ + $(NULL) + +libck_connector_la_LDFLAGS = \ + -version-info $(LIBCKCON_LT_CURRENT):$(LIBCKCON_LT_REVISION):$(LIBCKCON_LT_AGE) \ + $(NULL) + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = ck-connector.pc + +EXTRA_DIST = \ + ck-connector.pc.in \ + $(NULL) + +MAINTAINERCLEANFILES = \ + *~ \ + Makefile.in + +clean-local: + rm -f *~ diff --git a/libck-connector/Makefile.in b/libck-connector/Makefile.in new file mode 100644 index 0000000..7bd22f1 --- /dev/null +++ b/libck-connector/Makefile.in @@ -0,0 +1,634 @@ +# Makefile.in generated by automake 1.9.6 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +# 2003, 2004, 2005 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + + + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +noinst_PROGRAMS = test-connector$(EXEEXT) $(am__EXEEXT_1) +subdir = libck-connector +DIST_COMMON = $(libck_connectorinclude_HEADERS) $(srcdir)/Makefile.am \ + $(srcdir)/Makefile.in $(srcdir)/ck-connector.pc.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = ck-connector.pc +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = `echo $$p | sed -e 's|^.*/||'`; +am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgconfigdir)" \ + "$(DESTDIR)$(libck_connectorincludedir)" +libLTLIBRARIES_INSTALL = $(INSTALL) +LTLIBRARIES = $(lib_LTLIBRARIES) +am__DEPENDENCIES_1 = +libck_connector_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) +am__objects_1 = +am_libck_connector_la_OBJECTS = ck-connector.lo $(am__objects_1) +libck_connector_la_OBJECTS = $(am_libck_connector_la_OBJECTS) +am__EXEEXT_1 = +PROGRAMS = $(noinst_PROGRAMS) +am_test_connector_OBJECTS = test-connector.$(OBJEXT) $(am__objects_1) +test_connector_OBJECTS = $(am_test_connector_OBJECTS) +test_connector_DEPENDENCIES = \ + $(top_builddir)/libck-connector/libck-connector.la \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__depfiles_maybe = depfiles +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SOURCES = $(libck_connector_la_SOURCES) $(test_connector_SOURCES) +DIST_SOURCES = $(libck_connector_la_SOURCES) $(test_connector_SOURCES) +pkgconfigDATA_INSTALL = $(INSTALL_DATA) +DATA = $(pkgconfig_DATA) +libck_connectorincludeHEADERS_INSTALL = $(INSTALL_HEADER) +HEADERS = $(libck_connectorinclude_HEADERS) +ETAGS = etags +CTAGS = ctags +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMDEP_FALSE = @AMDEP_FALSE@ +AMDEP_TRUE = @AMDEP_TRUE@ +AMTAR = @AMTAR@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CATALOGS = @CATALOGS@ +CATOBJEXT = @CATOBJEXT@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CK_BACKEND = @CK_BACKEND@ +CK_COMPILE_FREEBSD_FALSE = @CK_COMPILE_FREEBSD_FALSE@ +CK_COMPILE_FREEBSD_TRUE = @CK_COMPILE_FREEBSD_TRUE@ +CK_COMPILE_LINUX_FALSE = @CK_COMPILE_LINUX_FALSE@ +CK_COMPILE_LINUX_TRUE = @CK_COMPILE_LINUX_TRUE@ +CK_COMPILE_SOLARIS_FALSE = @CK_COMPILE_SOLARIS_FALSE@ +CK_COMPILE_SOLARIS_TRUE = @CK_COMPILE_SOLARIS_TRUE@ +CONSOLE_KIT_CFLAGS = @CONSOLE_KIT_CFLAGS@ +CONSOLE_KIT_LIBS = @CONSOLE_KIT_LIBS@ +CONSOLE_KIT_PID_FILE = @CONSOLE_KIT_PID_FILE@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DATADIRNAME = @DATADIRNAME@ +DBUS_CFLAGS = @DBUS_CFLAGS@ +DBUS_SYS_DIR = @DBUS_SYS_DIR@ +DEBUG_CFLAGS = @DEBUG_CFLAGS@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DOCBOOK_DOCS_ENABLED_FALSE = @DOCBOOK_DOCS_ENABLED_FALSE@ +DOCBOOK_DOCS_ENABLED_TRUE = @DOCBOOK_DOCS_ENABLED_TRUE@ +ECHO = @ECHO@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +ENABLE_INOTIFY_FALSE = @ENABLE_INOTIFY_FALSE@ +ENABLE_INOTIFY_TRUE = @ENABLE_INOTIFY_TRUE@ +ENABLE_PAM_MODULE_FALSE = @ENABLE_PAM_MODULE_FALSE@ +ENABLE_PAM_MODULE_TRUE = @ENABLE_PAM_MODULE_TRUE@ +EXEEXT = @EXEEXT@ +F77 = @F77@ +FFLAGS = @FFLAGS@ +GETTEXT_PACKAGE = @GETTEXT_PACKAGE@ +GLIB_GENMARSHAL = @GLIB_GENMARSHAL@ +GMOFILES = @GMOFILES@ +GMSGFMT = @GMSGFMT@ +GREP = @GREP@ +HAVE_PAM = @HAVE_PAM@ +HAVE_PAM_FALSE = @HAVE_PAM_FALSE@ +HAVE_PAM_TRUE = @HAVE_PAM_TRUE@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +INSTOBJEXT = @INSTOBJEXT@ +INTLLIBS = @INTLLIBS@ +LDFLAGS = @LDFLAGS@ +LIBDBUS_CFLAGS = @LIBDBUS_CFLAGS@ +LIBDBUS_LIBS = @LIBDBUS_LIBS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +MAINT = @MAINT@ +MAINTAINER_MODE_FALSE = @MAINTAINER_MODE_FALSE@ +MAINTAINER_MODE_TRUE = @MAINTAINER_MODE_TRUE@ +MAKEINFO = @MAKEINFO@ +MKINSTALLDIRS = @MKINSTALLDIRS@ +MSGFMT = @MSGFMT@ +MSGFMT_OPTS = @MSGFMT_OPTS@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PAM_LIBS = @PAM_LIBS@ +PAM_MODULE_DIR = @PAM_MODULE_DIR@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PKG_CONFIG = @PKG_CONFIG@ +POFILES = @POFILES@ +POSUB = @POSUB@ +PO_IN_DATADIR_FALSE = @PO_IN_DATADIR_FALSE@ +PO_IN_DATADIR_TRUE = @PO_IN_DATADIR_TRUE@ +RANLIB = @RANLIB@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TOOLS_CFLAGS = @TOOLS_CFLAGS@ +TOOLS_LIBS = @TOOLS_LIBS@ +USE_NLS = @USE_NLS@ +VERSION = @VERSION@ +WARN_CFLAGS = @WARN_CFLAGS@ +XGETTEXT = @XGETTEXT@ +XMLTO = @XMLTO@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_CXX = @ac_ct_CXX@ +ac_ct_F77 = @ac_ct_F77@ +am__fastdepCC_FALSE = @am__fastdepCC_FALSE@ +am__fastdepCC_TRUE = @am__fastdepCC_TRUE@ +am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@ +am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +NULL = +INCLUDES = \ + -I. \ + $(LIBDBUS_CFLAGS) \ + $(NULL) + +lib_LTLIBRARIES = \ + libck-connector.la \ + $(NULL) + +libck_connectorincludedir = $(includedir)/ConsoleKit/ck-connector +libck_connectorinclude_HEADERS = \ + ck-connector.h \ + $(NULL) + +libck_connector_la_SOURCES = \ + ck-connector.c \ + ck-connector.h \ + $(NULL) + +test_connector_SOURCES = \ + test-connector.c \ + $(NULL) + +test_connector_LDADD = \ + $(top_builddir)/libck-connector/libck-connector.la \ + $(LIBDBUS_LIBS) \ + $(NULL) + + +# soname management for libck-connector +LIBCKCON_LT_CURRENT = 0 +LIBCKCON_LT_REVISION = 0 +LIBCKCON_LT_AGE = 0 +libck_connector_la_LIBADD = \ + $(LIBDBUS_LIBS) \ + $(NULL) + +libck_connector_la_LDFLAGS = \ + -version-info $(LIBCKCON_LT_CURRENT):$(LIBCKCON_LT_REVISION):$(LIBCKCON_LT_AGE) \ + $(NULL) + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = ck-connector.pc +EXTRA_DIST = \ + ck-connector.pc.in \ + $(NULL) + +MAINTAINERCLEANFILES = \ + *~ \ + Makefile.in + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ + && exit 0; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu libck-connector/Makefile'; \ + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu libck-connector/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +ck-connector.pc: $(top_builddir)/config.status $(srcdir)/ck-connector.pc.in + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ +install-libLTLIBRARIES: $(lib_LTLIBRARIES) + @$(NORMAL_INSTALL) + test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)" + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + if test -f $$p; then \ + f=$(am__strip_dir) \ + echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \ + $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \ + else :; fi; \ + done + +uninstall-libLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @set -x; list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + p=$(am__strip_dir) \ + echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \ + $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \ + done + +clean-libLTLIBRARIES: + -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES) + @list='$(lib_LTLIBRARIES)'; for p in $$list; do \ + dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ + test "$$dir" != "$$p" || dir=.; \ + echo "rm -f \"$${dir}/so_locations\""; \ + rm -f "$${dir}/so_locations"; \ + done +libck-connector.la: $(libck_connector_la_OBJECTS) $(libck_connector_la_DEPENDENCIES) + $(LINK) -rpath $(libdir) $(libck_connector_la_LDFLAGS) $(libck_connector_la_OBJECTS) $(libck_connector_la_LIBADD) $(LIBS) + +clean-noinstPROGRAMS: + @list='$(noinst_PROGRAMS)'; for p in $$list; do \ + f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f $$p $$f"; \ + rm -f $$p $$f ; \ + done +test-connector$(EXEEXT): $(test_connector_OBJECTS) $(test_connector_DEPENDENCIES) + @rm -f test-connector$(EXEEXT) + $(LINK) $(test_connector_LDFLAGS) $(test_connector_OBJECTS) $(test_connector_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ck-connector.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-connector.Po@am__quote@ + +.c.o: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c $< + +.c.obj: +@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +install-pkgconfigDATA: $(pkgconfig_DATA) + @$(NORMAL_INSTALL) + test -z "$(pkgconfigdir)" || $(mkdir_p) "$(DESTDIR)$(pkgconfigdir)" + @list='$(pkgconfig_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(pkgconfigDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(pkgconfigdir)/$$f'"; \ + $(pkgconfigDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(pkgconfigdir)/$$f"; \ + done + +uninstall-pkgconfigDATA: + @$(NORMAL_UNINSTALL) + @list='$(pkgconfig_DATA)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(pkgconfigdir)/$$f'"; \ + rm -f "$(DESTDIR)$(pkgconfigdir)/$$f"; \ + done +install-libck_connectorincludeHEADERS: $(libck_connectorinclude_HEADERS) + @$(NORMAL_INSTALL) + test -z "$(libck_connectorincludedir)" || $(mkdir_p) "$(DESTDIR)$(libck_connectorincludedir)" + @list='$(libck_connectorinclude_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f=$(am__strip_dir) \ + echo " $(libck_connectorincludeHEADERS_INSTALL) '$$d$$p' '$(DESTDIR)$(libck_connectorincludedir)/$$f'"; \ + $(libck_connectorincludeHEADERS_INSTALL) "$$d$$p" "$(DESTDIR)$(libck_connectorincludedir)/$$f"; \ + done + +uninstall-libck_connectorincludeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(libck_connectorinclude_HEADERS)'; for p in $$list; do \ + f=$(am__strip_dir) \ + echo " rm -f '$(DESTDIR)$(libck_connectorincludedir)/$$f'"; \ + rm -f "$(DESTDIR)$(libck_connectorincludedir)/$$f"; \ + done + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(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; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique +tags: TAGS + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(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; } \ + END { for (i in files) print i; }'`; \ + if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique; \ + fi +ctags: CTAGS +CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(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; } \ + END { for (i in files) print i; }'`; \ + test -z "$(CTAGS_ARGS)$$tags$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \ + list='$(DISTFILES)'; for file in $$list; do \ + case $$file in \ + $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \ + $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \ + esac; \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkdir_p) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(DATA) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgconfigdir)" "$(DESTDIR)$(libck_connectorincludedir)"; do \ + test -z "$$dir" || $(mkdir_p) "$$dir"; \ + done +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) +clean: clean-am + +clean-am: clean-generic clean-libLTLIBRARIES clean-libtool clean-local \ + clean-noinstPROGRAMS mostlyclean-am + +distclean: distclean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-libtool distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +info: info-am + +info-am: + +install-data-am: install-libck_connectorincludeHEADERS \ + install-pkgconfigDATA + +install-exec-am: install-libLTLIBRARIES + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -rf ./$(DEPDIR) + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: uninstall-info-am uninstall-libLTLIBRARIES \ + uninstall-libck_connectorincludeHEADERS \ + uninstall-pkgconfigDATA + +.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ + clean-libLTLIBRARIES clean-libtool clean-local \ + clean-noinstPROGRAMS ctags distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-exec install-exec-am \ + install-info install-info-am install-libLTLIBRARIES \ + install-libck_connectorincludeHEADERS install-man \ + install-pkgconfigDATA install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags uninstall uninstall-am uninstall-info-am \ + uninstall-libLTLIBRARIES \ + uninstall-libck_connectorincludeHEADERS \ + uninstall-pkgconfigDATA + + +clean-local: + rm -f *~ +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/libck-connector/ck-connector.c b/libck-connector/ck-connector.c new file mode 100644 index 0000000..34a8657 --- /dev/null +++ b/libck-connector/ck-connector.c @@ -0,0 +1,691 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * ck-connector.c : Code for login managers to register with ConsoleKit. + * + * Copyright (c) 2007 David Zeuthen <davidz@redhat.com> + * Copyright (c) 2007 William Jon McCann <mccann@jhu.edu> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> +#include <dbus/dbus.h> + +#include "ck-connector.h" + +#define N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0])) + +#if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +#define _CK_FUNCTION_NAME __func__ +#elif defined(__GNUC__) || defined(_MSC_VER) +#define _CK_FUNCTION_NAME __FUNCTION__ +#else +#define _CK_FUNCTION_NAME "unknown function" +#endif + +#define CK_CONNECTOR_ERROR "org.freedesktop.CkConnector.Error" + +#define _CK_WARNING_FORMAT "arguments to %s() were incorrect, assertion \"%s\" failed in file %s line %d.\n" +#define _ck_return_if_fail(condition) do { \ + if (!(condition)) { \ + fprintf (stderr, _CK_WARNING_FORMAT, _CK_FUNCTION_NAME, #condition, __FILE__, __LINE__); \ + return; \ + } } while (0) + +#define _ck_return_val_if_fail(condition, val) do { \ + if (!(condition)) { \ + fprintf (stderr, _CK_WARNING_FORMAT, _CK_FUNCTION_NAME, #condition, __FILE__, __LINE__); \ + return val; \ + } } while (0) + +struct _CkConnector +{ + int refcount; + char *cookie; + dbus_bool_t session_created; + DBusConnection *connection; +}; + +static struct { + char *name; + int type; +} parameter_lookup[] = { + { "display-device", DBUS_TYPE_STRING }, + { "x11-display-device", DBUS_TYPE_STRING }, + { "x11-display", DBUS_TYPE_STRING }, + { "remote-host-name", DBUS_TYPE_STRING }, + { "session-type", DBUS_TYPE_STRING }, + { "is-local", DBUS_TYPE_BOOLEAN }, + { "user", DBUS_TYPE_INT32 }, +}; + +static int +lookup_parameter_type (const char *name) +{ + int i; + int type; + + type = DBUS_TYPE_INVALID; + + for (i = 0; i < N_ELEMENTS (parameter_lookup); i++) { + if (strcmp (name, parameter_lookup[i].name) == 0) { + type = parameter_lookup[i].type; + break; + } + } + + return type; +} + +static dbus_bool_t +add_param_basic (DBusMessageIter *iter_array, + const char *name, + int type, + const void *value) +{ + DBusMessageIter iter_struct; + DBusMessageIter iter_variant; + const char *container_type; + + switch (type) { + case DBUS_TYPE_STRING: + container_type = DBUS_TYPE_STRING_AS_STRING; + break; + case DBUS_TYPE_BOOLEAN: + container_type = DBUS_TYPE_BOOLEAN_AS_STRING; + break; + case DBUS_TYPE_INT32: + container_type = DBUS_TYPE_INT32_AS_STRING; + break; + default: + goto oom; + break; + } + + if (! dbus_message_iter_open_container (iter_array, + DBUS_TYPE_STRUCT, + NULL, + &iter_struct)) { + goto oom; + } + + if (! dbus_message_iter_append_basic (&iter_struct, + DBUS_TYPE_STRING, + &name)) { + goto oom; + } + + if (! dbus_message_iter_open_container (&iter_struct, + DBUS_TYPE_VARIANT, + container_type, + &iter_variant)) { + goto oom; + } + + if (! dbus_message_iter_append_basic (&iter_variant, + type, + value)) { + goto oom; + } + + if (! dbus_message_iter_close_container (&iter_struct, + &iter_variant)) { + goto oom; + } + + if (! dbus_message_iter_close_container (iter_array, + &iter_struct)) { + goto oom; + } + + return TRUE; +oom: + return FALSE; +} + +/* Frees all resources allocated and disconnects from the system + * message bus. + */ +static void +_ck_connector_free (CkConnector *connector) +{ + if (connector->connection != NULL) { + /* it's a private connection so it's all good */ + dbus_connection_close (connector->connection); + } + + if (connector->cookie != NULL) { + free (connector->cookie); + } + + free (connector); +} + +/** + * Decrements the reference count of a CkConnector, disconnecting + * from the bus and freeing the connector if the count reaches 0. + * + * @param connector the connector + * @see ck_connector_ref + */ +void +ck_connector_unref (CkConnector *connector) +{ + _ck_return_if_fail (connector != NULL); + + /* Probably should use some kind of atomic op here */ + connector->refcount -= 1; + if (connector->refcount == 0) { + _ck_connector_free (connector); + } +} + +/** + * Increments the reference count of a CkConnector. + * + * @param connector the connector + * @returns the connector + * @see ck_connector_unref + */ +CkConnector * +ck_connector_ref (CkConnector *connector) +{ + _ck_return_val_if_fail (connector != NULL, NULL); + + /* Probably should use some kind of atomic op here */ + connector->refcount += 1; + + return connector; +} + +/** + * Constructs a new Connector to communicate with the ConsoleKit + * daemon. Returns #NULL if memory can't be allocated for the + * object. + * + * @returns a new CkConnector, free with ck_connector_unref() + */ +CkConnector * +ck_connector_new (void) +{ + CkConnector *connector; + + connector = calloc (1, sizeof (CkConnector)); + if (connector == NULL) { + goto oom; + } + + connector->refcount = 1; + connector->connection = NULL; + connector->cookie = NULL; + connector->session_created = FALSE; +oom: + return connector; +} + +/** + * Connects to the D-Bus system bus daemon and issues the method call + * OpenSession on the ConsoleKit manager interface. The + * connection to the bus is private. + * + * Returns FALSE on OOM, if the system bus daemon is not running, if + * the ConsoleKit daemon is not running or if the caller doesn't have + * sufficient privileges. + * + * @returns #TRUE if the operation succeeds + */ +dbus_bool_t +ck_connector_open_session (CkConnector *connector, + DBusError *error) +{ + DBusError local_error; + DBusMessage *message; + DBusMessage *reply; + dbus_bool_t ret; + char *cookie; + + _ck_return_val_if_fail (connector != NULL, FALSE); + _ck_return_val_if_fail ((error) == NULL || !dbus_error_is_set ((error)), FALSE); + + reply = NULL; + message = NULL; + ret = FALSE; + + dbus_error_init (&local_error); + connector->connection = dbus_bus_get_private (DBUS_BUS_SYSTEM, &local_error); + if (connector->connection == NULL) { + if (dbus_error_is_set (&local_error)) { + dbus_set_error (error, + CK_CONNECTOR_ERROR, + "Unable to open session: %s", + local_error.message); + dbus_error_free (&local_error); + } + + goto out; + } + + dbus_connection_set_exit_on_disconnect (connector->connection, FALSE); + + message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", + "/org/freedesktop/ConsoleKit/Manager", + "org.freedesktop.ConsoleKit.Manager", + "OpenSession"); + if (message == NULL) { + goto out; + } + + dbus_error_init (&local_error); + reply = dbus_connection_send_with_reply_and_block (connector->connection, + message, + -1, + &local_error); + if (reply == NULL) { + if (dbus_error_is_set (&local_error)) { + dbus_set_error (error, + CK_CONNECTOR_ERROR, + "Unable to open session: %s", + local_error.message); + dbus_error_free (&local_error); + goto out; + } + } + + dbus_error_init (&local_error); + if (! dbus_message_get_args (reply, + &local_error, + DBUS_TYPE_STRING, &cookie, + DBUS_TYPE_INVALID)) { + if (dbus_error_is_set (&local_error)) { + dbus_set_error (error, + CK_CONNECTOR_ERROR, + "Unable to open session: %s", + local_error.message); + dbus_error_free (&local_error); + goto out; + } + } + + connector->cookie = strdup (cookie); + if (connector->cookie == NULL) { + goto out; + } + + connector->session_created = TRUE; + ret = TRUE; + +out: + if (reply != NULL) { + dbus_message_unref (reply); + } + + if (message != NULL) { + dbus_message_unref (message); + } + + return ret; +} + +static dbus_bool_t +ck_connector_open_session_with_parameters_valist (CkConnector *connector, + DBusError *error, + const char *first_parameter_name, + va_list var_args) +{ + DBusError local_error; + DBusMessage *message; + DBusMessage *reply; + DBusMessageIter iter; + DBusMessageIter iter_array; + dbus_bool_t ret; + char *cookie; + const char *name; + + _ck_return_val_if_fail (connector != NULL, FALSE); + + reply = NULL; + message = NULL; + ret = FALSE; + + dbus_error_init (&local_error); + connector->connection = dbus_bus_get_private (DBUS_BUS_SYSTEM, &local_error); + if (connector->connection == NULL) { + if (dbus_error_is_set (&local_error)) { + dbus_set_error (error, + CK_CONNECTOR_ERROR, + "Unable to open session: %s", + local_error.message); + dbus_error_free (&local_error); + } + goto out; + } + + dbus_connection_set_exit_on_disconnect (connector->connection, FALSE); + + message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", + "/org/freedesktop/ConsoleKit/Manager", + "org.freedesktop.ConsoleKit.Manager", + "OpenSessionWithParameters"); + if (message == NULL) { + goto out; + } + + dbus_message_iter_init_append (message, &iter); + if (! dbus_message_iter_open_container (&iter, + DBUS_TYPE_ARRAY, + "(sv)", + &iter_array)) { + goto out; + } + + name = first_parameter_name; + while (name != NULL) { + int type; + const void *value; + dbus_bool_t res; + + type = lookup_parameter_type (name); + value = va_arg (var_args, const void *); + + if (type == DBUS_TYPE_INVALID) { + dbus_set_error (error, + CK_CONNECTOR_ERROR, + "Unknown parameter: %s", + name); + goto out; + } + + res = add_param_basic (&iter_array, name, type, value); + if (! res) { + dbus_set_error (error, + CK_CONNECTOR_ERROR, + "Error adding parameter: %s", + name); + goto out; + } + + name = va_arg (var_args, char *); + } + + if (! dbus_message_iter_close_container (&iter, &iter_array)) { + goto out; + } + + dbus_error_init (&local_error); + reply = dbus_connection_send_with_reply_and_block (connector->connection, + message, + -1, + &local_error); + if (reply == NULL) { + if (dbus_error_is_set (&local_error)) { + dbus_set_error (error, + CK_CONNECTOR_ERROR, + "Unable to open session: %s", + local_error.message); + dbus_error_free (&local_error); + goto out; + } + } + + dbus_error_init (&local_error); + if (! dbus_message_get_args (reply, + &local_error, + DBUS_TYPE_STRING, &cookie, + DBUS_TYPE_INVALID)) { + if (dbus_error_is_set (&local_error)) { + dbus_set_error (error, + CK_CONNECTOR_ERROR, + "Unable to open session: %s", + local_error.message); + dbus_error_free (&local_error); + goto out; + } + } + + connector->cookie = strdup (cookie); + if (connector->cookie == NULL) { + goto out; + } + + connector->session_created = TRUE; + ret = TRUE; + +out: + if (reply != NULL) { + dbus_message_unref (reply); + } + + if (message != NULL) { + dbus_message_unref (message); + } + + return ret; +} + +/** + * Opens a new session with parameter from variable argument list. The + * variable argument list should contain the name of each parameter + * followed by the value to append. + * For example: + * + * @code + * + * DBusError error; + * dbus_int32_t v_INT32 = 500; + * const char *v_STRING = "/dev/tty3"; + * + * dbus_error_init (&error); + * ck_connector_open_session_with_parameters (connector, + * &error, + * "user", &v_INT32, + * "display-device", &v_STRING, + * NULL); + * @endcode + * + * @param error error output + * @param first_parameter_name name of the first parameter + * @param ... value of first parameter, list of additional name-value pairs + * @returns #TRUE on success + */ +dbus_bool_t +ck_connector_open_session_with_parameters (CkConnector *connector, + DBusError *error, + const char *first_parameter_name, + ...) +{ + va_list var_args; + dbus_bool_t ret; + + _ck_return_val_if_fail (connector != NULL, FALSE); + _ck_return_val_if_fail ((error) == NULL || !dbus_error_is_set ((error)), FALSE); + + va_start (var_args, first_parameter_name); + ret = ck_connector_open_session_with_parameters_valist (connector, + error, + first_parameter_name, + var_args); + va_end (var_args); + + return ret; +} + +/** + * Connects to the D-Bus system bus daemon and issues the method call + * OpenSessionWithParameters on the ConsoleKit manager interface. The + * connection to the bus is private. + * + * The only parameter that is optional is x11_display - it may be set + * to NULL if there is no X11 server associated with the session. + * + * Returns FALSE on OOM, if the system bus daemon is not running, if + * the ConsoleKit daemon is not running or if the caller doesn't have + * sufficient privileges. + * + * @param user UID for the user owning the session + * @param display_device the tty device for the session + * @param x11_display the value of the X11 DISPLAY for the session + * @returns #TRUE if the operation succeeds + */ +dbus_bool_t +ck_connector_open_session_for_user (CkConnector *connector, + uid_t user, + const char *display_device, + const char *x11_display, + DBusError *error) +{ + dbus_bool_t ret; + + _ck_return_val_if_fail (connector != NULL, FALSE); + _ck_return_val_if_fail (display_device != NULL, FALSE); + _ck_return_val_if_fail ((error) == NULL || !dbus_error_is_set ((error)), FALSE); + + ret = ck_connector_open_session_with_parameters (connector, + error, + "display-device", &display_device, + "x11-display", &x11_display, + "user", &user, + NULL); + return ret; +} + +/** + * Gets the cookie for the current open session. + * Returns #NULL if no session is open. + * + * @returns a constant string with the cookie. + */ +const char * +ck_connector_get_cookie (CkConnector *connector) +{ + _ck_return_val_if_fail (connector != NULL, NULL); + + if (! connector->session_created) { + return NULL; + } else { + return connector->cookie; + } +} + +/** + * Issues the CloseSession method call on the ConsoleKit manager + * interface. + * + * Returns FALSE on OOM, if the system bus daemon is not running, if + * the ConsoleKit daemon is not running, if the caller doesn't have + * sufficient privilege or if a session isn't open. + * + * @returns #TRUE if the operation succeeds + */ +dbus_bool_t +ck_connector_close_session (CkConnector *connector, + DBusError *error) +{ + DBusError local_error; + DBusMessage *message; + DBusMessage *reply; + dbus_bool_t ret; + dbus_bool_t session_closed; + + _ck_return_val_if_fail (connector != NULL, FALSE); + _ck_return_val_if_fail ((error) == NULL || !dbus_error_is_set ((error)), FALSE); + + reply = NULL; + message = NULL; + ret = FALSE; + + if (!connector->session_created || connector->cookie == NULL) { + dbus_set_error (error, + CK_CONNECTOR_ERROR, + "Unable to close session: %s", + "no session open"); + goto out; + } + + dbus_error_init (&local_error); + message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", + "/org/freedesktop/ConsoleKit/Manager", + "org.freedesktop.ConsoleKit.Manager", + "CloseSession"); + if (message == NULL) { + goto out; + } + + if (! dbus_message_append_args (message, + DBUS_TYPE_STRING, &(connector->cookie), + DBUS_TYPE_INVALID)) { + goto out; + } + + dbus_error_init (&local_error); + reply = dbus_connection_send_with_reply_and_block (connector->connection, + message, + -1, + &local_error); + if (reply == NULL) { + if (dbus_error_is_set (&local_error)) { + dbus_set_error (error, + CK_CONNECTOR_ERROR, + "Unable to close session: %s", + local_error.message); + dbus_error_free (&local_error); + goto out; + } + } + + dbus_error_init (&local_error); + if (! dbus_message_get_args (reply, + &local_error, + DBUS_TYPE_BOOLEAN, &session_closed, + DBUS_TYPE_INVALID)) { + if (dbus_error_is_set (&local_error)) { + dbus_set_error (error, + CK_CONNECTOR_ERROR, + "Unable to close session: %s", + local_error.message); + dbus_error_free (&local_error); + goto out; + } + } + + if (! session_closed) { + goto out; + } + + connector->session_created = FALSE; + ret = TRUE; + +out: + if (reply != NULL) { + dbus_message_unref (reply); + } + + if (message != NULL) { + dbus_message_unref (message); + } + + return ret; + +} diff --git a/libck-connector/ck-connector.h b/libck-connector/ck-connector.h new file mode 100644 index 0000000..ab59f55 --- /dev/null +++ b/libck-connector/ck-connector.h @@ -0,0 +1,64 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * ck-connector.h : Code for login managers to register with ConsoleKit. + * + * Copyright (c) 2007 David Zeuthen <davidz@redhat.com> + * Copyright (c) 2007 William Jon McCann <mccann@jhu.edu> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef CK_CONNECTOR_H +#define CK_CONNECTOR_H + +#include <sys/types.h> +#include <dbus/dbus.h> + +DBUS_BEGIN_DECLS + +struct _CkConnecter; +typedef struct _CkConnector CkConnector; + +CkConnector *ck_connector_new (void); + +CkConnector *ck_connector_ref (CkConnector *ckc); +void ck_connector_unref (CkConnector *ckc); + +dbus_bool_t ck_connector_open_session_for_user (CkConnector *ckc, + uid_t user, + const char *tty, + const char *x11_display, + DBusError *error); +dbus_bool_t ck_connector_open_session_with_parameters (CkConnector *ckc, + DBusError *error, + const char *first_parameter_name, + ...); +dbus_bool_t ck_connector_open_session (CkConnector *ckc, + DBusError *error); + +const char *ck_connector_get_cookie (CkConnector *ckc); +dbus_bool_t ck_connector_close_session (CkConnector *ckc, + DBusError *error); + +DBUS_END_DECLS + +#endif /* CK_CONNECTOR_H */ diff --git a/libck-connector/ck-connector.pc.in b/libck-connector/ck-connector.pc.in new file mode 100644 index 0000000..67ecce3 --- /dev/null +++ b/libck-connector/ck-connector.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@prefix@ +libdir=@libdir@ +includedir=@prefix@/include + +Name: ck-connector +Description: Library for connecting new sessions to ConsoleKit +Version: @VERSION@ +Requires: dbus-1 +Libs: -L${libdir} -lck-connector +Cflags: -I${includedir}/ConsoleKit/ck-connector diff --git a/libck-connector/test-connector.c b/libck-connector/test-connector.c new file mode 100644 index 0000000..7f17426 --- /dev/null +++ b/libck-connector/test-connector.c @@ -0,0 +1,101 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (c) 2007 David Zeuthen <davidz@redhat.com> + * Copyright (c) 2007 William Jon McCann <mccann@jhu.edu> + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include "ck-connector.h" + +int +main (int argc, char *argv[]) +{ + CkConnector *connector; + int ret; + int res; + DBusError error; + int user; + const char *display_device; + const char *x11_display; + const char *remote_host_name; + + ret = 1; + + connector = ck_connector_new (); + if (connector == NULL) { + printf ("OOM creating CkConnector\n"); + goto out; + } + + user = 730; + display_device = "/dev/tty3"; + x11_display = ":20"; + remote_host_name = ""; + dbus_error_init (&error); + res = ck_connector_open_session_with_parameters (connector, + &error, + "user", &user, + "display-device", &display_device, + "x11-display", &x11_display, + "remote-host-name", &remote_host_name, + NULL); + if (! res) { + if (dbus_error_is_set (&error)) { + printf ("%s\n", + error.message); + dbus_error_free (&error); + } else { + printf ("cannot open CK session: OOM, D-Bus system bus not available,\n" + "ConsoleKit not available or insufficient privileges.\n"); + } + goto out; + } + + printf ("Session cookie is '%s'\n", ck_connector_get_cookie (connector)); + sleep (20); + + dbus_error_init (&error); + if (! ck_connector_close_session (connector, &error)) { + if (dbus_error_is_set (&error)) { + printf ("%s\n", + error.message); + dbus_error_free (&error); + } else { + printf ("Cannot close CK session: OOM, D-Bus system bus not available,\n" + "ConsoleKit not available or insufficient privileges.\n"); + } + goto out; + } + + ret = 0; +out: + if (connector != NULL) { + ck_connector_unref (connector); + } + + return ret; +} |