KDESu 5.99.0
Public Member Functions | List of all members
KDESu::KDEsuClient

A client class to access kdesud, the KDE su daemon. More...

#include <KDESu/Client>

Public Member Functions

 KDEsuClient (const KDEsuClient &)=delete
 
int delCommand (const QByteArray &command, const QByteArray &user)
 Remove a password for a user/command. More...
 
int delGroup (const QByteArray &group)
 Delete all persistent variables in a group. More...
 
int delVar (const QByteArray &key)
 Delete a persistent variable. More...
 
int delVars (const QByteArray &special_key)
 Delete all persistent variables with the given key. More...
 
int exec (const QByteArray &command, const QByteArray &user, const QByteArray &options=nullptr, const QList< QByteArray > &env=QList< QByteArray >())
 Lets kdesud execute a command. More...
 
int exitCode ()
 Wait for the last command to exit and return the exit code. More...
 
bool findGroup (const QByteArray &group)
 Returns true if the specified group exists is cached. More...
 
QList< QByteArray > getKeys (const QByteArray &group)
 Gets all the keys that are membes of the given group. More...
 
QByteArray getVar (const QByteArray &key)
 Get a persistent variable. More...
 
bool isServerSGID ()
 Returns true if the server is safe (installed setgid), false otherwise. More...
 
KDEsuClientoperator= (const KDEsuClient &)=delete
 
int ping ()
 Ping kdesud. More...
 
int setHost (const QByteArray &host)
 Set the target host (optional). More...
 
int setPass (const char *pass, int timeout)
 Set root's password, lasts one session. More...
 
int setPriority (int priority)
 Set the desired priority (optional), see StubProcess. More...
 
int setScheduler (int scheduler)
 Set the desired scheduler (optional), see StubProcess. More...
 
int setVar (const QByteArray &key, const QByteArray &value, int timeout=0, const QByteArray &group=nullptr)
 Set a persistent variable. More...
 
int startServer ()
 Try to start up kdesud. More...
 
int stopServer ()
 Stop the daemon. More...
 

Detailed Description

A client class to access kdesud, the KDE su daemon.

Kdesud can assist in password caching in two ways:

Member Function Documentation

◆ delCommand()

int KDESu::KDEsuClient::delCommand ( const QByteArray &  command,
const QByteArray &  user 
)

Remove a password for a user/command.

Parameters
commandThe command.
userThe user.
Returns
zero on success, -1 on an error

◆ delGroup()

int KDESu::KDEsuClient::delGroup ( const QByteArray &  group)

Delete all persistent variables in a group.

Parameters
groupthe group name. See setVar.
Returns

◆ delVar()

int KDESu::KDEsuClient::delVar ( const QByteArray &  key)

Delete a persistent variable.

Parameters
keyThe name of the variable.
Returns
zero on success, -1 on failure.

◆ delVars()

int KDESu::KDEsuClient::delVars ( const QByteArray &  special_key)

Delete all persistent variables with the given key.

A specicalized variant of delVar(QByteArray) that removes all subsets of the cached variables given by key. In order for all cached variables related to this key to be deleted properly, the value given to the group argument when the setVar function was called, must be a subset of the argument given here and the key

Note
Simply supplying the group key here WILL not necessarily work. If you only have a group key, then use delGroup instead.
Parameters
special_keythe name of the variable.
Returns
zero on success, -1 on failure.

◆ exec()

int KDESu::KDEsuClient::exec ( const QByteArray &  command,
const QByteArray &  user,
const QByteArray &  options = nullptr,
const QList< QByteArray > &  env = QList< QByteArray >() 
)

Lets kdesud execute a command.

If the daemon does not have a password for this command, this will fail and you need to call setPass().

Parameters
commandThe command to execute.
userThe user to run the command as.
optionsExtra options.
envExtra environment variables.
Returns
Zero on success, -1 on failure.

◆ exitCode()

int KDESu::KDEsuClient::exitCode ( )

Wait for the last command to exit and return the exit code.

Returns
Exit code of last command, -1 on failure.

◆ findGroup()

bool KDESu::KDEsuClient::findGroup ( const QByteArray &  group)

Returns true if the specified group exists is cached.

Parameters
groupthe group key
Returns
true if the group is found

◆ getKeys()

QList< QByteArray > KDESu::KDEsuClient::getKeys ( const QByteArray &  group)

Gets all the keys that are membes of the given group.

Parameters
groupthe group name of the variables.
Returns
a list of the keys in the group.

◆ getVar()

QByteArray KDESu::KDEsuClient::getVar ( const QByteArray &  key)

Get a persistent variable.

Parameters
keyThe name of the variable.
Returns
Its value.

◆ isServerSGID()

bool KDESu::KDEsuClient::isServerSGID ( )

Returns true if the server is safe (installed setgid), false otherwise.

◆ ping()

int KDESu::KDEsuClient::ping ( )

Ping kdesud.

This can be used for diagnostics.

Returns
Zero on success, -1 on failure

◆ setHost()

int KDESu::KDEsuClient::setHost ( const QByteArray &  host)

Set the target host (optional).

◆ setPass()

int KDESu::KDEsuClient::setPass ( const char *  pass,
int  timeout 
)

Set root's password, lasts one session.

Parameters
passRoot's password.
timeoutThe time that a password will live.
Returns
Zero on success, -1 on failure.

◆ setPriority()

int KDESu::KDEsuClient::setPriority ( int  priority)

Set the desired priority (optional), see StubProcess.

◆ setScheduler()

int KDESu::KDEsuClient::setScheduler ( int  scheduler)

Set the desired scheduler (optional), see StubProcess.

◆ setVar()

int KDESu::KDEsuClient::setVar ( const QByteArray &  key,
const QByteArray &  value,
int  timeout = 0,
const QByteArray &  group = nullptr 
)

Set a persistent variable.

Parameters
keyThe name of the variable.
valueIts value.
timeoutThe timeout in seconds for this key. Zero means no timeout.
groupMake the key part of a group. See delGroup.
Returns
zero on success, -1 on failure.

◆ startServer()

int KDESu::KDEsuClient::startServer ( )

Try to start up kdesud.

◆ stopServer()

int KDESu::KDEsuClient::stopServer ( )

Stop the daemon.