1/* vi: ts=8 sts=4 sw=4
2 *
3 * This file is part of the KDE project, module kdesu.
4 * Copyright (C) 1999,2000 Geert Jansen <jansen@kde.org>
5 *
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.
9 */
10
11#ifndef __SU_h_Included__
12#define __SU_h_Included__
13
14#include <kdesu/kdesu_export.h>
15
16#include "stub.h"
17
18
19namespace KDESu {
20
21/** \class SuProcess su.h kdesu/su.h
22 * Executes a command under elevated privileges, using su.
23 */
24
25class KDESU_EXPORT SuProcess: public StubProcess
26{
27public:
28 explicit SuProcess(const QByteArray &user=0, const QByteArray &command=0);
29 ~SuProcess();
30
31 enum Errors { SuNotFound=1, SuNotAllowed, SuIncorrectPassword };
32
33 /**
34 * Executes the command. This will wait for the command to finish.
35 */
36 enum checkMode { NoCheck=0, Install=1, NeedPassword=2 } ;
37 int exec(const char *password, int check=NoCheck);
38
39 /**
40 * Checks if the stub is installed and the password is correct.
41 * @return Zero if everything is correct, nonzero otherwise.
42 */
43 int checkInstall(const char *password);
44
45 /**
46 * Checks if a password is needed.
47 */
48 int checkNeedPassword();
49
50 /**
51 * Checks what the default super user command is, e.g. sudo, su, etc
52 * @return the default super user command
53 */
54 QString superUserCommand();
55
56 /**
57 * Checks whether or not the user's password is being asked for or another
58 * user's password. Due to usage of systems such as sudo, even when attempting
59 * to switch to another user one may need to enter their own password.
60 */
61 bool useUsersOwnPassword();
62
63private:
64 enum SuErrors { error=-1, ok=0, killme=1, notauthorized=2 } ;
65 int ConverseSU(const char *password);
66
67protected:
68 virtual void virtual_hook( int id, void* data );
69private:
70 class SuProcessPrivate;
71 SuProcessPrivate * const d;
72};
73
74}
75
76#endif
77