gint
gum_crypt_cmp_secret (
- const gchar *plain_secret,
- const gchar *enc_secret);
+ const gchar *plain_str1,
+ const gchar *enc_str2);
G_END_DECLS
* Copyright (C) 2013 Intel Corporation.
*
* Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
+ * Imran Zaman <imran.zaman@intel.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
GType gum_disposable_get_type (void) G_GNUC_CONST;
void
-gum_disposable_set_auto_dispose (GumDisposable *disposable,
- gboolean dispose);
+gum_disposable_set_auto_dispose (
+ GumDisposable *self,
+ gboolean dispose);
gboolean
-gum_disposable_get_auto_dispose (GumDisposable *disposable);
+gum_disposable_get_auto_dispose (
+ GumDisposable *self);
void
-gum_disposable_set_timeout (GumDisposable *self,
- guint timeout);
+gum_disposable_set_timeout (
+ GumDisposable *self,
+ guint timeout);
void
-gum_disposable_delete_later (GumDisposable *self);
+gum_disposable_delete_later (
+ GumDisposable *self);
G_END_DECLS
#include <glib.h>
+G_BEGIN_DECLS
+
#define GUM_STR_FREE(s) { \
if (s) { \
g_free (s); \
d = g_strdupv (s); \
}
-G_BEGIN_DECLS
-
gboolean
gum_string_utils_search_string (
const gchar *strings,
gum_string_utils_get_string (
const gchar *strings,
const gchar *separator,
- guint str_ind /*starts from 0*/);
+ guint str_ind);
gchar *
gum_string_utils_insert_string (
const gchar *strings,
const gchar *separator,
const gchar *str_to_insert,
- guint str_ind, /*starts from 0*/
+ guint str_ind,
guint total_strings);
gchar **
#include "common/gum-crypt.h"
#include "common/gum-log.h"
+/**
+ * SECTION:gum-crypt
+ * @short_description: Utility functions for encryption
+ * @title: Gum Crypt
+ * @include: gum/common/gum-crypt.h
+ *
+ * Following code snippets shows how a string can be encrypted with any of the
+ * encrytpion method listed in #GumCryptMethodID. Moreover, plain and encrypted
+ * secrets can be compared if needed.
+ *
+ * |[
+ * gchar *pass = gum_crypt_encrypt_secret("pas.-s123", GUM_CRYPT_SHA512);
+ * g_free (pass);
+ *
+ * pass = gum_crypt_encrypt_secret("pass ?()#123", GUM_CRYPT_SHA512);
+ * gum_crypt_cmp_secret("pass ?()#123", pass); //should return true.
+ * g_free (pass);
+ *
+ * ]|
+ */
+
+/**
+ * GumCryptMethodID:
+ * @GUM_CRYPT_MD5: MD5 encryption algorithm
+ * @GUM_CRYPT_SHA256: SHA-256 encryption algorithm
+ * @GUM_CRYPT_SHA512: SHA-512 encryption algorithm
+ * @GUM_CRYPT_DES: DES encryption algorithm
+ *
+ * This enumeration lists the supported encryption methods.
+ */
+
guchar _salt_chars[64 + 1] =
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
return g_strdup (salt);
}
+/**
+ * gum_crypt_encrypt_secret:
+ * @secret: (transfer none): string to encrypt
+ * @methodid: #GumCryptMethodID method id
+ *
+ * Encrypts the secret with the specified method.
+ *
+ * Returns: (transfer full): encrypted secret if successful, NULL otherwise.
+ */
gchar *
gum_crypt_encrypt_secret (
const gchar *secret,
return salt;
}
+/**
+ * gum_crypt_cmp_secret:
+ * @plain_str1: (transfer none): plain string
+ * @enc_str2: (transfer none): encrypted string
+ *
+ * Encrypts plain string with the same parameters as that of encrypted string
+ * and then compares both encrypted strings.
+ *
+ * Returns: 0 if enc_str1 == enc_str2, less than 0 if the enc_str1 < enc_str2,
+ * greater than 0 if enc_str1 > enc_str2.
+ */
gint
gum_crypt_cmp_secret (
- const gchar *plain_secret,
- const gchar *enc_secret)
+ const gchar *plain_str1,
+ const gchar *enc_str2)
{
gint cmp = -1;
gchar *plain_enc = NULL;
- if (!enc_secret || !plain_secret) return cmp;
+ if (!enc_str2 || !plain_str1) return cmp;
- gchar *salt = _extract_salt (enc_secret);
+ gchar *salt = _extract_salt (enc_str2);
if (!salt) return cmp;
- plain_enc = g_strdup (crypt (plain_secret, salt));
+ plain_enc = g_strdup (crypt (plain_str1, salt));
g_free (salt);
- cmp = g_strcmp0 (plain_enc, enc_secret);
+ cmp = g_strcmp0 (plain_enc, enc_str2);
g_free (plain_enc);
return cmp;
* Copyright (C) 2013 Intel Corporation.
*
* Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
+ * Imran Zaman <imran.zaman@intel.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#include "common/gum-disposable.h"
#include "common/gum-log.h"
+/**
+ * SECTION:gum-disposable
+ * @short_description: timer-based auto disposable object
+ * @include: gum/common/gum-disposable.h
+ *
+ * #GumDisposable is used to dispose the object when the timer expires with the
+ * specified timeout value provided auto-dispose is enabled. A #GObject which
+ * needs to be auto-disposable should derive itself from #GumDisposable and
+ * can set the timeout value (at the time of object construction e.g.). One such
+ * example, which can make use of #GumDisposable, is a DBus object as it may
+ * be required to destory after some period of inactivity.
+ *
+ * <refsect1><title>Usage</title></refsect1>
+ * Following code snippet demonstrates how to derive and use #GumDisposable:
+ * |[
+ *
+ * //gum-test-object.h
+ * struct _GumTestObject
+ * {
+ * GumDisposable parent;
+ * };
+ *
+ * struct _GumTestObjectClass
+ * {
+ * GumDisposableClass parent_class;
+ * };
+ *
+ * //gum-test-object.c
+ * GumTestObject *
+ * gum_test_object_new ()
+ * {
+ * GumTestObject *obj = g_object_new (GUM_TYPE_TEST_OBJECT, NULL);
+ *
+ * // ... other code
+ *
+ * // GumTestobject will be disposed after 5 seconds unless auto-dispose
+ * // is disabled by calling gum_disposable_set_auto_dispose (obj, FALSE)
+ * gint timeout = 5;
+ * gum_disposable_set_timeout (GUM_DISPOSABLE (obj), timeout);
+ *
+ * // ... other code
+ * }
+ *
+ * ]|
+ *
+ */
+
+/**
+ * GumDisposable:
+ *
+ * Opaque structure for the object.
+ */
+
+/**
+ * GumDisposableClass:
+ * @parent_class: parent class object
+ *
+ * Opaque structure for the class.
+ */
+
struct _GumDisposablePrivate
{
guint timeout; /* timeout in seconds */
object_class->dispose = _dispose;
object_class->finalize = _finalize;
+ /**
+ * GumDisposable:timeout:
+ *
+ * This property holds the value of timeout in seconds. Default value is 0.
+ * If timeout value is 0, the object never auto-dispose.
+ */
properties[PROP_TIMEOUT] =
g_param_spec_uint ("timeout",
"Object timeout",
0,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ /**
+ * GumDisposable:auto-dispose:
+ *
+ * This property holds the value of auto-dispose to be TRUE or FALSE.
+ * Default value is FALSE. If auto-dispose is TRUE, then object is
+ * auto-disposed otherwise not.
+ */
properties[PROP_AUTO_DISPOSE] =
g_param_spec_boolean ("auto-dispose",
"Auto dispose",
TRUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ /**
+ * GumDisposable:delete-later:
+ *
+ * This property is used when the object is asked to be deleted later.
+ * The object should not be used once #gum_disposable_delete_later is
+ * requested for the object.
+ */
properties[PROP_DELETE_LATER] =
g_param_spec_boolean ("delete-later",
"Delete Later",
g_object_class_install_properties (object_class, PROP_MAX, properties);
+ /**
+ * GumDisposable:disposing:
+ *
+ * This signal is emitted when the object is about to be disposed.
+ */
signals[SIG_DISPOSING] = g_signal_new ("disposing",
GUM_TYPE_DISPOSABLE,
G_SIGNAL_RUN_FIRST| G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
GumDisposable *self = GUM_DISPOSABLE (user_data);
g_signal_emit (self, signals[SIG_DISPOSING], 0);
/* destroy object */
- DBG ("%s AUTO DISPOSE %d", G_OBJECT_TYPE_NAME (self), G_OBJECT (self)->ref_count);
+ DBG ("%s AUTO DISPOSE %d", G_OBJECT_TYPE_NAME (self),
+ G_OBJECT (self)->ref_count);
g_object_unref (G_OBJECT (self));
return FALSE;
}
}
}
+/**
+ * gum_disposable_set_auto_dispose:
+ * @self: (transfer none): an instance of #GumDisposable
+ * @dispose: dispose flag
+ *
+ * Sets the auto-dispose flag, and sets up the timer if needed.
+ *
+ */
void
gum_disposable_set_auto_dispose (
GumDisposable *self,
_update_timer (self);
}
+/**
+ * gum_disposable_set_timeout:
+ * @self: (transfer none): an instance of #GumDisposable
+ * @timeout: timeout value in seconds
+ *
+ * Sets the timeout value and sets up the timer if needed. If timeout
+ * value is set to 0, the object is never disposed.
+ */
void
gum_disposable_set_timeout (
GumDisposable *self,
_update_timer (self);
}
+/**
+ * gum_disposable_delete_later:
+ * @self: (transfer none): an instance of #GumDisposable
+ *
+ * Sets the object to be deleted later. Once delete later is requested, the
+ * object should not be used.
+ */
void
gum_disposable_delete_later (
GumDisposable *self)
self->priv->delete_later = TRUE;
}
+/**
+ * gum_disposable_get_auto_dispose:
+ * @self: (transfer none): an instance of #GumDisposable
+ *
+ * Gets the auto-dispose value.
+ *
+ * Returns: the auto-dispose value of the object.
+ */
gboolean
gum_disposable_get_auto_dispose (
GumDisposable *self)
* @GUM_ERROR_USER_ERR: Placeholder to rearrange enumeration - User space
* specific
*
- * This enum provides a list of errors
+ * This enumeration provides a list of errors
*/
/**
#include "common/gum-log.h"
#include "common/gum-error.h"
+/**
+ * SECTION:gum-file
+ * @short_description: Utility functions for file handling
+ * @title: Gum File
+ * @include: gum/common/gum-file.h
+ *
+ *
+ * |[
+ *
+ * ]|
+ */
+
#define GUM_PERM 0777
static FILE *
goto _free_data;
}
}
+ /* when run in test mode, user may not exist */
#ifndef ENABLE_TESTS
if (!stop) stop = (chown (dest_filepath, uid, gid) < 0);
#endif
#include "common/gum-lock.h"
#include "common/gum-log.h"
+/**
+ * SECTION:gum-lock
+ * @short_description: Utility functions for (un)locking user/group database
+ * @title: Gum Lock
+ * @include: gum/common/gum-lock.h
+ *
+ * Locking the user/group database is required when modifications are needed to
+ * the database e.g. adding and deleting users. Lock can be called multiple
+ * times as it merely increases the lock counter after acquiring the lock for
+ * the first time. Similarly unlock can be called multiple times as it decreases
+ * lock counter until it the count reaches to 0 when the lock is released.
+ * Locking and unlocking the database is disabled for when testing is enabled
+ * as tests are run on dummy databases.
+ *
+ * |[
+ * //return value must be checked if the lock succeed or not.
+ * gboolean ret = gum_lock_pwdf_lock ();
+ *
+ * //return value must be checked if the unlock succeed or not.
+ * ret = gum_lock_pwdf_unlock ();
+ * ]|
+ */
+
static gint lock_count = 0;
+/**
+ * gum_lock_pwdf_lock:
+ *
+ * Gets the lock to the user/group database file(s). Lock can be called multiple
+ * times as it merely increases the lock counter after acquiring the lock for
+ * the first time. In order to release the lock, unlock needs to be called
+ * the same number of times as that of lock. Locking and unlocking the database
+ * is disabled for when testing is enabled as tests are run on dummy databases.
+ *
+ * Returns: TRUE if successful, FALSE otherwise.
+ */
gboolean
gum_lock_pwdf_lock ()
{
return TRUE;
}
+/**
+ * gum_lock_pwdf_unlock:
+ *
+ * Releases the lock to the user/group database file(s). Unlock can be called
+ * multiple times as it decreases lock counter until it the count reaches to 0
+ * when the lock is released. In order to release the lock, unlock needs to be
+ * called the same number of times as that of lock. Locking and unlocking the
+ * database is disabled for when testing is enabled as tests are run on dummy
+ * databases.
+ *
+ * Returns: TRUE if successful, FALSE otherwise.
+ */
gboolean
gum_lock_pwdf_unlock ()
{
#include "common/gum-log.h"
#include "common/gum-error.h"
+/**
+ * SECTION:gum-string-utils
+ * @short_description: Utility functions for strings handling
+ * @title: Gum String Utils
+ * @include: gum/common/gum-string-utils.h
+ *
+ */
+
+/**
+ * GUM_STR_FREE:
+ * @s: the string to free
+ *
+ * A helper macro that frees the string after checking if it is not NULL.
+ */
+
+/**
+ * GUM_STR_DUP:
+ * @s: the source string
+ * @d: the destination string
+ *
+ * A helper macro that duplicates source string to destination string after
+ * freeing the destination string first if it is not NULL.
+ */
+
+/**
+ * GUM_STR_FREEV:
+ * @s: the string vector to free
+ *
+ * A helper macro that frees string vector after checking if it is not NULL.
+ */
+
+/**
+ * GUM_STR_DUPV:
+ * @s: the source string vector
+ * @d: the destination string vector
+ *
+ * A helper macro that duplicates source string vector to destination string
+ * vector after freeing the destination string vector first if it is not NULL.
+ */
+
+/**
+ * gum_string_utils_search_string:
+ * @strings: (transfer none): concatenated strings in a string placeholder
+ * separated by a separator
+ * @separator: (transfer none): separator between strings
+ * @search_str: (transfer none): string to search
+ *
+ * Finds the 'search string' in the strings.
+ *
+ * Returns: TRUE if found, FALSE otherwise.
+ */
gboolean
gum_string_utils_search_string (
const gchar *strings,
return FALSE;
}
+/**
+ * gum_string_utils_search_stringv:
+ * @stringv: (transfer none): vector of strings
+ * @search_str: (transfer none): string to search
+ *
+ * Finds the 'search string' in the string vector.
+ *
+ * Returns: TRUE if found, FALSE otherwise.
+ */
gboolean
gum_string_utils_search_stringv (
gchar **stringv,
return FALSE;
}
+/**
+ * gum_string_utils_get_string:
+ * @strings: (transfer none): vector of strings
+ * @separator: (transfer none): separator between strings
+ * @str_ind: starting from 0, position for the string to fetch
+ *
+ * Gets the str_ind'th string from the strings.
+ *
+ * Returns: (transfer full): string if successful, NULL otherwise.
+ */
gchar *
gum_string_utils_get_string (
const gchar *strings,
const gchar *separator,
- guint str_ind /*starts from 0*/)
+ guint str_ind)
{
gchar **strv = NULL;
gchar *str = NULL;
return str;
}
+/**
+ * gum_string_utils_insert_string:
+ * @strings: (transfer none): vector of strings
+ * @separator: (transfer none): separator between strings
+ * @str_to_insert: (transfer none): string to insert
+ * @str_ind: starting from 0, position for the string to insert
+ * @total_strings: total number of strings in the strings vector
+ *
+ * Inserts the string at the desired position and returns the concatenated
+ * string
+ *
+ * Returns: (transfer full): concatenated string vector if successful, NULL
+ * otherwise.
+ */
gchar *
gum_string_utils_insert_string (
const gchar *strings,
const gchar *separator,
const gchar *str_to_insert,
- guint str_ind, /*starts from 0*/
+ guint str_ind,
guint total_strings)
{
gchar **src_strv = NULL, **dest_strv = NULL;
return result_str;
}
+/**
+ * gum_string_utils_delete_string:
+ * @src_strv: (transfer none): vector of strings
+ * @string: (transfer none): string to delete
+ *
+ * Deletes the string from the strings' vector.
+ *
+ * Returns: (transfer full): modified string vector if string found, NULL
+ * otherwise.
+ */
gchar **
gum_string_utils_delete_string (
gchar **src_strv,
return dest_strv;
}
+/**
+ * gum_string_utils_append_string:
+ * @src_strv: (transfer none): vector of strings
+ * @string: (transfer none): string to append
+ *
+ * Appends the string to the end of the strings' vector.
+ *
+ * Returns: (transfer full): concatenated string vector if successful, NULL
+ * otherwise.
+ */
gchar **
gum_string_utils_append_string (
gchar **src_strv,
#include "common/gum-utils.h"
#include "common/gum-log.h"
+/**
+ * SECTION:gum-utils
+ * @short_description: Utility functions
+ * @title: Gum Utils
+ * @include: gum/common/gum-utils.h
+ *
+ */
typedef struct __nonce_ctx_t
{
return _nonce_ctx.initialized;
}
+/**
+ * gum_generate_nonce:
+ * @algorithm: the #GChecksumType algorithm
+ *
+ * Generates nonce based on hashing algorithm as specified in @algorithm
+ *
+ * Returns: (transfer full): generate nonce if successful, NULL otherwise.
+ */
gchar *
-gum_generate_nonce ()
+gum_generate_nonce (
+ GChecksumType algorithm)
{
GHmac *hmac;
gchar *nonce = NULL;
if (G_UNLIKELY (!_init_nonce_gen()))
goto nonce_exit;
- hmac = g_hmac_new (G_CHECKSUM_SHA1,
- _nonce_ctx.key, sizeof (_nonce_ctx.key));
+ hmac = g_hmac_new (algorithm, _nonce_ctx.key, sizeof (_nonce_ctx.key));
+
g_hmac_update (hmac, _nonce_ctx.entropy, sizeof (_nonce_ctx.entropy));
+
_nonce_ctx.serial++;
- g_hmac_update (hmac,
- (const guchar *) &_nonce_ctx.serial,
- sizeof (_nonce_ctx.serial));
+ g_hmac_update (hmac, (const guchar *) &_nonce_ctx.serial,
+ sizeof (_nonce_ctx.serial));
+
if (clock_gettime (CLOCK_MONOTONIC, &ts) == 0)
g_hmac_update (hmac, (const guchar *) &ts, sizeof (ts));
+
memset (&ts, 0x00, sizeof(ts));
nonce = g_strdup (g_hmac_get_string (hmac));
g_hmac_unref (hmac);
#include "common/gum-log.h"
#include "common/gum-error.h"
+/**
+ * SECTION:gum-validate
+ * @short_description: Utility functions for validating strings
+ * @title: Gum Validate
+ * @include: gum/common/gum-validate.h
+ *
+ */
+
+/**
+ * GUM_NAME_PATTERN:
+ *
+ * A macro that defines the string pattern to be acceptable for names.
+ */
+
+/**
+ * GUM_DB_ENTRY_PATTERN:
+ *
+ * A macro that defines the string pattern to be acceptable for entries in the
+ * user/group database.
+ */
+
+/**
+ * gum_validate_name:
+ * @name: (transfer none): the name string to be validated
+ * @error: (transfer none): the #GError to be set in case of error
+ *
+ * Validates the name against the #GUM_NAME_PATTERN pattern.
+ *
+ * Returns: TRUE if validation succeeds, FALSE otherwise.
+ */
gboolean
gum_validate_name (
const gchar *name,
return TRUE;
}
+/**
+ * gum_validate_generate_username:
+ * @str: (transfer none): the string to be validated
+ * @error: (transfer none): the #GError to be set in case of error
+ *
+ * Generate username based on the string @str and then validate the generated
+ * user name against #GUM_NAME_PATTERN pattern.
+ *
+ * Returns: (transfer full): string if successful, NULL otherwise.
+ */
gchar *
gum_validate_generate_username (
const gchar *str,
return gen_name;
}
+/**
+ * gum_validate_db_string_entry_regx:
+ * @str: (transfer none): the string to be validated
+ * @error: (transfer none): the #GError to be set in case of error
+ *
+ * Validates the string @str against the #GUM_DB_ENTRY_PATTERN pattern using
+ * regular expressions.
+ *
+ * Returns: TRUE if validation succeeds, FALSE otherwise.
+ */
gboolean
gum_validate_db_string_entry_regx (
const gchar *str,
return TRUE;
}
+/**
+ * gum_validate_db_string_entry:
+ * @str: (transfer none): the string to be validated
+ * @error: (transfer none): the #GError to be set in case of error
+ *
+ * Validates the string @str to be used in the user/group database. No control
+ * chars (0x00-0x1F,0x7F), comma (',' 0x2c) or colon (':' 0x3A) is allowed.
+ *
+ * Returns: TRUE if validation succeeds, FALSE otherwise.
+ */
gboolean
gum_validate_db_string_entry (
const gchar *str,
return TRUE;
}
+/**
+ * gum_validate_db_secret_entry:
+ * @str: (transfer none): the string to be validated
+ * @error: (transfer none): the #GError to be set in case of error
+ *
+ * Validates the string @str to be used as secret in the user/group database.
+ * No control chars (0x00-0x1F,0x7F) or colon (':' 0x3A) is allowed.
+ *
+ * Returns: TRUE if validation succeeds, FALSE otherwise.
+ */
gboolean
gum_validate_db_secret_entry (
const gchar *str,
_sync_group_properties (G_OBJECT (adapter->priv->group),
G_OBJECT (adapter->priv->dbus_group));
- nonce = gum_generate_nonce ();
+ nonce = gum_generate_nonce (G_CHECKSUM_SHA1);
object_path = g_strdup_printf ("%s/Group_%s_%d",
GUM_GROUP_SERVICE_OBJECTPATH, nonce, object_counter++);
g_free (nonce);
_sync_user_properties (G_OBJECT (adapter->priv->user),
G_OBJECT (adapter->priv->dbus_user));
- nonce = gum_generate_nonce ();
+ nonce = gum_generate_nonce (G_CHECKSUM_SHA1);
object_path = g_strdup_printf ("%s/User_%s_%d",
GUM_USER_SERVICE_OBJECTPATH, nonce, object_counter++);
g_free (nonce);