~ubuntu-branches/ubuntu/trusty/libgksu1.2/trusty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
 * Gksu -- a library providing access to su functionality
 * Copyright (C) 2004 Gustavo Noronha Silva
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __GKSU_CONTEXT_H__
#define __GKSU_CONTEXT_H__

#include <glib.h>
#include <glib-object.h>

#define GKSU_TYPE_CONTEXT (gksu_context_get_type ())
#define GKSU_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GKSU_TYPE_CONTEXT, GksuContext))
#define GKSU_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GKSU_TYPE_CONTEXT, GksuContextClass))
#define GKSU_IS_CONTEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GKSU_TYPE_CONTEXT))
#define GKSU_IS_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GKSU_TYPE_CONTEXT))
#define GKSU_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GKSU_TYPE_CONTEXT, GksuContextClass))

G_BEGIN_DECLS

typedef enum
{
  GKSU_CONTEXT_ERROR_XAUTH,
  GKSU_CONTEXT_ERROR_HELPER,
  GKSU_CONTEXT_ERROR_NOCOMMAND,
  GKSU_CONTEXT_ERROR_NOPASSWORD,
  GKSU_CONTEXT_ERROR_FORK,
  GKSU_CONTEXT_ERROR_EXEC,
  GKSU_CONTEXT_ERROR_PIPE,
  GKSU_CONTEXT_ERROR_PIPEREAD,
  GKSU_CONTEXT_ERROR_WRONGPASS,
  GKSU_CONTEXT_ERROR_CHILDFAILED,
  GKSU_CONTEXT_ERROR_NOT_ALLOWED
} GksuContextError;

#define GKSU_TYPE_CONTEXT_ERROR (gksu_context_error_get_type ())

typedef struct _GksuContext GksuContext;
typedef struct _GksuContextClass GksuContextClass;

/**
 * GksuContext:
 * @parent: #GksuContext is based on #GObject
 * @xauth: the X authorization token
 * @dir: the directory where the .Xauthority file is created in sudo
 * mode
 * @display: storage for the DISPLAY environment variable
 * @user: user gksu will switch to
 * @password: the password that should be passed to su or sudo
 * @command: which command to run with su
 * @login_shell: should run a login shell?
 * @keep_env: should the current environment be kept?
 * @debug: show debug information?
 * @ssh_fwd: are we running inside a ssh X11 forwarding
 * tunnel?
 *
 * Object that holds all configuration information, some
 * important environment variables and some meta-information
 * about mainly x authentication.
 *
 */
struct _GksuContext
{
  GObject parent;

  gchar *xauth;
  gchar *dir;

  gchar *display;

  gchar *user;
  gchar *password;
  gchar *command;

  gboolean login_shell;
  gboolean keep_env;

  gboolean debug;
  gboolean ssh_fwd;
};

struct _GksuContextClass
{
  GObjectClass parent;
};

typedef gboolean (*GksuAskPasswordFunc) (GksuContext*, gchar*, gpointer, GError**);
typedef void (*GksuPasswordNotNeededFunc) (GksuContext*, gpointer);

/* 
   Context handling
*/
GksuContext*
gksu_context_new ();

void
gksu_context_free (GksuContext *context);

/* 
   getters and setters for the configuration
   options
*/
void
gksu_context_set_user (GksuContext *context, gchar *username);

const gchar*
gksu_context_get_user (GksuContext *context);

void
gksu_context_set_command (GksuContext *context, gchar *command);

const gchar*
gksu_context_get_command (GksuContext *context);

void
gksu_context_set_password (GksuContext *context, gchar *password);

const gchar*
gksu_context_get_password (GksuContext *context);

void
gksu_context_set_login_shell (GksuContext *context, gboolean value);

gboolean
gksu_context_get_login_shell (GksuContext *context);

void
gksu_context_set_keep_env (GksuContext *context, gboolean value);

gboolean
gksu_context_get_keep_env (GksuContext *context);

void
gksu_context_set_debug (GksuContext *context, gboolean value);

gboolean
gksu_context_get_debug (GksuContext *context);

void
gksu_context_set_ssh_fwd (GksuContext *context, gboolean value);

gboolean
gksu_context_get_ssh_fwd (GksuContext *context);

GType
gksu_context_get_type (void);

gboolean
gksu_context_try_need_password (GksuContext *context);

gboolean
gksu_context_run_full (GksuContext *context, 
		       GksuAskPasswordFunc ask_pass, gpointer user_data, 
		       GksuPasswordNotNeededFunc pass_not_needed, 
		       gpointer pnn_user_data, GError **error);

gboolean
gksu_context_run (GksuContext *context, GError **error);

gboolean
gksu_context_sudo_try_need_password (GksuContext *context);

gboolean
gksu_context_sudo_run_full (GksuContext *context, 
			    GksuAskPasswordFunc ask_pass, gpointer user_data, 
			    GksuPasswordNotNeededFunc pass_not_needed, 
			    gpointer pnn_user_data, GError **error);

gboolean
gksu_context_sudo_run (GksuContext *context, GError **error);

/* DO NOT USE - Deprecated */
gboolean
gksu_context_ask_and_run (GksuContext *context, GksuAskPasswordFunc ask_pass, 
			  gpointer user_data, GError **error);

gboolean
gksu_context_sudo_ask_and_run (GksuContext *context, GksuAskPasswordFunc ask_pass, 
			       gpointer user_data, GError **error);

G_END_DECLS

#endif