Esempio n. 1
0
static char *specifier_user_home(char specifier, void *data, void *userdata) {
        Unit *u = userdata;
        ExecContext *c;
        int r;
        const char *username, *home;

        assert(u);

        c = unit_get_exec_context(u);

        /* return HOME if set, otherwise from passwd */
        if (!c || !c->user) {
                char *h;

                r = get_home_dir(&h);
                if (r < 0)
                        return NULL;

                return h;
        }

        username = c->user;
        r = get_user_creds(&username, NULL, NULL, &home, NULL);
        if (r < 0)
               return NULL;

        return strdup(home);
}
Esempio n. 2
0
static char *specifier_user_shell(char specifier, void *data, void *userdata) {
        Unit *u = userdata;
        ExecContext *c;
        int r;
        const char *username, *shell;

        assert(u);

        c = unit_get_exec_context(u);

        /* return HOME if set, otherwise from passwd */
        if (!c || !c->user) {
                char *sh;

                r = get_shell(&sh);
                if (r < 0)
                        return strdup("/bin/sh");

                return sh;
        }

        username = c->user;
        r = get_user_creds(&username, NULL, NULL, NULL, &shell);
        if (r < 0)
                return strdup("/bin/sh");

        return strdup(shell);
}
Esempio n. 3
0
static char *specifier_user_shell(char specifier, void *data, void *userdata) {
        Unit *u = userdata;
        ExecContext *c;
        int r;
        const char *username, *shell;
        char *ret;

        assert(u);

        c = unit_get_exec_context(u);

        if (c && c->user)
                username = c->user;
        else
                username = "******";

        /* return /bin/sh for root, otherwise the value from passwd */
        r = get_user_creds(&username, NULL, NULL, NULL, &shell);
        if (r < 0) {
                log_warning_unit(u->id,
                                 "Failed to determine shell: %s",
                                 strerror(-r));
                return NULL;
        }

        if (!path_is_absolute(shell)) {
                log_warning_unit(u->id,
                                 "Shell %s is not absolute, ignoring.",
                                 shell);
        }

        ret = strdup(shell);
        if (!ret)
                log_oom();

        return ret;
}
Esempio n. 4
0
static char *specifier_user_name(char specifier, void *data, void *userdata) {
        Unit *u = userdata;
        ExecContext *c;
        int r;
        const char *username;
        _cleanup_free_ char *tmp = NULL;
        uid_t uid;
        char *printed = NULL;

        assert(u);

        c = unit_get_exec_context(u);

        if (c && c->user)
                username = c->user;
        else
                /* get USER env from env or our own uid */
                username = tmp = getusername_malloc();

        /* fish username from passwd */
        r = get_user_creds(&username, &uid, NULL, NULL, NULL);
        if (r < 0)
                return NULL;

        switch (specifier) {
                case 'U':
                        if (asprintf(&printed, "%d", uid) < 0)
                                return NULL;
                        break;
                case 'u':
                        printed = strdup(username);
                        break;
        }

        return printed;
}