A few deprecations eradicated involving QCheckBox.
[kdenetwork.git] / filesharing / advanced / kcm_sambaconf / passwd.cpp
blobe44639b7f58cf88351b42e55ad0c953e5afe97e9
1 /***************************************************************************
2 passwd.cpp - description
3 -------------------
4 begin : Tue June 6 2002
5 copyright : (C) 2002 by Jan Schaefer
6 email : janschaefer@users.sourceforge.net
7 ***************************************************************************/
9 /******************************************************************************
10 * *
11 * This file is part of KSambaPlugin. *
12 * *
13 * KSambaPlugin is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 * *
18 * KSambaPlugin is distributed in the hope that it will be useful, *
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21 * GNU General Public License for more details. *
22 * *
23 * You should have received a copy of the GNU General Public License *
24 * along with KSambaPlugin; if not, write to the Free Software *
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
26 * *
27 ******************************************************************************/
30 #include <sys/types.h>
31 #include <pwd.h>
32 #include <grp.h>
33 #include <iostream>
35 #include "passwd.h"
37 UnixUserList getUnixUserList()
39 UnixUserList list;
41 struct passwd* p;
43 while ((p = getpwent()))
45 if (!p) continue;
47 UnixUser *u = new UnixUser();
48 u->name = p->pw_name;
49 u->uid = p->pw_uid;
50 list.append(u);
53 endpwent();
55 list.sort();
57 return list;
60 QStringList getUnixUsers()
62 QStringList list;
64 struct passwd* p;
66 while ((p = getpwent()))
68 if (p)
69 list.append(QString(p->pw_name));
72 endpwent();
74 list.sort();
76 return list;
79 QStringList getUnixGroups()
81 QStringList list;
83 struct group* g;
85 while ((g = getgrent()))
87 if (g)
88 list.append(QString(g->gr_name));
91 endgrent();
93 list.sort();
95 return list;
98 int getUserUID(const QString & name)
100 if (name.isNull()) return -1;
102 struct passwd* p;
104 p = getpwnam(name.toLocal8Bit());
106 if (p)
107 return p->pw_uid;
109 return -1;
112 int getUserGID(const QString & name)
114 if (name.isNull()) return -1;
116 struct passwd* p;
118 p = getpwnam(name.toLocal8Bit());
120 if (p)
121 return p->pw_gid;
123 return -1;
126 int getGroupGID(const QString & name)
128 if (name.isNull()) return -1;
130 struct group* g;
132 g = getgrnam(name.toLocal8Bit());
134 if (g)
135 return g->gr_gid;
137 return -1;
140 bool isUserInGroup(const QString & user, const QString & group) {
141 struct group* g;
143 while ((g = getgrent()))
145 if (g && QString(g->gr_name) == group) {
146 char** names = g->gr_mem;
148 int i = 0;
149 char* name = names[0];
150 while (name != 0L) {
151 i++;
152 if (QString(name) == user) {
153 endgrent();
154 return true;
156 name = names[i];
158 break;
162 endgrent();
163 return false;