1 /* 2 * Gksu -- a library providing access to su functionality 3 * Copyright (C) 2004 Gustavo Noronha Silva 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the 17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 * Boston, MA 02111-1307, USA. 19 */ 20 21 #ifndef __LIBGKSU_H__ 22 #define __LIBGKSU_H__ 23 24 #include <glib.h> 25 #include <glib-object.h> 26 27 #define SN_API_NOT_YET_FROZEN 28 #include <libsn/sn.h> 29 30 #include <gtk/gtk.h> 31 32 #include <gconf/gconf-client.h> 33 34 G_BEGIN_DECLS 35 36 typedef struct _GksuContext GksuContext; 37 struct _GksuContext 38 { 39 /* 40 * Protected 41 */ 42 43 /* Xauth stuff */ 44 gchar *xauth; 45 gchar *dir; 46 gchar *display; 47 48 gboolean sudo_mode; 49 50 GConfClient *gconf_client; 51 52 /* what to run, with whose powers */ 53 gchar *user; 54 gchar *command; 55 56 gboolean login_shell; 57 gboolean keep_env; 58 59 /* UI options */ 60 gchar *description; 61 gchar *message; 62 gchar *alert; 63 gboolean grab; 64 gboolean always_ask_password; 65 66 /* startup notification */ 67 SnLauncherContext *sn_context; 68 gchar *sn_id; 69 70 /* ref counting */ 71 gint ref_count; 72 73 gboolean debug; 74 }; 75 76 #define GKSU_TYPE_CONTEXT gksu_context_get_type() 77 GType gksu_context_get_type (void); 78 GksuContext* gksu_context_new (void); 79 GksuContext* gksu_context_ref (GksuContext *context); 80 void gksu_context_unref (GksuContext *context); 81 82 GType gksu_error_get_type (void); 83 #define GKSU_TYPE_ERROR (gksu_error_get_type ()) 84 85 typedef enum 86 { 87 GKSU_ERROR_XAUTH, 88 GKSU_ERROR_HELPER, 89 GKSU_ERROR_NOCOMMAND, 90 GKSU_ERROR_NOPASSWORD, 91 GKSU_ERROR_FORK, 92 GKSU_ERROR_EXEC, 93 GKSU_ERROR_PIPE, 94 GKSU_ERROR_PIPEREAD, 95 GKSU_ERROR_WRONGPASS, 96 GKSU_ERROR_CHILDFAILED, 97 GKSU_ERROR_NOT_ALLOWED, 98 GKSU_ERROR_CANCELED, 99 GKSU_ERROR_WRONGAUTOPASS 100 } GksuError; 101 102 typedef 103 gchar* 104 (*GksuAskPassFunc) (GksuContext *context, gchar *prompt, 105 gpointer user_data, GError**); 106 107 typedef 108 void 109 (*GksuPassNotNeededFunc) (GksuContext *context, gpointer user_data); 110 111 /* 112 getters and setters for the configuration 113 options 114 */ 115 void 116 gksu_context_set_user (GksuContext *context, gchar *username); 117 118 const gchar* 119 gksu_context_get_user (GksuContext *context); 120 121 void 122 gksu_context_set_command (GksuContext *context, gchar *command); 123 124 const gchar* 125 gksu_context_get_command (GksuContext *context); 126 127 void 128 gksu_context_set_login_shell (GksuContext *context, gboolean value); 129 130 gboolean 131 gksu_context_get_login_shell (GksuContext *context); 132 133 void 134 gksu_context_set_keep_env (GksuContext *context, gboolean value); 135 136 gboolean 137 gksu_context_get_keep_env (GksuContext *context); 138 139 void 140 gksu_context_set_description (GksuContext *context, gchar *description); 141 142 gchar* 143 gksu_context_get_description (GksuContext *context); 144 145 void 146 gksu_context_set_message (GksuContext *context, gchar *message); 147 148 gchar* 149 gksu_context_get_message (GksuContext *context); 150 151 void 152 gksu_context_set_alert (GksuContext *context, gchar *alert); 153 154 gchar* 155 gksu_context_get_alert (GksuContext *context); 156 157 void 158 gksu_context_set_grab (GksuContext *context, gboolean value); 159 160 gboolean 161 gksu_context_get_grab (GksuContext *context); 162 163 void 164 gksu_context_set_always_ask_password (GksuContext *context, gboolean value); 165 166 gboolean 167 gksu_context_get_always_ask_password (GksuContext *context); 168 169 void 170 gksu_context_set_launcher_context (GksuContext *context, SnLauncherContext *sn_context); 171 172 SnLauncherContext* 173 gksu_context_get_launcher_context (GksuContext *context); 174 175 void 176 gksu_context_set_debug (GksuContext *context, gboolean value); 177 178 gboolean 179 gksu_context_get_debug (GksuContext *context); 180 181 void 182 gksu_context_free (GksuContext *context); 183 184 gboolean 185 gksu_su_fuller (GksuContext *context, 186 GksuAskPassFunc ask_pass, 187 gpointer ask_pass_data, 188 GksuPassNotNeededFunc pass_not_needed, 189 gpointer pass_not_needed_data, 190 gint8 *exit_status, 191 GError **error); 192 193 gboolean 194 gksu_su_full (GksuContext *context, 195 GksuAskPassFunc ask_pass, 196 gpointer ask_pass_data, 197 GksuPassNotNeededFunc pass_not_needed, 198 gpointer pass_not_needed_data, 199 GError **error); 200 201 gboolean 202 gksu_su (gchar *command_line, 203 GError **error); 204 205 gboolean 206 gksu_sudo_fuller (GksuContext *context, 207 GksuAskPassFunc ask_pass, 208 gpointer ask_pass_data, 209 GksuPassNotNeededFunc pass_not_needed, 210 gpointer pass_not_needed_data, 211 gint8 *exit_status, 212 GError **error); 213 214 gboolean 215 gksu_sudo_full (GksuContext *context, 216 GksuAskPassFunc ask_pass, 217 gpointer ask_pass_data, 218 GksuPassNotNeededFunc pass_not_needed, 219 gpointer pass_not_needed_data, 220 GError **error); 221 222 gboolean 223 gksu_sudo (gchar *command_line, 224 GError **error); 225 226 gboolean 227 gksu_run_fuller (GksuContext *context, 228 GksuAskPassFunc ask_pass, 229 gpointer ask_pass_data, 230 GksuPassNotNeededFunc pass_not_needed, 231 gpointer pass_not_needed_data, 232 gint8 *exit_status, 233 GError **error); 234 235 gboolean 236 gksu_run_full (GksuContext *context, 237 GksuAskPassFunc ask_pass, 238 gpointer ask_pass_data, 239 GksuPassNotNeededFunc pass_not_needed, 240 gpointer pass_not_needed_data, 241 GError **error); 242 243 gboolean 244 gksu_run (gchar *command_line, 245 GError **error); 246 247 gchar* 248 gksu_ask_password_full (GksuContext *context, 249 gchar *prompt, 250 GError **error); 251 252 gchar* 253 gksu_ask_password (GError **error); 254 255 G_END_DECLS 256 257 #endif 258