OpenSync  0.22
opensync_user.c
1 /*
2  * libopensync - A synchronization framework
3  * Copyright (C) 2004-2005 Armin Bauer <armin.bauer@opensync.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  */
20 
21 #include "opensync.h"
22 #include "opensync_internals.h"
23 
31 
32 
41 {
42  OSyncUserInfo *user = osync_try_malloc0(sizeof(OSyncUserInfo), error);
43  if (!user)
44  return NULL;
45 
46  user->uid = getuid();
47  user->gid = getgid();
48 
49  user->homedir = g_get_home_dir();
50  user->username = g_get_user_name();
51 
52  user->confdir = g_strdup_printf("%s/.opensync", user->homedir);
53 
54  osync_trace(TRACE_INTERNAL, "Detected User:\nUID: %i\nGID: %i\nHome: %s\nOSyncDir: %s", user->uid, user->gid, user->homedir, user->confdir);
55 
56  return user;
57 }
58 
59 
60 void osync_user_free(OSyncUserInfo *info)
61 {
62  g_free(info->confdir);
63 
64  g_free(info);
65 }
66 
75 void osync_user_set_confdir(OSyncUserInfo *user, const char *path)
76 {
77  g_assert(user);
78 
79  if (user->confdir)
80  g_free(user->confdir);
81 
82  user->confdir = g_strdup(path);
83 }
84 
94 {
95  g_assert(user);
96  return user->confdir;
97 }
98