Pages
API Documentation
On this page

KDESu::Client Class

A client class to access kdesud, the KDE su daemon. This class was introduced in Qt 6.0. More...

  • Header: #include <KDESu/Client>
  • Since: Qt 6.0
  • CMake: find_package(KF6 REQUIRED COMPONENTS Su)
    target_link_libraries(mytarget PRIVATE KF6::Su)

List of all members, including inherited members

Public Functions

Detailed Description

Kdesud can assist in password caching in two ways:

For high security passwords, like for su and ssh, it executes the password requesting command for you. It feeds the password to the command, without ever returning it to you, the user. See exec, setPass, delCommand.

For lower security passwords, like web and ftp passwords, it can act as a persistent storage for string variables. These variables are returned to the user. See setVar, delVar, delGroup.

Porting from KF5 to KF6:

The class KDESu::KDEsuClient was renamed to KDESu::Client.

Member Function Documentation

Client::Client()

int Client::delCommand(const QByteArray &command, const QByteArray &user)

Remove a password for a user/command.

command The command.

user The user.

Return zero on success, -1 on an error

int Client::delGroup(const QByteArray &group)

Delete all persistent variables in a group.

group the group name. See setVar.

int Client::delVar(const QByteArray &key)

Delete a persistent variable.

key The name of the variable.

Returns zero on success, -1 on failure.

int Client::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.

special_key the name of the variable.

Returns zero on success, -1 on failure.

int Client::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().

command The command to execute.

user The user to run the command as.

options Extra options.

env Extra environment variables.

Returns Zero on success, -1 on failure.

int Client::exitCode()

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

Returns the exit code of last command, -1 on failure.

bool Client::findGroup(const QByteArray &group)

Returns true if the specified group exists is cached.

group the group key

Returns true if the group is found

QList<QByteArray> Client::getKeys(const QByteArray &group)

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

group the group name of the variables.

Returns a list of the keys in the group.

QByteArray Client::getVar(const QByteArray &key)

Get a persistent variable.

key The name of the variable.

Returns its value.

int Client::ping()

Ping kdesud. This can be used for diagnostics.

Returns zero on success, -1 on failure

int Client::setHost(const QByteArray &host)

Set the target host (optional).

int Client::setPass(const char *pass, int timeout)

Set root's password, lasts one session.

pass Root's password.

timeout The time that a password will live.

Returns zero on success, -1 on failure.

int Client::setPriority(int priority)

Set the desired priority (optional), see StubProcess.

int Client::setScheduler(int scheduler)

Set the desired scheduler (optional), see StubProcess.

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

Set a persistent variable.

key The name of the variable.

value Its value.

timeout The timeout in seconds for this key. Zero means no timeout.

group Make the key part of a group. See delGroup.

Return zero on success, -1 on failure.

int Client::startServer()

Try to start up kdesud

int Client::stopServer()

Stop the daemon.

We use cookies to personalize content and to analyze our traffic. Please decide if you are willing to accept cookies from our website.