2
* Copyright (C) 2001,2002, 2004 Red Hat, Inc.
2
* Copyright (C) 2001,2002, 2004, 2006 Red Hat, Inc.
4
4
* This is free software; you can redistribute it and/or modify it under
5
5
* the terms of the GNU Library General Public License as published by
16
16
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
#ident "$Id: lchsh.c,v 1.18 2005/09/12 18:21:34 mitr Exp $"
19
#ident "$Id: lchsh.c,v 1.21 2006/05/01 05:10:43 mitr Exp $"
21
21
#ifdef HAVE_CONFIG_H
22
22
#include "config.h"
36
36
main(int argc, const char **argv)
38
const char *user = NULL;
39
struct lu_context *ctx = NULL;
39
struct lu_context *ctx;
40
40
struct lu_error *error = NULL;
41
struct lu_ent *ent = NULL;
42
GValueArray *values = NULL;
44
43
int interactive = FALSE;
46
struct lu_prompt prompts[1];
48
46
struct poptOption options[] = {
49
47
{"interactive", 'i', POPT_ARG_NONE, &interactive, 0,
71
69
/* If no user was specified, or we're setuid, force the user name to
72
70
* be that of the current user. */
73
71
if ((user == NULL) || (geteuid() != getuid())) {
74
struct passwd *pwd = NULL;
75
74
pwd = getpwuid(getuid());
77
76
user = g_strdup(pwd->pw_name);
109
108
/* Read the user's shell. */
110
109
values = lu_ent_get(ent, LU_LOGINSHELL);
111
110
if (values != NULL) {
111
struct lu_prompt prompts[1];
112
114
value = g_value_array_get_nth(values, 0);
113
115
/* Fill in the prompt structure using the user's shell. */
114
116
memset(prompts, 0, sizeof(prompts));
119
121
prompts[0].default_value = lu_value_strdup(value);
120
122
/* Prompt for a new shell. */
121
123
if (lu_prompt_console(prompts, G_N_ELEMENTS(prompts),
123
/* Modify the in-memory structure's shell attribute. */
124
memset(&val, 0, sizeof(val));
125
g_value_init(&val, G_TYPE_STRING);
126
g_value_set_string(&val, prompts[0].value);
127
if (prompts[0].free_value != NULL) {
128
prompts[0].free_value(prompts[0].value);
129
prompts[0].value = NULL;
131
lu_ent_clear(ent, LU_LOGINSHELL);
132
lu_ent_add(ent, LU_LOGINSHELL, &val);
133
/* Modify the user's record in the information store. */
134
if (lu_user_modify(ctx, ent, &error)) {
135
g_print(_("Shell changed.\n"));
138
fprintf(stderr, _("Shell not changed: %s\n"),
124
NULL, &error) == FALSE) {
125
fprintf(stderr, _("Shell not changed: %s\n"),
129
/* Modify the in-memory structure's shell attribute. */
130
memset(&val, 0, sizeof(val));
131
g_value_init(&val, G_TYPE_STRING);
132
g_value_set_string(&val, prompts[0].value);
133
if (prompts[0].free_value != NULL) {
134
prompts[0].free_value(prompts[0].value);
135
prompts[0].value = NULL;
137
lu_ent_clear(ent, LU_LOGINSHELL);
138
lu_ent_add(ent, LU_LOGINSHELL, &val);
139
/* Modify the user's record in the information store. */
140
if (lu_user_modify(ctx, ent, &error)) {
141
g_print(_("Shell changed.\n"));
144
fprintf(stderr, _("Shell not changed: %s\n"),
144
151
lu_ent_free(ent);