summaryrefslogtreecommitdiff
path: root/noncore/settings/usermanager/passwd.cpp
Unidiff
Diffstat (limited to 'noncore/settings/usermanager/passwd.cpp') (more/less context) (ignore 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
@@ -1,37 +1,38 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9 9
10#include "passwd.h" 10#include "passwd.h"
11 11
12// Needed for crypt_make_salt(); 12// Needed for crypt_make_salt();
13#include <sys/types.h> 13#include <sys/types.h>
14#include <sys/stat.h>
14#include <unistd.h> 15#include <unistd.h>
15#include <time.h> 16#include <time.h>
16 17
17Passwd::Passwd() { 18Passwd::Passwd() {
18} 19}
19 20
20Passwd::~Passwd() { 21Passwd::~Passwd() {
21} 22}
22 23
23// This function is taken from 'busybox'. 24// This function is taken from 'busybox'.
24int Passwd::i64c(int i) 25int Passwd::i64c(int i)
25{ 26{
26 if (i <= 0) 27 if (i <= 0)
27 return ('.'); 28 return ('.');
28 if (i == 1) 29 if (i == 1)
29 return ('/'); 30 return ('/');
30 if (i >= 2 && i < 12) 31 if (i >= 2 && i < 12)
31 return ('0' - 2 + i); 32 return ('0' - 2 + i);
32 if (i >= 12 && i < 38) 33 if (i >= 12 && i < 38)
33 return ('A' - 12 + i); 34 return ('A' - 12 + i);
34 if (i >= 38 && i < 63) 35 if (i >= 38 && i < 63)
35 return ('a' - 38 + i); 36 return ('a' - 38 + i);
36 return ('z'); 37 return ('z');
37} 38}
@@ -118,58 +119,60 @@ void Passwd::splitGroupEntry(QString &groupString) {
118 gr_mem=QStringList::split(" ",(*it++)); 119 gr_mem=QStringList::split(" ",(*it++));
119} 120}
120 121
121bool Passwd::searchUser(QRegExp &userRegExp) { 122bool Passwd::searchUser(QRegExp &userRegExp) {
122 QStringList tempStringList(passwdStringList.grep(userRegExp)); 123 QStringList tempStringList(passwdStringList.grep(userRegExp));
123 if((tempStringList.isEmpty())) { 124 if((tempStringList.isEmpty())) {
124 return false; 125 return false;
125 } else { 126 } else {
126 userString=(*(tempStringList.begin())); 127 userString=(*(tempStringList.begin()));
127 splitPasswdEntry(userString); 128 splitPasswdEntry(userString);
128 } 129 }
129 return true; 130 return true;
130} 131}
131 132
132bool Passwd::findUser(const char *username) { 133bool Passwd::findUser(const char *username) {
133 QRegExp userRegExp(QString("^%1\\:").arg(username)); 134 QRegExp userRegExp(QString("^%1\\:").arg(username));
134 return searchUser(userRegExp); 135 return searchUser(userRegExp);
135} 136}
136 137
137bool Passwd::findUser(int uid) { 138bool Passwd::findUser(int uid) {
138 QRegExp userRegExp(QString(":%1\\:").arg(uid)); 139 QRegExp userRegExp(QString(":%1\\:").arg(uid));
139 return searchUser(userRegExp); 140 return searchUser(userRegExp);
140} 141}
141 142
142bool 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) { 143bool 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) {
143 QString tempString; 144 QString tempString;
144 if((createGroup) && (!(findGroup(pw_gid)))) addGroup(pw_name,pw_gid); 145 if((createGroup) && (!(findGroup(pw_gid)))) addGroup(pw_name,pw_gid);
145 pw_passwd = crypt(pw_passwd, crypt_make_salt()); 146 pw_passwd = crypt(pw_passwd, crypt_make_salt());
146 tempString=pw_name+":"+pw_passwd+":"+QString::number(pw_uid)+":"+QString::number(pw_gid)+":"+pw_gecos+":"+pw_dir+":"+pw_shell; 147 tempString=pw_name+":"+pw_passwd+":"+QString::number(pw_uid)+":"+QString::number(pw_gid)+":"+pw_gecos+":"+pw_dir+":"+pw_shell;
147 passwdStringList.append(tempString); 148 passwdStringList.append(tempString);
148 // Make home dir. 149 // Make home dir.
149 QDir d; 150 QDir d;
150 if(!(d.exists(pw_dir))) { 151 if(!(d.exists(pw_dir))) {
151 d.mkdir(pw_dir); 152 d.mkdir(pw_dir);
153 chown(pw_dir,pw_uid,pw_gid);
154 chmod(pw_dir,S_IRUSR|S_IWUSR|S_IXUSR);
152 } 155 }
153 return 1; 156 return 1;
154} 157}
155 158
156bool Passwd::updateUser(QString login) { 159bool Passwd::updateUser(QString login) {
157 QRegExp userRegExp(QString("^%1\\:").arg(login)); 160 QRegExp userRegExp(QString("^%1\\:").arg(login));
158 for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { 161 for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) {
159 if(userRegExp.find((*it),0)!=-1) { 162 if(userRegExp.find((*it),0)!=-1) {
160 *it=QString(pw_name+":"+pw_passwd+":"+QString::number(pw_uid)+":"+QString::number(pw_gid)+":"+pw_gecos+":"+pw_dir+":"+pw_shell); 163 *it=QString(pw_name+":"+pw_passwd+":"+QString::number(pw_uid)+":"+QString::number(pw_gid)+":"+pw_gecos+":"+pw_dir+":"+pw_shell);
161 return true; 164 return true;
162 } 165 }
163 } 166 }
164 return false; 167 return false;
165} 168}
166 169
167bool Passwd::deleteUser(QRegExp &userRegExp, bool delGroup) { 170bool Passwd::deleteUser(QRegExp &userRegExp, bool delGroup) {
168 for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { 171 for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) {
169 if(userRegExp.find((*it),0)!=-1) { 172 if(userRegExp.find((*it),0)!=-1) {
170 splitPasswdEntry(*it); 173 splitPasswdEntry(*it);
171 if(delGroup) this->delGroup(pw_gid); 174 if(delGroup) this->delGroup(pw_gid);
172 passwdStringList.remove(it); 175 passwdStringList.remove(it);
173 return true; 176 return true;
174 } 177 }
175 } 178 }