3 * This file is part of the KDE project, module kdesu.
4 * Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
6 * This is free software; you can use this library under the GNU Library
7 * General Public License, version 2. See the file "COPYING.LIB" for the
8 * exact licensing terms.
10 * client.h: client to access kdesud.
13 #ifndef __KDE_su_Client_h_Included__
14 #define __KDE_su_Client_h_Included__
16 #include <QtCore/QBool>
17 #include <QtCore/QList>
18 #include <kdesu/kdesu_export.h>
22 #include <sys/types.h>
23 #include <sys/socket.h>
26 #include <QtCore/QByteArray>
30 /** \class KDEsuClient client.h kdesu/client.h
31 * A client class to access kdesud, the KDE su daemon. Kdesud can assist in
32 * password caching in two ways:
34 * @li For high security passwords, like for su and ssh, it executes the
35 * password requesting command for you. It feeds the password to the
36 * command, without ever returning it to you, the user. The daemon should
37 * be installed setgid nogroup, in order to be able to act as an inaccessible,
39 * See exec, setPass, delCommand.
41 * @li For lower security passwords, like web and ftp passwords, it can act
42 * as a persistent storage for string variables. These variables are
43 * returned to the user, and the daemon doesn't need to be setgid nogroup
45 * See setVar, delVar, delGroup.
48 class KDESU_EXPORT KDEsuClient
{
54 * Lets kdesud execute a command. If the daemon does not have a password
55 * for this command, this will fail and you need to call setPass().
57 * @param command The command to execute.
58 * @param user The user to run the command as.
59 * @param options Extra options.
60 * @param env Extra environment variables.
61 * @return Zero on success, -1 on failure.
63 int exec(const QByteArray
&command
, const QByteArray
&user
, const QByteArray
&options
=0, const QList
<QByteArray
> &env
=QList
<QByteArray
>());
66 * Wait for the last command to exit and return the exit code.
67 * @return Exit code of last command, -1 on failure.
72 * Set root's password, lasts one session.
74 * @param pass Root's password.
75 * @param timeout The time that a password will live.
76 * @return Zero on success, -1 on failure.
78 int setPass(const char *pass
, int timeout
);
81 * Set the target host (optional).
83 int setHost(const QByteArray
&host
);
86 * Set the desired priority (optional), see StubProcess.
88 int setPriority(int priority
);
91 * Set the desired scheduler (optional), see StubProcess.
93 int setScheduler(int scheduler
);
96 * Remove a password for a user/command.
97 * @param command The command.
98 * @param user The user.
99 * @return zero on success, -1 on an error
101 int delCommand(const QByteArray
&command
, const QByteArray
&user
);
104 * Set a persistent variable.
105 * @param key The name of the variable.
106 * @param value Its value.
107 * @param timeout The timeout in seconds for this key. Zero means
109 * @param group Make the key part of a group. See delGroup.
110 * @return zero on success, -1 on failure.
112 int setVar(const QByteArray
&key
, const QByteArray
&value
, int timeout
=0, const QByteArray
&group
=0);
115 * Get a persistent variable.
116 * @param key The name of the variable.
119 QByteArray
getVar(const QByteArray
&key
);
122 * Gets all the keys that are membes of the given group.
123 * @param group the group name of the variables.
124 * @return a list of the keys in the group.
126 QList
<QByteArray
> getKeys(const QByteArray
&group
);
129 * Returns true if the specified group exists is
132 * @param group the group key
133 * @return true if the group is found
135 bool findGroup(const QByteArray
&group
);
138 * Delete a persistent variable.
139 * @param key The name of the variable.
140 * @return zero on success, -1 on failure.
142 int delVar(const QByteArray
&key
);
145 * Delete all persistent variables with the given key.
147 * A specicalized variant of delVar(QByteArray) that removes all
148 * subsets of the cached varaibles given by @p key. In order for all
149 * cached variables related to this key to be deleted properly, the
150 * value given to the @p group argument when the setVar function
151 * was called, must be a subset of the argument given here and the key
153 * @note Simply supplying the group key here WILL not necessarily
154 * work. If you only have a group key, then use delGroup instead.
156 * @param special_key the name of the variable.
157 * @return zero on success, -1 on failure.
159 int delVars(const QByteArray
&special_key
);
162 * Delete all persistent variables in a group.
164 * @param group the group name. See setVar.
167 int delGroup(const QByteArray
&group
);
170 * Ping kdesud. This can be used for diagnostics.
171 * @return Zero on success, -1 on failure
181 * Try to start up kdesud
186 * Returns true if the server is safe (installed setgid), false otherwise.
193 int command(const QByteArray
&cmd
, QByteArray
*result
=0L);
194 QByteArray
escape(const QByteArray
&str
);
196 class KDEsuClientPrivate
;
197 KDEsuClientPrivate
* const d
;
200 } //END namespace KDESu
204 #endif //__KDE_su_Client_h_Included__