~ubuntu-branches/ubuntu/trusty/policykit-1/trusty

« back to all changes in this revision

Viewing changes to src/polkit/polkitunixuser.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2012-01-06 12:28:54 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20120106122854-ib9s0ej8akqiy0lb
Tags: 0.104-1
* New upstream release.
  - Add support for netgroups. (LP: #724052)
* debian/rules: Disable systemd support, continue to work with ConsokeKit.
* 05_revert-admin-identities-unix-group-wheel.patch: Refresh to apply
  cleanly.
* debian/libpolkit-gobject-1-0.symbols: Add new symbols from this new
  release.
* debian/rules: Do not let test failures fail the build. The new test suite
  also runs a test against the system D-BUS/ConsoleKit, which can't work on
  buildds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
  GObject parent_instance;
50
50
 
51
51
  gint uid;
 
52
  gchar *name;
52
53
};
53
54
 
54
55
struct _PolkitUnixUserClass
71
72
static void
72
73
polkit_unix_user_init (PolkitUnixUser *unix_user)
73
74
{
 
75
  unix_user->name = NULL;
 
76
}
 
77
 
 
78
static void
 
79
polkit_unix_user_finalize (GObject *object)
 
80
{
 
81
  PolkitUnixUser *unix_user = POLKIT_UNIX_USER (object);
 
82
 
 
83
  g_free(unix_user->name);
 
84
 
 
85
  G_OBJECT_CLASS (polkit_unix_user_parent_class)->finalize (object);
74
86
}
75
87
 
76
88
static void
118
130
{
119
131
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
120
132
 
 
133
  gobject_class->finalize = polkit_unix_user_finalize;
121
134
  gobject_class->get_property = polkit_unix_user_get_property;
122
135
  gobject_class->set_property = polkit_unix_user_set_property;
123
136
 
228
241
  return identity;
229
242
}
230
243
 
 
244
/**
 
245
 * polkit_unix_user_get_name:
 
246
 * @user: A #PolkitUnixUser.
 
247
 *
 
248
 * Get the user's name.
 
249
 *
 
250
 * Returns: (allow-none) (transfer none): User name string or %NULL if user uid not found.
 
251
 */
 
252
const gchar *
 
253
polkit_unix_user_get_name (PolkitUnixUser *user)
 
254
{
 
255
  if (user->name == NULL)
 
256
    {
 
257
      struct passwd *passwd;
 
258
      passwd = getpwuid (user->uid);
 
259
 
 
260
      if (passwd != NULL)
 
261
        user->name = g_strdup(passwd->pw_name);
 
262
    }
 
263
 
 
264
  return user->name;
 
265
}
 
266
 
231
267
static gboolean
232
268
polkit_unix_user_equal (PolkitIdentity *a,
233
269
                        PolkitIdentity *b)
255
291
polkit_unix_user_to_string (PolkitIdentity *identity)
256
292
{
257
293
  PolkitUnixUser *user = POLKIT_UNIX_USER (identity);
258
 
  struct passwd *passwd;
259
 
 
260
 
  passwd = getpwuid (user->uid);
261
 
 
262
 
  if (passwd == NULL)
 
294
  const gchar *user_name = polkit_unix_user_get_name(user);
 
295
 
 
296
  if (user_name != NULL)
 
297
    return g_strdup_printf ("unix-user:%s", user_name);
 
298
  else
263
299
    return g_strdup_printf ("unix-user:%d", user->uid);
264
 
  else
265
 
    return g_strdup_printf ("unix-user:%s", passwd->pw_name);
266
300
}
267
301
 
268
302
static void