summaryrefslogtreecommitdiff
path: root/noncore/settings/usermanager/passwd.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/usermanager/passwd.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/usermanager/passwd.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/noncore/settings/usermanager/passwd.cpp b/noncore/settings/usermanager/passwd.cpp
index 310cef8..5063661 100644
--- a/noncore/settings/usermanager/passwd.cpp
+++ b/noncore/settings/usermanager/passwd.cpp
@@ -2,24 +2,25 @@
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "passwd.h"
// Needed for crypt_make_salt();
#include <sys/types.h>
+#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
Passwd::Passwd() {
}
Passwd::~Passwd() {
}
// This function is taken from 'busybox'.
int Passwd::i64c(int i)
{
@@ -130,34 +131,36 @@ bool Passwd::searchUser(QRegExp &userRegExp) {
}
bool Passwd::findUser(const char *username) {
QRegExp userRegExp(QString("^%1\\:").arg(username));
return searchUser(userRegExp);
}
bool Passwd::findUser(int uid) {
QRegExp userRegExp(QString(":%1\\:").arg(uid));
return searchUser(userRegExp);
}
-bool Passwd::addUser(QString pw_name, QString pw_passwd, int pw_uid, int pw_gid, QString pw_gecos,QString pw_dir, QString pw_shell, bool createGroup=true) {
+bool Passwd::addUser(QString pw_name, QString pw_passwd, int pw_uid, int pw_gid, QString pw_gecos,QString pw_dir, QString pw_shell, bool createGroup) {
QString tempString;
if((createGroup) && (!(findGroup(pw_gid)))) addGroup(pw_name,pw_gid);
pw_passwd = crypt(pw_passwd, crypt_make_salt());
tempString=pw_name+":"+pw_passwd+":"+QString::number(pw_uid)+":"+QString::number(pw_gid)+":"+pw_gecos+":"+pw_dir+":"+pw_shell;
passwdStringList.append(tempString);
// Make home dir.
QDir d;
if(!(d.exists(pw_dir))) {
d.mkdir(pw_dir);
+ chown(pw_dir,pw_uid,pw_gid);
+ chmod(pw_dir,S_IRUSR|S_IWUSR|S_IXUSR);
}
return 1;
}
bool Passwd::updateUser(QString login) {
QRegExp userRegExp(QString("^%1\\:").arg(login));
for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) {
if(userRegExp.find((*it),0)!=-1) {
*it=QString(pw_name+":"+pw_passwd+":"+QString::number(pw_uid)+":"+QString::number(pw_gid)+":"+pw_gecos+":"+pw_dir+":"+pw_shell);
return true;
}
}