/* gcc -Wall -o dmfd dmfd.c `pkg-config --libs --cflags gio-2.0 glib-2.0 gio-unix-2.0` */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static gboolean _quit (gpointer user_data) { GMainLoop *loop = (GMainLoop *) user_data; g_main_loop_quit (loop); return TRUE; } gint main (gint argc, gchar *argv[]) { GDBusConnection *c; GError *error = NULL; GVariant *parameters = NULL; GVariantBuilder builder; GVariant *v_fd; #define FD_COUNT 17 gint fds[FD_COUNT]; GUnixFDList *fd_list; GMainLoop *loop; int i; gchar *target = NULL; struct sockaddr_in servaddr; struct sockaddr_un my_addr; socklen_t addrlen; c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); if (argc == 2) target = argv[1]; else g_object_get (c, "unique-name", &target, NULL); printf ("target: %s\n", target); /* Prepare fds */ pipe (fds); socketpair (AF_UNIX, SOCK_STREAM, 0, fds + 2); socketpair (AF_UNIX, SOCK_DGRAM, 0, fds + 4); socketpair (AF_UNIX, SOCK_SEQPACKET, 0, fds + 6); fds[8] = socket (AF_UNIX, SOCK_STREAM, 0); fds[9] = socket (AF_BLUETOOTH, SOCK_STREAM, 0); fds[10] = socket (AF_INET, SOCK_STREAM, 0); fds[11] = socket (AF_INET6, SOCK_STREAM, 0); fds[12] = open("/dev/zero", O_RDONLY); fds[13] = socket (AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); fds[14] = socket (AF_INET, SOCK_STREAM, 0); fds[15] = socket (AF_UNIX, SOCK_STREAM, 0); fds[16] = socket (AF_UNIX, SOCK_STREAM, 0); memset(&my_addr, 0, sizeof(struct sockaddr_un)); my_addr.sun_family = AF_UNIX; strncpy(my_addr.sun_path + 1, "/tmp/d67s774Sws0pEra", sizeof(my_addr.sun_path) - 1); bind (fds[15], (struct sockaddr *) &my_addr, sizeof(struct sockaddr_un)); listen (fds[15], 10); addrlen = sizeof (struct sockaddr_un); getsockname(fds[15], (struct sockaddr *) &my_addr, &addrlen); connect(fds[16], (struct sockaddr *) &my_addr, addrlen); bzero(&servaddr,sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr=inet_addr("127.0.0.1"); servaddr.sin_port=htons(22); /* ssh is running */ connect(fds[14], (struct sockaddr *)&servaddr, sizeof(servaddr)); /* Send message 1 */ g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE); fd_list = g_unix_fd_list_new_from_array (fds, FD_COUNT); for (i = 0 ; i < FD_COUNT ; i++) { v_fd = g_variant_new_handle (i); g_variant_builder_add_value (&builder, v_fd); } parameters = g_variant_builder_end (&builder); g_dbus_connection_call_with_unix_fd_list_sync (c, target, "/org/freedesktop/DBus", "org.freedesktop.DBus", "Foo", parameters, NULL, G_DBUS_CALL_FLAGS_NONE, -1, fd_list, NULL, NULL, &error); if (error) { g_print ("Error: %s\n", error->message); sleep(150); return 1; } loop = g_main_loop_new (NULL, FALSE); g_timeout_add_seconds (150, _quit, loop); g_main_loop_run (loop); g_main_loop_unref (loop); return 0; }