~elementary-apps/pantheon-files/trunk

« back to all changes in this revision

Viewing changes to libcore/eel-fcts.c

* Show user bookmarks even when running as root
* Only show local folders in sidebar while root

Show diffs side-by-side

added added

removed removed

Lines of Context:
235
235
    return TRUE;
236
236
}
237
237
 
 
238
static const char*
 
239
get_user_home_from_user_uid (uid_t uid)
 
240
{
 
241
    struct passwd *password_info;
 
242
 
 
243
    password_info = getpwuid (uid);
 
244
 
 
245
    if (password_info == NULL || password_info->pw_dir == NULL)
 
246
        return NULL;
 
247
 
 
248
    return password_info->pw_dir;
 
249
}
 
250
 
 
251
char*
 
252
eel_get_real_user_home ()
 
253
{
 
254
    const char *real_uid_s;
 
255
    int uid;
 
256
 
 
257
    real_uid_s = g_environ_getenv (g_get_environ (), "PKEXEC_UID");
 
258
    /* If running as administrator return the real user home, not root home */
 
259
    if (real_uid_s != NULL && eel_get_id_from_digit_string (real_uid_s, &uid)) {
 
260
        return g_strdup (get_user_home_from_user_uid ((uid_t)uid));
 
261
    } else {
 
262
        return g_strdup (g_get_home_dir ());
 
263
    }
 
264
}
 
265
 
238
266
gboolean
239
267
eel_get_id_from_digit_string (const char *digit_string, uid_t *id)
240
268
{
249
277
    if (sscanf (digit_string, "%ld%c", &scanned_id, &c) != 1) {
250
278
        return FALSE;
251
279
    }
 
280
 
252
281
    *id = scanned_id;
 
282
 
253
283
    return TRUE;
254
284
}
255
285