static void log_with_msgid (const gchar *msgid, GLogLevelFlags log_level, const gchar *numeric_log_level, const gchar *format, va_list args) { G_STATIC_ASSERT (G_LOG_DOMAIN != NULL); G_STATIC_ASSERT (G_LOG_DOMAIN[0] != '\0'); g_autofree gchar *message = NULL; /* Apparently the version of GCC in Endless ignores the * G_GNUC_PRINTF annotation that has a zero as the second parameter, * so it suggests to use this attribute. Similarly, so does Clang 4. */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic ignored "-Wsuggest-attribute=format" #pragma GCC diagnostic ignored "-Wformat-nonliteral" gint message_length = g_vasprintf (&message, format, args); #pragma GCC diagnostic pop const GLogField fields[] = { { "MESSAGE", message, message_length }, { "MESSAGE_ID", msgid, EOS_UPDATER_MSGID_LENGTH }, { "PRIORITY", numeric_log_level, -1 }, /* strlen (G_LOG_DOMAIN) should be folded to a constant at a * compilation time, because G_LOG_DOMAIN is a macro defining a * literal string */ { "GLIB_DOMAIN", G_LOG_DOMAIN, strlen (G_LOG_DOMAIN) }, }; g_log_structured_array (log_level, fields, G_N_ELEMENTS (fields)); }
static gint compare_mapping_entry (gconstpointer user_data, gconstpointer data) { const struct mapping_entry *entry = data; const gunichar *key = user_data; gunichar src_0; G_STATIC_ASSERT(MAX_KEY_SIZE == 2); src_0 = get_src_char (src_table, entry->src, 0); if (key[0] > src_0) return 1; else if (key[0] < src_0) return -1; if (get_length (entry->src) > 1) { gunichar src_1; src_1 = get_src_char (src_table, entry->src, 1); if (key[1] > src_1) return 1; else if (key[1] < src_1) return -1; } else if (key[1]) return 1; return 0; }
/** * pango_bidi_type_for_unichar: * @ch: a Unicode character * * Determines the normative bidirectional character type of a * character, as specified in the Unicode Character Database. * * A simplified version of this function is available as * pango_unichar_direction(). * * Return value: the bidirectional character type, as used in the * Unicode bidirectional algorithm. * * Since: 1.22 */ PangoBidiType pango_bidi_type_for_unichar (gunichar ch) { FriBidiCharType fribidi_ch_type; G_STATIC_ASSERT (sizeof (FriBidiChar) == sizeof (gunichar)); fribidi_ch_type = fribidi_get_bidi_type (ch); switch (fribidi_ch_type) { case FRIBIDI_TYPE_LTR: return PANGO_BIDI_TYPE_L; case FRIBIDI_TYPE_LRE: return PANGO_BIDI_TYPE_LRE; case FRIBIDI_TYPE_LRO: return PANGO_BIDI_TYPE_LRO; case FRIBIDI_TYPE_RTL: return PANGO_BIDI_TYPE_R; case FRIBIDI_TYPE_AL: return PANGO_BIDI_TYPE_AL; case FRIBIDI_TYPE_RLE: return PANGO_BIDI_TYPE_RLE; case FRIBIDI_TYPE_RLO: return PANGO_BIDI_TYPE_RLO; case FRIBIDI_TYPE_PDF: return PANGO_BIDI_TYPE_PDF; case FRIBIDI_TYPE_EN: return PANGO_BIDI_TYPE_EN; case FRIBIDI_TYPE_ES: return PANGO_BIDI_TYPE_ES; case FRIBIDI_TYPE_ET: return PANGO_BIDI_TYPE_ET; case FRIBIDI_TYPE_AN: return PANGO_BIDI_TYPE_AN; case FRIBIDI_TYPE_CS: return PANGO_BIDI_TYPE_CS; case FRIBIDI_TYPE_NSM: return PANGO_BIDI_TYPE_NSM; case FRIBIDI_TYPE_BN: return PANGO_BIDI_TYPE_BN; case FRIBIDI_TYPE_BS: return PANGO_BIDI_TYPE_B; case FRIBIDI_TYPE_SS: return PANGO_BIDI_TYPE_S; case FRIBIDI_TYPE_WS: return PANGO_BIDI_TYPE_WS; case FRIBIDI_TYPE_ON: return PANGO_BIDI_TYPE_ON; default: g_assert_not_reached (); return PANGO_BIDI_TYPE_ON; } }
/** * udisks_daemon_util_get_caller_pid_sync: * @daemon: A #UDisksDaemon. * @invocation: A #GDBusMethodInvocation. * @cancellable: (allow-none): A #GCancellable or %NULL. * @out_pid: (out): Return location for resolved pid or %NULL. * @error: Return location for error. * * Gets the UNIX process id of the peer represented by @invocation. * * Returns: %TRUE if the process id was obtained, %FALSE otherwise */ gboolean udisks_daemon_util_get_caller_pid_sync (UDisksDaemon *daemon, GDBusMethodInvocation *invocation, GCancellable *cancellable, pid_t *out_pid, GError **error) { gboolean ret; const gchar *caller; GVariant *value; GError *local_error; pid_t pid; /* TODO: cache this on @daemon */ ret = FALSE; caller = g_dbus_method_invocation_get_sender (invocation); local_error = NULL; value = g_dbus_connection_call_sync (g_dbus_method_invocation_get_connection (invocation), "org.freedesktop.DBus", /* bus name */ "/org/freedesktop/DBus", /* object path */ "org.freedesktop.DBus", /* interface */ "GetConnectionUnixProcessID", /* method */ g_variant_new ("(s)", caller), G_VARIANT_TYPE ("(u)"), G_DBUS_CALL_FLAGS_NONE, -1, /* timeout_msec */ cancellable, &local_error); if (value == NULL) { g_set_error (error, UDISKS_ERROR, UDISKS_ERROR_FAILED, "Error determining uid of caller %s: %s (%s, %d)", caller, local_error->message, g_quark_to_string (local_error->domain), local_error->code); g_error_free (local_error); goto out; } { G_STATIC_ASSERT (sizeof (uid_t) == sizeof (guint32)); } g_variant_get (value, "(u)", &pid); if (out_pid != NULL) *out_pid = pid; ret = TRUE; out: return ret; }
static void request_handshake_rfc6455 (WebSocketClient *self, WebSocketConnection *conn, const gchar *host, const gchar *path) { gchar *key; gchar *protocols; GString *handshake; const gchar *origin; guint32 raw[4]; gsize len; raw[0] = g_random_int (); raw[1] = g_random_int (); raw[2] = g_random_int (); raw[3] = g_random_int (); G_STATIC_ASSERT (sizeof (raw) == 16); key = g_base64_encode ((const guchar *)raw, sizeof (raw)); /* Save this for verify_handshake_rfc6455() */ g_free (self->accept_key); self->accept_key = _web_socket_complete_accept_key_rfc6455 (key); handshake = g_string_new (""); g_string_printf (handshake, "GET %s HTTP/1.1\r\n" "Host: %s\r\n" "Upgrade: websocket\r\n" "Connection: Upgrade\r\n" "Sec-WebSocket-Key: %s\r\n" "Sec-WebSocket-Version: 13\r\n", path, host, key); /* RFC 6454 talks about 'null' */ origin = web_socket_connection_get_origin (conn); g_string_append_printf (handshake, "Origin: %s\r\n", origin ? origin : "null"); if (self->possible_protocols) { protocols = g_strjoinv (", ", self->possible_protocols); g_string_append_printf (handshake, "Sec-WebSocket-Protocol: %s\r\n", protocols); g_free (protocols); } include_custom_headers (self, handshake); g_string_append (handshake, "\r\n"); g_free (key); len = handshake->len; _web_socket_connection_queue (conn, WEB_SOCKET_QUEUE_URGENT, g_string_free (handshake, FALSE), len, 0); g_debug ("queued rfc6455 handshake request"); }
GQuark udisks_error_quark (void) { G_STATIC_ASSERT (G_N_ELEMENTS (dbus_error_entries) == UDISKS_ERROR_NUM_ENTRIES); static volatile gsize quark_volatile = 0; g_dbus_error_register_error_domain ("udisks-error-quark", &quark_volatile, dbus_error_entries, G_N_ELEMENTS (dbus_error_entries)); return (GQuark) quark_volatile; }
GQuark g_dbus_error_quark (void) { G_STATIC_ASSERT (G_N_ELEMENTS (g_dbus_error_entries) - 1 == G_DBUS_ERROR_PROPERTY_READ_ONLY); static volatile gsize quark_volatile = 0; g_dbus_error_register_error_domain ("g-dbus-error-quark", &quark_volatile, g_dbus_error_entries, G_N_ELEMENTS (g_dbus_error_entries)); return (GQuark) quark_volatile; }
/* pspec_key_hash: */ static guint pspec_key_hash ( gconstpointer key ) { /* just in case */ G_STATIC_ASSERT(sizeof(guint) <= sizeof(LObjectClass *)); #define k ((const PSpecKey *) key) const gchar *p; guint h = 5381; for (p = k->name; *p; p++) h = (h << 5) + h + *p; return h ^ *((guint *) k->owner_type); #undef k }
void adjust_ionice(const CPSettings settings) { /*@observer@*/ static const char *key = "PORTAGE_IONICE_COMMAND"; const char *raw_value = cp_settings_get(settings, key); if (raw_value == NULL) { return; } #if HAVE_GETPID { #ifndef S_SPLINT_S G_STATIC_ASSERT(sizeof(pid_t) <= sizeof(long)); #endif GError *error = NULL; GHashTable *vars = NULL; char *cmd = NULL; int retval; /*@-moduncon@*/ pid_t pid = getpid(); /*@=moduncon@*/ vars = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); g_hash_table_insert(vars, g_strdup("PID"), g_strdup_printf("%ld", (long)pid)); cmd = cp_varexpand(raw_value, vars, &error); if (cmd == NULL) { goto ERR; } /*@-modfilesys@*/ if (!g_spawn_command_line_sync(cmd, NULL, NULL, &retval, &error)) { goto ERR; } /*@=modfilesys@*/ if (retval != EXIT_SUCCESS) { g_warning(_("Command '%s' returned %d"), cmd, retval); g_warning(_("See the make.conf(5) man page for %s usage instructions."), key); } ERR: if (error != NULL) { g_warning(_("Can't run '%s': %s"), cmd, error->message); g_error_free(error); } g_free(cmd); cp_hash_table_destroy(vars); } #else g_warning(_("%s is specified but system doesn't have getpid() function"), key); #endif }
/** * pango_unichar_direction: * @ch: a Unicode character * * Determines the inherent direction of a character; either * %PANGO_DIRECTION_LTR, %PANGO_DIRECTION_RTL, or * %PANGO_DIRECTION_NEUTRAL. * * This function is useful to categorize characters into left-to-right * letters, right-to-left letters, and everything else. If full * Unicode bidirectional type of a character is needed, * pango_bidi_type_for_unichar() can be used instead. * * Return value: the direction of the character. */ PangoDirection pango_unichar_direction (gunichar ch) { FriBidiCharType fribidi_ch_type; G_STATIC_ASSERT (sizeof (FriBidiChar) == sizeof (gunichar)); fribidi_ch_type = fribidi_get_bidi_type (ch); if (!FRIBIDI_IS_STRONG (fribidi_ch_type)) return PANGO_DIRECTION_NEUTRAL; else if (FRIBIDI_IS_RTL (fribidi_ch_type)) return PANGO_DIRECTION_RTL; else return PANGO_DIRECTION_LTR; }
static int do_open (const char *path, mode_t mode, struct fuse_file_info *finfo) { const int flags = finfo->flags & O_ACCMODE; int fd; struct stat stbuf; /* Support read only opens */ G_STATIC_ASSERT (O_RDONLY == 0); path = ENSURE_RELPATH (path); if (flags == 0) fd = openat (basefd, path, flags); else { const int forced_excl_flags = flags | O_CREAT | O_EXCL; /* Do an exclusive open, don't allow writable fds for existing files */ fd = openat (basefd, path, forced_excl_flags, mode); /* If they didn't specify O_EXCL, give them EROFS if the file * exists. */ if (fd == -1 && (flags & O_EXCL) == 0) { if (errno == EEXIST) errno = EROFS; } else if (fd != -1) { if (fstat (fd, &stbuf) == -1) return -errno; devino_set_insert (stbuf.st_dev, stbuf.st_ino); } } if (fd == -1) return -errno; finfo->fh = fd; return 0; }
static void goa_panel_accounts_model_constructed (GObject *object) { GoaPanelAccountsModel *model = GOA_PANEL_ACCOUNTS_MODEL (object); GType types[GOA_PANEL_ACCOUNTS_MODEL_N_COLUMNS]; G_STATIC_ASSERT (5 == GOA_PANEL_ACCOUNTS_MODEL_N_COLUMNS); types[0] = G_TYPE_STRING; types[1] = GOA_TYPE_OBJECT; types[2] = G_TYPE_BOOLEAN; types[3] = G_TYPE_STRING; types[4] = G_TYPE_ICON; gtk_list_store_set_column_types (GTK_LIST_STORE (model), GOA_PANEL_ACCOUNTS_MODEL_N_COLUMNS, types); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model), GOA_PANEL_ACCOUNTS_MODEL_COLUMN_SORT_KEY, GTK_SORT_ASCENDING); g_signal_connect (model->client, "account-added", G_CALLBACK (on_account_added), model); g_signal_connect (model->client, "account-removed", G_CALLBACK (on_account_removed), model); g_signal_connect (model->client, "account-changed", G_CALLBACK (on_account_changed), model); init_model (model); if (G_OBJECT_CLASS (goa_panel_accounts_model_parent_class)->constructed != NULL) G_OBJECT_CLASS (goa_panel_accounts_model_parent_class)->constructed (object); }
static gboolean process (GeglOperation *operation, GeglBuffer *input, GeglBuffer *output, const GeglRectangle *roi, gint level) { GeglProperties *o = GEGL_PROPERTIES (operation); gdouble percentile = o->percentile / 100.0; gdouble alpha_percentile = o->alpha_percentile / 100.0; const gint *neighborhood_outline = o->user_data; const Babl *format = gegl_operation_get_format (operation, "input"); gint n_components = babl_format_get_n_components (format); gboolean has_alpha = babl_format_has_alpha (format); G_STATIC_ASSERT (sizeof (gint32) == sizeof (gfloat)); gint32 *src_buf; gfloat *dst_buf; GeglRectangle src_rect; gint src_stride; gint dst_stride; gint n_pixels; Histogram *hist; const gint32 *src; gfloat *dst; gint dst_x, dst_y; Direction dir; gint i; gint c; src_rect = gegl_operation_get_required_for_output (operation, "input", roi); src_stride = src_rect.width * n_components; dst_stride = roi->width * n_components; n_pixels = roi->width * roi->height; dst_buf = g_new0 (gfloat, n_pixels * n_components); src_buf = g_new0 (gint32, src_rect.width * src_rect.height * n_components); gegl_buffer_get (input, &src_rect, 1.0, format, src_buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP); convert_values_to_bins (src_buf, n_components, has_alpha, src_rect.width * src_rect.height); hist = g_slice_new0 (Histogram); src = src_buf + o->radius * (src_rect.width + 1) * n_components; dst = dst_buf; /* compute the first window */ for (i = -o->radius; i <= o->radius; i++) { histogram_modify_vals (hist, src, n_components, src_stride, has_alpha, i, -neighborhood_outline[abs (i)], i, +neighborhood_outline[abs (i)], +1); hist->size += 2 * neighborhood_outline[abs (i)] + 1; } for (c = 0; c < 3; c++) dst[c] = histogram_get_median (hist, c, percentile); if (has_alpha) dst[3] = histogram_get_median (hist, 3, alpha_percentile); dst_x = 0; dst_y = 0; n_pixels--; dir = LEFT_TO_RIGHT; while (n_pixels--) { /* move the src coords based on current direction and positions */ if (dir == LEFT_TO_RIGHT) { if (dst_x != roi->width - 1) { dst_x++; src += n_components; dst += n_components; } else { dst_y++; src += src_stride; dst += dst_stride; dir = TOP_TO_BOTTOM; } } else if (dir == TOP_TO_BOTTOM) { if (dst_x == 0) { dst_x++; src += n_components; dst += n_components; dir = LEFT_TO_RIGHT; } else { dst_x--; src -= n_components; dst -= n_components; dir = RIGHT_TO_LEFT; } } else if (dir == RIGHT_TO_LEFT) { if (dst_x != 0) { dst_x--; src -= n_components; dst -= n_components; } else { dst_y++; src += src_stride; dst += dst_stride; dir = TOP_TO_BOTTOM; } } histogram_update (hist, src, n_components, src_stride, has_alpha, o->neighborhood, o->radius, neighborhood_outline, dir); for (c = 0; c < 3; c++) dst[c] = histogram_get_median (hist, c, percentile); if (has_alpha) dst[3] = histogram_get_median (hist, 3, alpha_percentile); } gegl_buffer_set (output, roi, 0, format, dst_buf, GEGL_AUTO_ROWSTRIDE); g_slice_free (Histogram, hist); g_free (dst_buf); g_free (src_buf); return TRUE; }
/** * pango_log2vis_get_embedding_levels: * @text: the text to itemize. * @length: the number of bytes (not characters) to process, or -1 * if @text is nul-terminated and the length should be calculated. * @pbase_dir: input base direction, and output resolved direction. * * This will return the bidirectional embedding levels of the input paragraph * as defined by the Unicode Bidirectional Algorithm available at: * * http://www.unicode.org/reports/tr9/ * * If the input base direction is a weak direction, the direction of the * characters in the text will determine the final resolved direction. * * Return value: a newly allocated array of embedding levels, one item per * character (not byte), that should be freed using g_free. * * Since: 1.4 */ guint8 * pango_log2vis_get_embedding_levels (const gchar *text, int length, PangoDirection *pbase_dir) { glong n_chars, i; guint8 *embedding_levels_list; const gchar *p; FriBidiParType fribidi_base_dir; FriBidiCharType *bidi_types; #ifdef USE_FRIBIDI_EX_API FriBidiBracketType *bracket_types; #endif FriBidiLevel max_level; G_STATIC_ASSERT (sizeof (FriBidiLevel) == sizeof (guint8)); G_STATIC_ASSERT (sizeof (FriBidiChar) == sizeof (gunichar)); switch (*pbase_dir) { case PANGO_DIRECTION_LTR: case PANGO_DIRECTION_TTB_RTL: fribidi_base_dir = FRIBIDI_PAR_LTR; break; case PANGO_DIRECTION_RTL: case PANGO_DIRECTION_TTB_LTR: fribidi_base_dir = FRIBIDI_PAR_RTL; break; case PANGO_DIRECTION_WEAK_RTL: fribidi_base_dir = FRIBIDI_PAR_WRTL; break; case PANGO_DIRECTION_WEAK_LTR: case PANGO_DIRECTION_NEUTRAL: default: fribidi_base_dir = FRIBIDI_PAR_WLTR; break; } if (length < 0) length = strlen (text); n_chars = g_utf8_strlen (text, length); bidi_types = g_new (FriBidiCharType, n_chars); #ifdef USE_FRIBIDI_EX_API bracket_types = g_new (FriBidiBracketType, n_chars); #endif embedding_levels_list = g_new (guint8, n_chars); for (i = 0, p = text; p < text + length; p = g_utf8_next_char(p), i++) { gunichar ch = g_utf8_get_char (p); bidi_types[i] = fribidi_get_bidi_type (ch); #ifdef USE_FRIBIDI_EX_API if (G_UNLIKELY(bidi_types[i] == FRIBIDI_TYPE_ON)) bracket_types[i] = fribidi_get_bracket (ch); else bracket_types[i] = FRIBIDI_NO_BRACKET; #endif } #ifdef USE_FRIBIDI_EX_API max_level = fribidi_get_par_embedding_levels_ex (bidi_types, bracket_types, n_chars, &fribidi_base_dir, (FriBidiLevel*)embedding_levels_list); g_free (bracket_types); #else max_level = fribidi_get_par_embedding_levels (bidi_types, n_chars, &fribidi_base_dir, (FriBidiLevel*)embedding_levels_list); #endif g_free (bidi_types); if (G_UNLIKELY(max_level == 0)) { /* fribidi_get_par_embedding_levels() failed, * is this the best thing to do? */ memset (embedding_levels_list, 0, length); } *pbase_dir = (fribidi_base_dir == FRIBIDI_PAR_LTR) ? PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL; return embedding_levels_list; }
/** * g_str_to_ascii: * @str: a string, in UTF-8 * @from_locale: (allow-none): the source locale, if known * * Transliterate @str to plain ASCII. * * For best results, @str should be in composed normalised form. * * This function performs a reasonably good set of character * replacements. The particular set of replacements that is done may * change by version or even by runtime environment. * * If the source language of @str is known, it can used to improve the * accuracy of the translation by passing it as @from_locale. It should * be a valid POSIX locale string (of the form * "language[_territory][.codeset][@modifier]"). * * If @from_locale is %NULL then the current locale is used. * * If you want to do translation for no specific locale, and you want it * to be done independently of the currently locale, specify "C" for * @from_locale. * * Returns: a string in plain ASCII * * Since: 2.40 **/ gchar * g_str_to_ascii (const gchar *str, const gchar *from_locale) { GString *result; guint item_id; g_return_val_if_fail (str != NULL, NULL); if (g_str_is_ascii (str)) return g_strdup (str); if (from_locale) item_id = lookup_item_id_for_locale (from_locale); else item_id = get_default_item_id (); result = g_string_sized_new (strlen (str)); while (*str) { /* We only need to transliterate non-ASCII values... */ if (*str & 0x80) { gunichar key[MAX_KEY_SIZE]; const gchar *r; gint consumed; gint r_len; gunichar c; G_STATIC_ASSERT(MAX_KEY_SIZE == 2); c = g_utf8_get_char (str); /* This is where it gets evil... * * We know that MAX_KEY_SIZE is 2. We also know that we * only want to try another character if it's non-ascii. */ str = g_utf8_next_char (str); key[0] = c; if (*str & 0x80) key[1] = g_utf8_get_char (str); else key[1] = 0; r = lookup_in_item (item_id, key, &r_len, &consumed); /* If we failed to map two characters, try again with one. * * gconv behaviour is a bit weird here -- it seems to * depend in the randomness of the binary search and the * size of the input buffer as to what result we get here. * * Doing it this way is more work, but should be * more-correct. */ if (r == NULL && key[1]) { key[1] = 0; r = lookup_in_item (item_id, key, &r_len, &consumed); } if (r != NULL) { g_string_append_len (result, r, r_len); if (consumed == 2) /* If it took both then skip again */ str = g_utf8_next_char (str); } else /* no match found */ g_string_append_c (result, '?'); } else if (*str & 0x80) /* Out-of-range non-ASCII case */ { g_string_append_c (result, '?'); str = g_utf8_next_char (str); } else /* ASCII case */ g_string_append_c (result, *str++); } return g_string_free (result, FALSE); }
static void seahorse_pkcs11_generate_constructed (GObject *obj) { SeahorsePkcs11Generate *self = SEAHORSE_PKCS11_GENERATE (obj); GtkCellRenderer *renderer; GcrCollection *collection; GtkBuilder *builder; const gchar *path; GError *error = NULL; GtkWidget *content; GtkWidget *widget; G_OBJECT_CLASS (seahorse_pkcs11_generate_parent_class)->constructed (obj); builder = gtk_builder_new (); path = "/org/gnome/Seahorse/seahorse-pkcs11-generate.xml"; gtk_builder_add_from_resource (builder, path, &error); if (error != NULL) { g_warning ("couldn't load ui file: %s", path); g_clear_error (&error); g_object_unref (builder); return; } gtk_window_set_resizable (GTK_WINDOW (self), FALSE); content = gtk_dialog_get_content_area (GTK_DIALOG (self)); widget = GTK_WIDGET (gtk_builder_get_object (builder, "pkcs11-generate")); gtk_container_add (GTK_CONTAINER (content), widget); gtk_widget_show (widget); self->bits_entry = GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "key-bits")); gtk_spin_button_set_range (self->bits_entry, 0, G_MAXINT); /* updated later */ gtk_spin_button_set_increments (self->bits_entry, 128, 128); gtk_spin_button_set_value (self->bits_entry, 2048); self->label_entry = GTK_ENTRY (gtk_builder_get_object (builder, "key-label")); /* The mechanism */ self->mechanism_box = GTK_COMBO_BOX (gtk_builder_get_object (builder, "key-mechanism")); G_STATIC_ASSERT (MECHANISM_N_COLS == G_N_ELEMENTS (MECHANISM_TYPES)); self->mechanism_store = gtk_list_store_newv (MECHANISM_N_COLS, MECHANISM_TYPES); gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (self->mechanism_store), on_mechanism_sort, NULL, NULL); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self->mechanism_store), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING); gtk_combo_box_set_model (self->mechanism_box, GTK_TREE_MODEL (self->mechanism_store)); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self->mechanism_box), renderer, TRUE); gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self->mechanism_box), renderer, "markup", MECHANISM_LABEL); g_signal_connect (self->mechanism_box, "changed", G_CALLBACK (on_mechanism_changed), self); /* The tokens */ self->token_box = GTK_COMBO_BOX (gtk_builder_get_object (builder, "key-token")); collection = seahorse_pkcs11_backend_get_writable_tokens (NULL, CKM_RSA_PKCS_KEY_PAIR_GEN); self->token_model = gcr_collection_model_new (collection, GCR_COLLECTION_MODEL_LIST, "icon", G_TYPE_ICON, "label", G_TYPE_STRING, NULL); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self->token_model), 1, GTK_SORT_ASCENDING); gtk_combo_box_set_model (self->token_box, GTK_TREE_MODEL (self->token_model)); renderer = gtk_cell_renderer_pixbuf_new (); g_object_set (renderer, "stock-size", GTK_ICON_SIZE_BUTTON, NULL); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self->token_box), renderer, FALSE); gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self->token_box), renderer, "gicon", 0); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self->token_box), renderer, TRUE); gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self->token_box), renderer, "text", 1); g_signal_connect (self->token_box, "changed", G_CALLBACK (on_token_changed), self); if (gcr_collection_get_length (collection) > 0) gtk_combo_box_set_active (self->token_box, 0); g_object_unref (collection); /* The buttons */ gtk_dialog_add_buttons (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, _("Create"), GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response (GTK_DIALOG (self), GTK_RESPONSE_OK); update_response (self); g_object_unref (builder); }
/** * udisks_daemon_util_get_caller_uid_sync: * @daemon: A #UDisksDaemon. * @invocation: A #GDBusMethodInvocation. * @cancellable: (allow-none): A #GCancellable or %NULL. * @out_uid: (out): Return location for resolved uid or %NULL. * @out_gid: (out) (allow-none): Return location for resolved gid or %NULL. * @out_user_name: (out) (allow-none): Return location for resolved user name or %NULL. * @error: Return location for error. * * Gets the UNIX user id (and possibly group id and user name) of the * peer represented by @invocation. * * Returns: %TRUE if the user id (and possibly group id) was obtained, %FALSE otherwise */ gboolean udisks_daemon_util_get_caller_uid_sync (UDisksDaemon *daemon, GDBusMethodInvocation *invocation, GCancellable *cancellable, uid_t *out_uid, gid_t *out_gid, gchar **out_user_name, GError **error) { gboolean ret; const gchar *caller; GVariant *value; GError *local_error; uid_t uid; /* TODO: cache this on @daemon */ ret = FALSE; caller = g_dbus_method_invocation_get_sender (invocation); local_error = NULL; value = g_dbus_connection_call_sync (g_dbus_method_invocation_get_connection (invocation), "org.freedesktop.DBus", /* bus name */ "/org/freedesktop/DBus", /* object path */ "org.freedesktop.DBus", /* interface */ "GetConnectionUnixUser", /* method */ g_variant_new ("(s)", caller), G_VARIANT_TYPE ("(u)"), G_DBUS_CALL_FLAGS_NONE, -1, /* timeout_msec */ cancellable, &local_error); if (value == NULL) { g_set_error (error, UDISKS_ERROR, UDISKS_ERROR_FAILED, "Error determining uid of caller %s: %s (%s, %d)", caller, local_error->message, g_quark_to_string (local_error->domain), local_error->code); g_error_free (local_error); goto out; } { G_STATIC_ASSERT (sizeof (uid_t) == sizeof (guint32)); } g_variant_get (value, "(u)", &uid); if (out_uid != NULL) *out_uid = uid; if (out_gid != NULL || out_user_name != NULL) { struct passwd pwstruct; gchar pwbuf[8192]; struct passwd *pw = NULL; int rc; rc = getpwuid_r (uid, &pwstruct, pwbuf, sizeof pwbuf, &pw); if (rc == 0 && pw == NULL) { g_set_error (error, UDISKS_ERROR, UDISKS_ERROR_FAILED, "User with uid %d does not exist", (gint) uid); goto out; } else if (pw == NULL) { g_set_error (error, UDISKS_ERROR, UDISKS_ERROR_FAILED, "Error looking up passwd struct for uid %d: %m", (gint) uid); goto out; } if (out_gid != NULL) *out_gid = pw->pw_gid; if (out_user_name != NULL) *out_user_name = g_strdup (pwstruct.pw_name); } ret = TRUE; out: return ret; }