+ again:
+ cmd_size = 0;
+ if(ioctl(((DBusTransportSocket*)transport)->fd, KDBUS_CMD_NAME_LIST, pCmd))
+ {
+ if(errno == EINTR)
+ goto again;
+ if(errno == ENOBUFS) //buffer to small to put all names into it
+ cmd_size = pCmd->size; //here kernel tells how much memory it needs
+ else
+ {
+ _dbus_verbose("kdbus error asking for name list: err %d (%m)\n",errno);
+ goto out;
+ }
+ }
+ if(cmd_size) //kernel needs more memory
+ {
+ pCmd = realloc(pCmd, cmd_size); //prepare memory
+ if(pCmd == NULL)
+ return FALSE;
+ goto again; //and try again
+ }
+ else
+ {
+ DBusMessage *reply;
+ DBusMessageIter args;
+ struct kdbus_cmd_name* pCmd_name;
+ char* pName;
+
+ reply = dbus_message_new_method_return(message);
+ if(reply == NULL)
+ goto out;
+ dbus_message_set_sender(reply, DBUS_SERVICE_DBUS);
+ dbus_message_iter_init_append(reply, &args);
+
+ for (pCmd_name = pCmd->names; (uint8_t *)(pCmd_name) < (uint8_t *)(pCmd) + pCmd->size; pCmd_name = KDBUS_PART_NEXT(pCmd_name))
+ {
+ pName = pCmd_name->name;
+ if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &pName))
+ {
+ dbus_message_unref(reply);
+ goto out;
+ }
+ }
+
+ if(add_message_to_received(reply, transport->connection))
+ {
+ free(pCmd);
+ return TRUE;
+ }
+ }
+out:
+ if(pCmd)
+ free(pCmd);
+ return FALSE;
+ }
+ else if(!strcmp(dbus_message_get_member(message), "GetId"))
+ {
+ char* path;
+ char uuid[DBUS_UUID_LENGTH_BYTES];
+ struct stat stats;
+ MD5_CTX md5;
+ DBusString binary, encoded;
+
+ ret_value = FALSE;
+ path = &transport->address[11]; //start of kdbus bus path
+ if(stat(path, &stats) < -1)
+ {
+ _dbus_verbose("kdbus error reading stats of bus: err %d (%m)\n", errno);
+ return reply_with_error(DBUS_ERROR_FAILED, "Could not determine bus '%s' uuid", path, message, transport->connection);
+ }
+
+ MD5_Init(&md5);
+ MD5_Update(&md5, path, strlen(path));
+ MD5_Update(&md5, &stats.st_ctim.tv_sec, sizeof(stats.st_ctim.tv_sec));
+ MD5_Final(uuid, &md5);
+
+ if(!_dbus_string_init (&encoded))
+ goto outgid;
+ _dbus_string_init_const_len (&binary, uuid, DBUS_UUID_LENGTH_BYTES);
+ if(!_dbus_string_hex_encode (&binary, 0, &encoded, _dbus_string_get_length (&encoded)))
+ goto outb;
+ path = (char*)_dbus_string_get_const_data (&encoded);
+ ret_value = reply_1_data(message, DBUS_TYPE_STRING, &path, transport->connection);
+
+ outb:
+ _dbus_string_free(&binary);
+ _dbus_string_free(&encoded);
+ outgid:
+ return ret_value;
+ }
+ else if(!strcmp(dbus_message_get_member(message), "GetAdtAuditSessionData"))
+ {
+ char* name = NULL;
+
+ dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
+ return reply_with_error(DBUS_ERROR_ADT_AUDIT_DATA_UNKNOWN, "Could not determine audit session data for '%s'", name, message, transport->connection);
+ }
+ else if(!strcmp(dbus_message_get_member(message), "GetConnectionSELinuxSecurityContext"))
+ {
+ char* name = NULL;
+
+ dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
+ inter_ret = kdbus_NameQuery(name, ((DBusTransportSocket*)transport)->fd, &info);
+ if(inter_ret == -ENOENT) //name has no owner
+ return reply_with_error(DBUS_ERROR_NAME_HAS_NO_OWNER, "Could not get security context of name '%s': no such name", name, message, transport->connection);
+ else if(inter_ret < 0)
+ return reply_with_error(DBUS_ERROR_SELINUX_SECURITY_CONTEXT_UNKNOWN, "Could not determine security context for '%s'", name, message, transport->connection);
+ else
+ {
+ DBusMessage *reply;
+
+ ret_value = FALSE;
+ reply = dbus_message_new_method_return(message);
+ if(reply != NULL)
+ {
+ dbus_message_set_sender(reply, DBUS_SERVICE_DBUS);
+ if (!dbus_message_append_args (reply, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &info.sec_label, info.sec_label_len, DBUS_TYPE_INVALID))
+ dbus_message_unref(reply);
+ else if(add_message_to_received(reply, transport->connection))
+ ret_value = TRUE;
+ }
+ }
+ }
+ else
+ return reply_with_error(DBUS_ERROR_UNKNOWN_METHOD, NULL, (char*)dbus_message_get_member(message), message, transport->connection);
+/* else if(!strcmp(dbus_message_get_member(message), "ListActivatableNames")) //todo
+ {
+
+ }
+ else if(!strcmp(dbus_message_get_member(message), "StartServiceByName"))
+ {
+
+ }
+ else if(!strcmp(dbus_message_get_member(message), "UpdateActivationEnvironment"))
+ {
+
+ }
+ else if(!strcmp(dbus_message_get_member(message), "ReloadConfig"))
+ {
+
+ }
+ */
+
+ if(info.sec_label)
+ free(info.sec_label);
+ return ret_value;