gum-dbus-user-gen.h\
gum-dbus-user-service-gen.h\
gum-dbus-group-gen.h\
-gum-dbus-group-service-gen.h
+gum-dbus-group-service-gen.h \
+gum-defines.h \
+gum-dbus.h
+
# Images to copy into HTML directory.
# e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png
GUM_OPTYPE_MODIFY = 3
} GumOpType;
-typedef gboolean (*GumFileUpdateFunc) (
+typedef gboolean (*GumFileUpdateCB) (
GObject *object,
GumOpType op,
- FILE *origf,
- FILE *newf,
+ FILE *source_file,
+ FILE *dup_file,
gpointer user_data,
GError **error);
gum_file_update (
GObject *object,
GumOpType op,
- GumFileUpdateFunc update_func,
- const gchar *origfn,
+ GumFileUpdateCB callback,
+ const gchar *source_file_path,
gpointer user_data,
GError **error);
gboolean
gum_file_open_db_files (
- const gchar *origfn,
- const gchar *newfn,
- FILE **origf,
- FILE **newf,
+ const gchar *source_file_path,
+ const gchar *dup_file_path,
+ FILE **source_file,
+ FILE **dup_file,
GError **error);
gboolean
gum_file_close_db_files (
- const gchar *origfn,
- const gchar *newfn,
- FILE *orig,
- FILE *newf,
+ const gchar *source_file_path,
+ const gchar *dup_file_path,
+ FILE *source_file,
+ FILE *dup_file,
GError **error);
struct passwd *
* @title: Gum File
* @include: gum/common/gum-file.h
*
+ * Below is the code snippet, which demonstrate how can file update function be
+ * used to add, remove or modify an entry in the user/group database file
+ * (e.g. /etc/passwd).
*
* |[
*
+ * gboolean _custom_update_file_entries (GObject *obj, GumOpType op,
+ * FILE *source_file, FILE *dup_file, gpointer user_data, GError **error)
+ * {
+ * //loop through the file entries and modify as per operation type
+ * return TRUE;
+ * }
+ *
+ * void update_file_entries ()
+ * {
+ * GObject* obj = NULL;
+ * GError *error = NULL;
+ * const gchar *source_file = "/tmp/passwd";
+ * gum_file_update (obj, GUM_OPTYPE_ADD,
+ * (GumFileUpdateCB)_custom_update_file_entries, source_file, NULL,
+ * &error);
+ * }
+ *
* ]|
*/
+/**
+ * GumOpType:
+ * @GUM_OPTYPE_ADD: add an entry
+ * @GUM_OPTYPE_DELETE: delete an entry
+ * @GUM_OPTYPE_MODIFY: modify an entry
+ *
+ * This enumeration lists the operations on file entry.
+ */
+
+/**
+ * GumFileUpdateCB:
+ * @object: (transfer none): the instance of #GObject
+ * @op: (transfer none): the #GumOpType operation to be done on the file entry
+ * @source_file: (transfer none): the source file pointer
+ * @dup_file: (transfer none): the duplicate file pointer
+ * @user_data: the user data
+ * @error: (transfer none): the #GError which is set in case of an error
+ *
+ * Callback can be used for adding, deleting or modifying file entries. It is
+ * invoked in #gum_file_update function.
+ *
+ * Returns: TRUE if successful, FALSE otherwise and @error is set.
+ */
+
#define GUM_PERM 0777
static FILE *
return ret;
}
+/**
+ * gum_file_open_db_files:
+ * @source_file_path: (transfer none): the path to source file
+ * @dup_file_path: (transfer none): the path to duplicate file, created from
+ * the source file
+ * @source_file: (transfer none): the file pointer created when source file
+ * is opened in read mode
+ * @dup_file: (transfer none): the file pointer created when duplicate file is
+ * opened in write mode
+ * @error: (transfer none): the #GError which is set in case of an error
+ *
+ * Opens the source file @source_file_path in read mode. Then creates the
+ * duplicate file @dup_file_path in write mode and copies source file attributes
+ * to the duplicate file. Open file handles are set in @source_file and
+ * @dup_file.
+ *
+ * Returns: TRUE if successful, FALSE otherwise and @error is set.
+ */
gboolean
gum_file_open_db_files (
- const gchar *origfn,
- const gchar *newfn,
- FILE **origf,
- FILE **newf,
+ const gchar *source_file_path,
+ const gchar *dup_file_path,
+ FILE **source_file,
+ FILE **dup_file,
GError **error)
{
- if (!origfn || !origf || !(*origf = _open_file (origfn, "r"))) {
- DBG("origfn %s --- orig %p", origfn ? origfn : "NULL", origf);
+ if (!source_file_path || !source_file ||
+ !(*source_file = _open_file (source_file_path, "r"))) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_OPEN, "Unable to open orig file",
error, FALSE);
}
- if (!newfn || !newf || !(*newf = _open_file (newfn, "w+"))) {
- if (*origf) fclose (*origf);
+ if (!dup_file_path || !dup_file ||
+ !(*dup_file = _open_file (dup_file_path, "w+"))) {
+ if (*source_file) fclose (*source_file);
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_OPEN, "Unable to open new file",
error, FALSE);
}
- if (!_copy_file_attributes (origfn, newfn)) {
- if (*origf) fclose (*origf);
- if (*newf) fclose (*newf);
- g_unlink (newfn);
+ if (!_copy_file_attributes (source_file_path, dup_file_path)) {
+ if (*source_file) fclose (*source_file);
+ if (*dup_file) fclose (*dup_file);
+ g_unlink (dup_file_path);
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_ATTRIBUTE,
"Unable to get/set file attributes", error, FALSE);
}
return TRUE;
}
+/**
+ * gum_file_close_db_files:
+ * @source_file_path: (transfer none): the path to source file
+ * @dup_file_path: (transfer none): the path to duplicate file
+ * @source_file: (transfer none): the source file pointer
+ * @dup_file: (transfer none): the duplicate file pointer
+ * @error: (transfer none): the #GError which is set in case of an error
+ *
+ * Closes the duplicate file @dup_file_path after flushing all the data. Backup
+ * of the source file @source_file_path is created and duplicate file is renamed
+ * to as the source file.
+ *
+ * Returns: TRUE if successful, FALSE otherwise and @error is set.
+ */
gboolean
gum_file_close_db_files (
- const gchar *origfn,
- const gchar *newfn,
- FILE *origf,
- FILE *newf,
+ const gchar *source_file_path,
+ const gchar *dup_file_path,
+ FILE *source_file,
+ FILE *dup_file,
GError **error)
{
gboolean retval = TRUE;
gchar *old_file = NULL;
- if (!newf ||
- !newfn ||
- fflush (newf) != 0 ||
- fsync (fileno (newf)) != 0 ||
- fclose (newf) != 0) {
- GUM_SET_ERROR (GUM_ERROR_FILE_WRITE, "File write failure", error, retval,
- FALSE);
+ if (!dup_file ||
+ !dup_file_path ||
+ fflush (dup_file) != 0 ||
+ fsync (fileno (dup_file)) != 0 ||
+ fclose (dup_file) != 0) {
+ GUM_SET_ERROR (GUM_ERROR_FILE_WRITE, "File write failure", error,
+ retval, FALSE);
goto _close_new;
}
- newf = NULL;
+ dup_file = NULL;
- /* Move original file to old file and new file as updated file */
- old_file = g_strdup_printf ("%s.old", origfn);
+ /* Move source file to old file and dup file as updated file */
+ old_file = g_strdup_printf ("%s.old", source_file_path);
if (!old_file) {
GUM_SET_ERROR (GUM_ERROR_FILE_MOVE, "Unable to create old file", error,
retval, FALSE);
}
g_unlink (old_file);
- if (link (origfn, old_file) != 0 ||
- g_rename (newfn, origfn) != 0) {
- GUM_SET_ERROR (GUM_ERROR_FILE_MOVE, "Unable to move file", error, retval,
- FALSE);
+ if (link (source_file_path, old_file) != 0 ||
+ g_rename (dup_file_path, source_file_path) != 0) {
+ GUM_SET_ERROR (GUM_ERROR_FILE_MOVE, "Unable to move file", error,
+ retval, FALSE);
}
_close_new:
- if (newf) fclose (newf);
- g_unlink (newfn);
+ if (dup_file) fclose (dup_file);
+ g_unlink (dup_file_path);
- if (origf) fclose (origf);
+ if (source_file) fclose (source_file);
g_free (old_file);
return retval;
}
+/**
+ * gum_file_update:
+ * @object: (transfer none): the instance of #GObject; can be NULL
+ * @op: (transfer none): the #GumOpType operation to be done on file entry
+ * the source file
+ * @callback: (transfer none): the callback #GumFileUpdateCB to be invoked
+ * when the source and duplicate files are opened to be handled
+ * @source_file_path: (transfer none): the source file path
+ * @user_data: user data to be passed on to the @callback
+ * @error: (transfer none): the #GError which is set in case of an error
+ *
+ * Opens the files and invokes the callback to do the required operation.
+ * Finally files are flushed and closed.
+ *
+ * Returns: TRUE if successful, FALSE otherwise and @error is set.
+ */
gboolean
gum_file_update (
GObject *object,
GumOpType op,
- GumFileUpdateFunc update_func,
- const gchar *origfn,
+ GumFileUpdateCB callback,
+ const gchar *source_file_path,
gpointer user_data,
GError **error)
{
- /* open files
- * read (current) file
- ** write 1-by-1 line to new file along with the
- ** modification (add/remove/modify)
- * rename files and move original file to old file
- * close files
- * */
gboolean retval = TRUE;
- FILE *origf = NULL, *newf = NULL;
- gchar *newfn = NULL;
+ FILE *source_file = NULL, *dup_file = NULL;
+ gchar *dup_file_path = NULL;
- newfn = g_strdup_printf ("%s-tmp.%lu", origfn, (unsigned long)getpid ());
- retval = gum_file_open_db_files (origfn, newfn, &origf, &newf, error);
+ dup_file_path = g_strdup_printf ("%s-tmp.%lu", source_file_path,
+ (unsigned long)getpid ());
+ retval = gum_file_open_db_files (source_file_path, dup_file_path,
+ &source_file, &dup_file, error);
if (!retval) goto _finished;
/* Update, sync and close file */
- if (!update_func) {
- GUM_SET_ERROR (GUM_ERROR_FILE_WRITE, "File write function not specified",
- error, retval, FALSE);
+ if (!callback) {
+ GUM_SET_ERROR (GUM_ERROR_FILE_WRITE,
+ "File write function not specified", error, retval, FALSE);
goto _close;
}
- retval = (*update_func) (object, op, origf, newf, user_data, error);
+ retval = (*callback) (object, op, source_file, dup_file, user_data, error);
if (!retval) {
goto _close;
}
- retval = gum_file_close_db_files (origfn, newfn, origf, newf, error);
+ retval = gum_file_close_db_files (source_file_path, dup_file_path,
+ source_file, dup_file, error);
_close:
if (!retval) {
- if (newf) fclose (newf);
- g_unlink (newfn);
- if (origf) fclose (origf);
+ if (dup_file) fclose (dup_file);
+ g_unlink (dup_file_path);
+ if (source_file) fclose (source_file);
}
_finished:
- g_free (newfn);
+ g_free (dup_file_path);
return retval;
}
* @title: Gum String Utils
* @include: gum/common/gum-string-utils.h
*
+ * String utility functions
+ *
*/
/**
* @title: Gum Utils
* @include: gum/common/gum-utils.h
*
+ * Utility functions
*/
typedef struct __nonce_ctx_t
* @title: Gum Validate
* @include: gum/common/gum-validate.h
*
+ * Name/secret validation functions
*/
/**
_update_daemon_group_entry (
GumdDaemonGroup *self,
GumOpType op,
- FILE *origf,
- FILE *newf,
+ FILE *source_file,
+ FILE *dup_file,
gpointer user_data,
GError **error)
{
gboolean done = FALSE;
struct group *entry;
- while ((entry = fgetgrent (origf)) != NULL) {
+ while ((entry = fgetgrent (source_file)) != NULL) {
if (!done) {
switch (op) {
case GUM_OPTYPE_ADD:
if (self->priv->group->gr_gid < entry->gr_gid) {
- if (putgrent (self->priv->group, newf) < 0) {
+ if (putgrent (self->priv->group, dup_file) < 0) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_WRITE,
"File write failure", error, FALSE);
}
self->priv->group->gr_name;
if (self->priv->group->gr_gid == entry->gr_gid &&
g_strcmp0 (old_name, entry->gr_name) == 0) {
- if (putgrent (self->priv->group, newf) < 0) {
+ if (putgrent (self->priv->group, dup_file) < 0) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_WRITE,
"File write failure", error, FALSE);
}
break;
}
}
- if (putgrent (entry, newf) < 0) {
+ if (putgrent (entry, dup_file) < 0) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_WRITE, "File write failure",
error, FALSE);
}
/* Write entry to file in case it is first entry in the file */
if (!done && op == GUM_OPTYPE_ADD) {
- if (putgrent (self->priv->group, newf) < 0) {
+ if (putgrent (self->priv->group, dup_file) < 0) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_WRITE, "File write failure",
error, FALSE);
}
_update_gshadow_entry (
GumdDaemonGroup *self,
GumOpType op,
- FILE *origf,
- FILE *newf,
+ FILE *source_file,
+ FILE *dup_file,
gpointer user_data,
GError **error)
{
gboolean done = FALSE;
struct sgrp *entry = NULL;
- while ((entry = fgetsgent (origf)) != NULL) {
+ while ((entry = fgetsgent (source_file)) != NULL) {
if (!done) {
switch (op) {
case GUM_OPTYPE_ADD:
gchar *old_name = user_data ? (gchar *)user_data :
self->priv->gshadow->sg_namp;
if (g_strcmp0 (old_name, entry->sg_namp) == 0) {
- if (putsgent (self->priv->gshadow, newf) < 0) {
+ if (putsgent (self->priv->gshadow, dup_file) < 0) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_WRITE,
"File write failure", error, FALSE);
}
break;
}
}
- if (putsgent (entry, newf) < 0) {
+ if (putsgent (entry, dup_file) < 0) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_WRITE, "File write failure",
error, FALSE);
}
/* Write entry to file in case it is first entry in the file */
if (!done && op == GUM_OPTYPE_ADD) {
- if (putsgent (self->priv->gshadow, newf) < 0) {
+ if (putsgent (self->priv->gshadow, dup_file) < 0) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_WRITE, "File write failure",
error, FALSE);
}
}
if (!gum_file_update (G_OBJECT (self), GUM_OPTYPE_ADD,
- (GumFileUpdateFunc)_update_daemon_group_entry,
+ (GumFileUpdateCB)_update_daemon_group_entry,
gum_config_get_string (self->priv->config,
GUM_CONFIG_GENERAL_GROUP_FILE), NULL, error)) {
gum_lock_pwdf_unlock ();
GUM_CONFIG_GENERAL_GSHADOW_FILE);
if (g_file_test (shadow_file, G_FILE_TEST_EXISTS) &&
!gum_file_update (G_OBJECT (self), GUM_OPTYPE_ADD,
- (GumFileUpdateFunc)_update_gshadow_entry, shadow_file, NULL,
+ (GumFileUpdateCB)_update_gshadow_entry, shadow_file, NULL,
error)) {
gum_lock_pwdf_unlock ();
return FALSE;
}
if (!gum_file_update (G_OBJECT (self), GUM_OPTYPE_DELETE,
- (GumFileUpdateFunc)_update_daemon_group_entry,
+ (GumFileUpdateCB)_update_daemon_group_entry,
gum_config_get_string (self->priv->config,
GUM_CONFIG_GENERAL_GROUP_FILE), NULL, error)) {
gum_lock_pwdf_unlock ();
GUM_CONFIG_GENERAL_GSHADOW_FILE);
if (g_file_test (shadow_file, G_FILE_TEST_EXISTS) &&
!gum_file_update (G_OBJECT (self), GUM_OPTYPE_DELETE,
- (GumFileUpdateFunc)_update_gshadow_entry, shadow_file, NULL,
+ (GumFileUpdateCB)_update_gshadow_entry, shadow_file, NULL,
error)) {
gum_lock_pwdf_unlock ();
return FALSE;
GUM_STR_DUP (grp->gr_name, old_name);
if (!gum_file_update (G_OBJECT (self), GUM_OPTYPE_MODIFY,
- (GumFileUpdateFunc)_update_daemon_group_entry,
+ (GumFileUpdateCB)_update_daemon_group_entry,
gum_config_get_string (self->priv->config,
GUM_CONFIG_GENERAL_GROUP_FILE), old_name, error)) {
g_free (old_name);
GUM_CONFIG_GENERAL_GSHADOW_FILE);
if (g_file_test (shadow_file, G_FILE_TEST_EXISTS) &&
!gum_file_update (G_OBJECT (self), GUM_OPTYPE_MODIFY,
- (GumFileUpdateFunc)_update_gshadow_entry,
+ (GumFileUpdateCB)_update_gshadow_entry,
shadow_file, old_name, error)) {
g_free (old_name);
gum_lock_pwdf_unlock ();
}
if (!gum_file_update (G_OBJECT (self), GUM_OPTYPE_MODIFY,
- (GumFileUpdateFunc)_update_daemon_group_entry,
+ (GumFileUpdateCB)_update_daemon_group_entry,
gum_config_get_string (self->priv->config,
GUM_CONFIG_GENERAL_GROUP_FILE), NULL, error)) {
gum_lock_pwdf_unlock ();
GUM_CONFIG_GENERAL_GSHADOW_FILE);
if (g_file_test (shadow_file, G_FILE_TEST_EXISTS) &&
!gum_file_update (G_OBJECT (self), GUM_OPTYPE_MODIFY,
- (GumFileUpdateFunc)_update_gshadow_entry, shadow_file,
+ (GumFileUpdateCB)_update_gshadow_entry, shadow_file,
NULL, error)) {
gum_lock_pwdf_unlock ();
return FALSE;
}
if (!gum_file_update (G_OBJECT (self), GUM_OPTYPE_MODIFY,
- (GumFileUpdateFunc)_update_daemon_group_entry,
+ (GumFileUpdateCB)_update_daemon_group_entry,
gum_config_get_string (self->priv->config,
GUM_CONFIG_GENERAL_GROUP_FILE), NULL, error)) {
gum_lock_pwdf_unlock ();
GUM_CONFIG_GENERAL_GSHADOW_FILE);
if (g_file_test (shadow_file, G_FILE_TEST_EXISTS) &&
!gum_file_update (G_OBJECT (self), GUM_OPTYPE_MODIFY,
- (GumFileUpdateFunc)_update_gshadow_entry, shadow_file, NULL,
+ (GumFileUpdateCB)_update_gshadow_entry, shadow_file, NULL,
error)) {
gum_lock_pwdf_unlock ();
return FALSE;
GError **error)
{
gboolean retval = TRUE;
- FILE *origf = NULL, *newf = NULL;
- gchar *newfn = NULL;
- const gchar *origfn = NULL;
+ FILE *source_file = NULL, *dup_file = NULL;
+ gchar *dup_file_path = NULL;
+ const gchar *source_file_path = NULL;
if (!config || !user_name) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_GROUP_INVALID_DATA,
}
/* update group entries */
- origfn = gum_config_get_string (config, GUM_CONFIG_GENERAL_GROUP_FILE);
- newfn = g_strdup_printf ("%s-tmp.%lu", origfn, (unsigned long)getpid ());
+ source_file_path = gum_config_get_string (config,
+ GUM_CONFIG_GENERAL_GROUP_FILE);
+ dup_file_path = g_strdup_printf ("%s-tmp.%lu", source_file_path,
+ (unsigned long)getpid ());
- retval = gum_file_open_db_files (origfn, newfn, &origf, &newf, error);
+ retval = gum_file_open_db_files (source_file_path, dup_file_path,
+ &source_file, &dup_file, error);
if (!retval) goto _finished;
struct group *gent = NULL;
- while ((gent = fgetgrent (origf)) != NULL) {
+ while ((gent = fgetgrent (source_file)) != NULL) {
if (gum_string_utils_search_stringv (gent->gr_mem, user_name)) {
gint status = 0;
GUM_STR_FREEV (gdest->gr_mem);
gdest->gr_mem = gum_string_utils_delete_string (gent->gr_mem,
user_name);
- status = putgrent (gdest, newf);
+ status = putgrent (gdest, dup_file);
_free_daemon_group_entry (gdest);
if (status < 0) {
GUM_SET_ERROR (GUM_ERROR_FILE_WRITE, "File write failure",
break;
}
- } else if (putgrent (gent, newf) < 0) {
+ } else if (putgrent (gent, dup_file) < 0) {
GUM_SET_ERROR (GUM_ERROR_FILE_WRITE, "File write failure",
error, retval, FALSE);
break;
}
}
if (!retval) {
- fclose (newf);
- g_unlink (newfn);
- fclose (origf);
+ fclose (dup_file);
+ g_unlink (dup_file_path);
+ fclose (source_file);
} else {
- retval = gum_file_close_db_files (origfn, newfn, origf, newf, error);
+ retval = gum_file_close_db_files (source_file_path, dup_file_path,
+ source_file, dup_file, error);
}
- newf = NULL; origf = NULL;
- g_free (newfn); newfn = NULL;
+ dup_file = NULL; source_file = NULL;
+ g_free (dup_file_path); dup_file_path = NULL;
/* update gshadow entries */
- origfn = gum_config_get_string (config, GUM_CONFIG_GENERAL_GSHADOW_FILE);
- if (!g_file_test (origfn, G_FILE_TEST_EXISTS)) goto _finished;
+ source_file_path = gum_config_get_string (config,
+ GUM_CONFIG_GENERAL_GSHADOW_FILE);
+ if (!g_file_test (source_file_path, G_FILE_TEST_EXISTS)) goto _finished;
- newfn = g_strdup_printf ("%s-tmp.%lu", origfn, (unsigned long)getpid ());
+ dup_file_path = g_strdup_printf ("%s-tmp.%lu", source_file_path,
+ (unsigned long)getpid ());
- retval = gum_file_open_db_files (origfn, newfn, &origf, &newf, error);
+ retval = gum_file_open_db_files (source_file_path, dup_file_path,
+ &source_file, &dup_file, error);
if (!retval) goto _finished;
struct sgrp *gsent = NULL;
- while ((gsent = fgetsgent (origf)) != NULL) {
+ while ((gsent = fgetsgent (source_file)) != NULL) {
gboolean is_mem = gum_string_utils_search_stringv (gsent->sg_mem,
user_name);
user_name);
}
- status = putsgent (gsdest, newf);
+ status = putsgent (gsdest, dup_file);
_free_gshadow_entry (gsdest);
if (status < 0) {
GUM_SET_ERROR (GUM_ERROR_FILE_WRITE, "File write failure",
break;
}
- } else if (putsgent (gsent, newf) < 0) {
+ } else if (putsgent (gsent, dup_file) < 0) {
GUM_SET_ERROR (GUM_ERROR_FILE_WRITE, "File write failure",
error, retval, FALSE);
break;
}
if (!retval) {
- fclose (newf);
- g_unlink (newfn);
- fclose (origf);
+ fclose (dup_file);
+ g_unlink (dup_file_path);
+ fclose (source_file);
} else {
- retval = gum_file_close_db_files (origfn, newfn, origf, newf, error);
+ retval = gum_file_close_db_files (source_file_path, dup_file_path,
+ source_file, dup_file, error);
}
_finished:
- g_free (newfn);
+ g_free (dup_file_path);
gum_lock_pwdf_unlock ();
return retval;
_update_passwd_entry (
GumdDaemonUser *self,
GumOpType op,
- FILE *origf,
- FILE *newf,
+ FILE *source_file,
+ FILE *dup_file,
gpointer user_data,
GError **error)
{
gboolean done = FALSE;
struct passwd *entry;
- while ((entry = fgetpwent (origf)) != NULL) {
+ while ((entry = fgetpwent (source_file)) != NULL) {
if (!done) {
switch (op) {
case GUM_OPTYPE_ADD:
if (self->priv->pw->pw_uid < entry->pw_uid) {
- if (putpwent (self->priv->pw, newf) < 0) {
+ if (putpwent (self->priv->pw, dup_file) < 0) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_WRITE,
"File write failure", error, FALSE);
}
if (self->priv->pw->pw_uid == entry->pw_uid &&
self->priv->pw->pw_gid == entry->pw_gid &&
g_strcmp0 (old_name, entry->pw_name) == 0) {
- if (putpwent (self->priv->pw, newf) < 0) {
+ if (putpwent (self->priv->pw, dup_file) < 0) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_WRITE,
"File write failure", error, FALSE);
}
break;
}
}
- if (putpwent (entry, newf) < 0) {
+ if (putpwent (entry, dup_file) < 0) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_WRITE, "File write failure",
error, FALSE);
}
/* Write entry to file in case it is first entry in the file */
if (!done && op == GUM_OPTYPE_ADD) {
- if (putpwent (self->priv->pw, newf) < 0) {
+ if (putpwent (self->priv->pw, dup_file) < 0) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_WRITE, "Add entry failure",
error, FALSE);
}
_lock_shadow_entry (
GumdDaemonUser *self,
GumOpType op,
- FILE *origf,
- FILE *newf,
+ FILE *source_file,
+ FILE *dup_file,
gpointer user_data,
GError **error)
{
"File write failure", error, FALSE);
}
- while ((entry = fgetspent (origf)) != NULL) {
+ while ((entry = fgetspent (source_file)) != NULL) {
if (!done) {
switch (op) {
case GUM_OPTYPE_MODIFY: {
/* entry is locked, unlock it */
spent->sp_pwdp = g_strdup (entry->sp_pwdp+1);
}
- ret = putspent (spent, newf);
+ ret = putspent (spent, dup_file);
_free_shadow_entry (spent);
if (ret < 0) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_WRITE,
break;
}
}
- if (putspent (entry, newf) < 0) {
+ if (putspent (entry, dup_file) < 0) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_WRITE, "File write failure",
error, FALSE);
}
_update_shadow_entry (
GumdDaemonUser *self,
GumOpType op,
- FILE *origf,
- FILE *newf,
+ FILE *source_file,
+ FILE *dup_file,
gpointer user_data,
GError **error)
{
gboolean done = FALSE;
struct spwd *entry = NULL;
- while ((entry = fgetspent (origf)) != NULL) {
+ while ((entry = fgetspent (source_file)) != NULL) {
if (!done) {
switch (op) {
case GUM_OPTYPE_ADD:
gchar *old_name = user_data ? (gchar *)user_data :
self->priv->shadow->sp_namp;
if (g_strcmp0 (old_name, entry->sp_namp) == 0) {
- if (putspent (self->priv->shadow, newf) < 0) {
+ if (putspent (self->priv->shadow, dup_file) < 0) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_WRITE,
"File write failure", error, FALSE);
}
break;
}
}
- if (putspent (entry, newf) < 0) {
+ if (putspent (entry, dup_file) < 0) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_WRITE, "File write failure",
error, FALSE);
}
/* Write entry to file in case it is first entry in the file */
if (!done && op == GUM_OPTYPE_ADD) {
- if (putspent (self->priv->shadow, newf) < 0) {
+ if (putspent (self->priv->shadow, dup_file) < 0) {
GUM_RETURN_WITH_ERROR (GUM_ERROR_FILE_WRITE, "Add entry failure",
error, FALSE);
}
}
if (!gum_file_update (G_OBJECT (self), GUM_OPTYPE_ADD,
- (GumFileUpdateFunc)_update_passwd_entry,
+ (GumFileUpdateCB)_update_passwd_entry,
gum_config_get_string (self->priv->config,
GUM_CONFIG_GENERAL_PASSWD_FILE), NULL, error) ||
!gum_file_update (G_OBJECT (self), GUM_OPTYPE_ADD,
- (GumFileUpdateFunc)_update_shadow_entry,
+ (GumFileUpdateCB)_update_shadow_entry,
gum_config_get_string (self->priv->config,
GUM_CONFIG_GENERAL_SHADOW_FILE), NULL, error)) {
gum_lock_pwdf_unlock ();
/* lock the user */
if (!gum_file_update (G_OBJECT (self), GUM_OPTYPE_MODIFY,
- (GumFileUpdateFunc)_lock_shadow_entry,
+ (GumFileUpdateCB)_lock_shadow_entry,
gum_config_get_string (self->priv->config,
GUM_CONFIG_GENERAL_SHADOW_FILE), &lock, error)) {
gum_lock_pwdf_unlock ();
/* unlock the user */
lock = FALSE;
gum_file_update (G_OBJECT (self), GUM_OPTYPE_MODIFY,
- (GumFileUpdateFunc)_lock_shadow_entry,
+ (GumFileUpdateCB)_lock_shadow_entry,
gum_config_get_string (self->priv->config,
GUM_CONFIG_GENERAL_SHADOW_FILE), &lock, NULL);
gum_lock_pwdf_unlock ();
}
if (!gum_file_update (G_OBJECT (self), GUM_OPTYPE_DELETE,
- (GumFileUpdateFunc)_update_passwd_entry,
+ (GumFileUpdateCB)_update_passwd_entry,
gum_config_get_string (self->priv->config,
GUM_CONFIG_GENERAL_PASSWD_FILE), NULL, error) ||
!gum_file_update (G_OBJECT (self), GUM_OPTYPE_DELETE,
- (GumFileUpdateFunc)_update_shadow_entry,
+ (GumFileUpdateCB)_update_shadow_entry,
gum_config_get_string (self->priv->config,
GUM_CONFIG_GENERAL_SHADOW_FILE), NULL, error)) {
/* unlock the user */
lock = FALSE;
gum_file_update (G_OBJECT (self), GUM_OPTYPE_MODIFY,
- (GumFileUpdateFunc)_lock_shadow_entry,
+ (GumFileUpdateCB)_lock_shadow_entry,
gum_config_get_string (self->priv->config,
GUM_CONFIG_GENERAL_SHADOW_FILE), &lock, NULL);
gum_lock_pwdf_unlock ();
GUM_STR_DUP (pw->pw_name, old_name);
if (!gum_file_update (G_OBJECT (self), GUM_OPTYPE_MODIFY,
- (GumFileUpdateFunc)_update_passwd_entry,
+ (GumFileUpdateCB)_update_passwd_entry,
gum_config_get_string (self->priv->config,
GUM_CONFIG_GENERAL_PASSWD_FILE), old_name, error) ||
!gum_file_update (G_OBJECT (self), GUM_OPTYPE_MODIFY,
- (GumFileUpdateFunc)_update_shadow_entry,
+ (GumFileUpdateCB)_update_shadow_entry,
gum_config_get_string (self->priv->config,
GUM_CONFIG_GENERAL_SHADOW_FILE), old_name, error)) {
g_free (old_name);
fail_if (stat (origfn, &origst) < 0);
fail_unless (gum_file_update (user, GUM_OPTYPE_ADD,
- (GumFileUpdateFunc)_update_file_entries, origfn, NULL,
+ (GumFileUpdateCB)_update_file_entries, origfn, NULL,
&error) == TRUE);
fail_unless (error == NULL);