mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 18:32:50 +00:00
generic: make use of KUser and KUserGroup
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
a961fadacd
commit
06a7d81327
12 changed files with 38 additions and 61 deletions
|
@ -31,7 +31,6 @@
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
@ -41,32 +40,32 @@
|
|||
|
||||
#include <kdebug.h>
|
||||
#include <kstandarddirs.h>
|
||||
#include <kuser.h>
|
||||
|
||||
|
||||
PasswdProcess::PasswdProcess(const QByteArray &user)
|
||||
PasswdProcess::PasswdProcess(const QString &user)
|
||||
{
|
||||
struct passwd *pw;
|
||||
uid_t userid = -1;
|
||||
|
||||
if (user.isEmpty())
|
||||
{
|
||||
pw = getpwuid(getuid());
|
||||
if (pw == 0L)
|
||||
const KUser kuser(::getuid());
|
||||
if (!kuser.isValid())
|
||||
{
|
||||
kDebug(1512) << "You don't exist!\n";
|
||||
return;
|
||||
}
|
||||
m_User = pw->pw_name;
|
||||
m_User = kuser.loginName();
|
||||
} else
|
||||
{
|
||||
pw = getpwnam(user);
|
||||
if (pw == 0L)
|
||||
const KUser kuser(user);
|
||||
if (!kuser.isValid())
|
||||
{
|
||||
kDebug(1512) << "User " << user << "does not exist.\n";
|
||||
return;
|
||||
}
|
||||
m_User = user;
|
||||
}
|
||||
bOtherUser = (pw->pw_uid != getuid());
|
||||
bOtherUser = (userid != ::getuid());
|
||||
}
|
||||
|
||||
|
||||
|
@ -95,7 +94,7 @@ int PasswdProcess::exec(const char *oldpass, const char *newpass,
|
|||
|
||||
QList<QByteArray> args;
|
||||
if(bOtherUser)
|
||||
args += m_User;
|
||||
args += m_User.toLocal8Bit();
|
||||
int ret = PtyProcess::exec("passwd", args);
|
||||
if (ret < 0)
|
||||
{
|
||||
|
|
|
@ -37,7 +37,7 @@ class PasswdProcess
|
|||
: public PtyProcess
|
||||
{
|
||||
public:
|
||||
PasswdProcess(const QByteArray &user = QByteArray());
|
||||
PasswdProcess(const QString &user = QString());
|
||||
~PasswdProcess();
|
||||
|
||||
enum Errors { PasswdNotFound=1, PasswordIncorrect, PasswordNotGood };
|
||||
|
@ -52,7 +52,8 @@ private:
|
|||
int ConversePasswd(const char *oldpass, const char *newpass,
|
||||
int check);
|
||||
|
||||
QByteArray m_User, m_Error;
|
||||
QString m_User;
|
||||
QByteArray m_Error;
|
||||
bool bOtherUser;
|
||||
};
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ KDEpasswd1Dialog::~KDEpasswd1Dialog()
|
|||
|
||||
void KDEpasswd1Dialog::accept()
|
||||
{
|
||||
PasswdProcess proc(0);
|
||||
PasswdProcess proc;
|
||||
|
||||
int ret = proc.checkCurrent(password().toLocal8Bit());
|
||||
switch (ret)
|
||||
|
@ -92,7 +92,7 @@ int KDEpasswd1Dialog::getPassword(QByteArray &password)
|
|||
|
||||
|
||||
|
||||
KDEpasswd2Dialog::KDEpasswd2Dialog(const char *oldpass, const QByteArray &user)
|
||||
KDEpasswd2Dialog::KDEpasswd2Dialog(const char *oldpass, const QString &user)
|
||||
: KNewPasswordDialog()
|
||||
{
|
||||
m_Pass = oldpass;
|
||||
|
@ -102,7 +102,7 @@ KDEpasswd2Dialog::KDEpasswd2Dialog(const char *oldpass, const QByteArray &user)
|
|||
if (m_User.isEmpty())
|
||||
setPrompt(i18n("Please enter your new password:"));
|
||||
else
|
||||
setPrompt(i18n("Please enter the new password for user <b>%1</b>:", QString::fromLocal8Bit(m_User)));
|
||||
setPrompt(i18n("Please enter the new password for user <b>%1</b>:", m_User));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#include <kpassworddialog.h>
|
||||
#include <knewpassworddialog.h>
|
||||
#include <QtCore/qbytearray.h>
|
||||
#include <QString>
|
||||
|
||||
class KDEpasswd1Dialog
|
||||
: public KPasswordDialog
|
||||
|
@ -50,14 +50,14 @@ class KDEpasswd2Dialog
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
KDEpasswd2Dialog(const char *oldpass, const QByteArray &user);
|
||||
KDEpasswd2Dialog(const char *oldpass, const QString &user);
|
||||
~KDEpasswd2Dialog();
|
||||
|
||||
void accept();
|
||||
|
||||
private:
|
||||
const char *m_Pass;
|
||||
QByteArray m_User;
|
||||
QString m_User;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <kde_file.h>
|
||||
#include <kcomponentdata.h>
|
||||
#include <kmimetype.h>
|
||||
#include <kuser.h>
|
||||
#include <kdemacros.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
@ -35,8 +36,6 @@
|
|||
#include <QEventLoop>
|
||||
|
||||
#include <time.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -64,12 +63,8 @@ extern "C" {
|
|||
TrashProtocol::TrashProtocol( const QByteArray& protocol, const QByteArray &pool, const QByteArray &app)
|
||||
: SlaveBase(protocol, pool, app )
|
||||
{
|
||||
struct passwd *user = getpwuid( getuid() );
|
||||
if ( user )
|
||||
m_userName = QString::fromLatin1(user->pw_name);
|
||||
struct group *grp = getgrgid( getgid() );
|
||||
if ( grp )
|
||||
m_groupName = QString::fromLatin1(grp->gr_name);
|
||||
m_userName = KUser(::getuid()).loginName();
|
||||
m_groupName = KUserGroup(::getgid()).name();
|
||||
}
|
||||
|
||||
TrashProtocol::~TrashProtocol()
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
// Qt
|
||||
|
@ -397,27 +396,13 @@ void UnixProcessInfo::readUserName()
|
|||
const int uid = userId(&ok);
|
||||
if (!ok) return;
|
||||
|
||||
struct passwd passwdStruct;
|
||||
struct passwd* getpwResult;
|
||||
char* getpwBuffer;
|
||||
long getpwBufferSize;
|
||||
int getpwStatus;
|
||||
|
||||
getpwBufferSize = sysconf(_SC_GETPW_R_SIZE_MAX);
|
||||
if (getpwBufferSize == -1)
|
||||
getpwBufferSize = 16384;
|
||||
|
||||
getpwBuffer = new char[getpwBufferSize];
|
||||
if (getpwBuffer == NULL)
|
||||
return;
|
||||
getpwStatus = getpwuid_r(uid, &passwdStruct, getpwBuffer, getpwBufferSize, &getpwResult);
|
||||
if ((getpwStatus == 0) && (getpwResult != NULL)) {
|
||||
setUserName(QString(passwdStruct.pw_name));
|
||||
const KUser kuser(static_cast<K_UID>(uid));
|
||||
if (kuser.isValid()) {
|
||||
setUserName(kuser.loginName());
|
||||
} else {
|
||||
setUserName(QString());
|
||||
kWarning() << "getpwuid_r returned error : " << getpwStatus;
|
||||
kWarning() << "invalid user ID: " << uid;
|
||||
}
|
||||
delete [] getpwBuffer;
|
||||
}
|
||||
|
||||
#if defined(Q_OS_LINUX) || defined(Q_OS_HURD)
|
||||
|
|
|
@ -37,7 +37,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#include <config-workspace.h>
|
||||
#include <config-unix.h>
|
||||
#include <config-ksmserver.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -75,6 +75,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#include <kprocess.h>
|
||||
#include <kdebug.h>
|
||||
#include <kshell.h>
|
||||
#include <kuser.h>
|
||||
#include <kworkspace/kdisplaymanager.h>
|
||||
#include <krandom.h>
|
||||
#include <klauncher_iface.h>
|
||||
|
@ -97,8 +98,8 @@ QProcess* KSMServer::startApplication( const QStringList& cmd, const QString& cl
|
|||
if ( command.isEmpty() )
|
||||
return NULL;
|
||||
if ( !userId.isEmpty()) {
|
||||
struct passwd* pw = getpwuid( getuid());
|
||||
if( pw != NULL && userId != QString::fromLocal8Bit( pw->pw_name )) {
|
||||
const KUser kuser(::getuid());
|
||||
if( kuser.isValid() && userId != kuser.loginName() ) {
|
||||
command.prepend( "--" );
|
||||
command.prepend( userId );
|
||||
command.prepend( "-u" );
|
||||
|
|
|
@ -30,7 +30,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
#include <config-unix.h>
|
||||
|
||||
#include <pwd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
|
|
@ -31,7 +31,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
#include "config-unix.h"
|
||||
|
||||
#include <pwd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
|
|
@ -23,10 +23,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <pwd.h>
|
||||
#include <fixx11h.h>
|
||||
#include <kconfig.h>
|
||||
#include <kglobal.h>
|
||||
#include <kuser.h>
|
||||
|
||||
#include "workspace.h"
|
||||
#include "client.h"
|
||||
|
@ -428,9 +428,9 @@ SessionSaveDoneHelper::SessionSaveDoneHelper()
|
|||
props[ 0 ].type = const_cast< char* >(SmCARD8);
|
||||
props[ 0 ].num_vals = 1;
|
||||
props[ 0 ].vals = &propvalue[ 0 ];
|
||||
struct passwd* entry = getpwuid(geteuid());
|
||||
propvalue[ 1 ].length = entry != NULL ? strlen(entry->pw_name) : 0;
|
||||
propvalue[ 1 ].value = (SmPointer)(entry != NULL ? entry->pw_name : "");
|
||||
QByteArray username = KUser(KUser::UseEffectiveUID).loginName().toLocal8Bit();
|
||||
propvalue[ 1 ].length = username.size();
|
||||
propvalue[ 1 ].value = (SmPointer)(username.isEmpty() ? "" : username.data());
|
||||
props[ 1 ].name = const_cast< char* >(SmUserID);
|
||||
props[ 1 ].type = const_cast< char* >(SmARRAY8);
|
||||
props[ 1 ].num_vals = 1;
|
||||
|
|
|
@ -39,7 +39,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <sched.h>
|
||||
#include <dirent.h>
|
||||
#include <pwd.h>
|
||||
#include <procfs.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/resource.h>
|
||||
|
|
|
@ -30,11 +30,10 @@
|
|||
#include <kapplication.h>
|
||||
#include <klocale.h>
|
||||
#include <kstandarddirs.h>
|
||||
#include <kuser.h>
|
||||
#include <ksmserver_interface.h>
|
||||
|
||||
#include <unistd.h> // geteuid()
|
||||
#include <stdlib.h> // getenv()
|
||||
#include <pwd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
|
@ -92,9 +91,9 @@ KRequestShutdownHelper::KRequestShutdownHelper()
|
|||
props[ 0 ].type = const_cast< char* >( SmCARD8 );
|
||||
props[ 0 ].num_vals = 1;
|
||||
props[ 0 ].vals = &propvalue[ 0 ];
|
||||
struct passwd* entry = getpwuid( geteuid() );
|
||||
propvalue[ 1 ].length = entry != NULL ? strlen( entry->pw_name ) : 0;
|
||||
propvalue[ 1 ].value = (SmPointer)( entry != NULL ? entry->pw_name : "" );
|
||||
QByteArray username = KUser(KUser::UseEffectiveUID).loginName().toLocal8Bit();
|
||||
propvalue[ 1 ].length = username.size();
|
||||
propvalue[ 1 ].value = (SmPointer)( username.isEmpty() ? "" : username.data() );
|
||||
props[ 1 ].name = const_cast< char* >( SmUserID );
|
||||
props[ 1 ].type = const_cast< char* >( SmARRAY8 );
|
||||
props[ 1 ].num_vals = 1;
|
||||
|
|
Loading…
Add table
Reference in a new issue