summaryrefslogtreecommitdiffstats
path: root/debian/opensync/opensync-0.22/opensync/opensync_user.c
blob: fcfe950f979f376fe6a73f13277ed33b9c51abe4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * libopensync - A synchronization framework
 * Copyright (C) 2004-2005  Armin Bauer <armin.bauer@opensync.org>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 * 
 */
 
#include "opensync.h"
#include "opensync_internals.h"

/**
 * @defgroup OSyncEnvUserPrivate OpenSync User Internals
 * @ingroup OSyncPrivate
 * @brief The private API of dealing with users
 * 
 */
/*@{*/


/*! @brief This will create a new user
 * 
 * The user will hold information like uid, gid, home directory etc
 * 
 * @returns A pointer to a newly allocated OSyncUserInfo
 * 
 */
OSyncUserInfo *osync_user_new(OSyncError **error)
{
	OSyncUserInfo *user = osync_try_malloc0(sizeof(OSyncUserInfo), error);
	if (!user)
		return NULL;
	
	user->uid = getuid();
	user->gid = getgid();
	
	user->homedir = g_get_home_dir();
	user->username = g_get_user_name();
	
	user->confdir = g_strdup_printf("%s/.opensync", user->homedir);
	
	osync_trace(TRACE_INTERNAL, "Detected User:\nUID: %i\nGID: %i\nHome: %s\nOSyncDir: %s", user->uid, user->gid, user->homedir, user->confdir);
	
	return user;
}


void osync_user_free(OSyncUserInfo *info)
{
	g_free(info->confdir);
	
	g_free(info);
}

/*! @brief This will set the configdir for the given user
 * 
 * This will set the configdir for the given user
 * 
 * @param user The user to change
 * @param path The new configdir path
 * 
 */
void osync_user_set_confdir(OSyncUserInfo *user, const char *path)
{
	g_assert(user);
	
	if (user->confdir)
		g_free(user->confdir);
	
	user->confdir = g_strdup(path);
}

/*! @brief This will get the configdir for the given user
 * 
 * This will set the configdir for the given user
 * 
 * @param user The user to get the path from
 * @returns The configdir path
 * 
 */
const char *osync_user_get_confdir(OSyncUserInfo *user)
{
	g_assert(user);
	return user->confdir;
}

/*@}*/