summaryrefslogtreecommitdiff
path: root/noncore/settings/usermanager/passwd.h
blob: 37c41dcc80405f5f1fde4e30695f7d911cc3ed9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef PASSWD_H
#define PASSWD_H

#include <qobject.h>
#include <qfile.h>
#include <qstring.h>
#include <qstringlist.h>
#include <qtextstream.h>
#include <qregexp.h>
#include <qdir.h>

#include <crypt.h>
#include <pwd.h>
#include <grp.h>

class Passwd
{
public:
	QStringList passwdStringList;	// List of all users (name,passwd,uid,gid,gecos,dir,shell)
	QStringList groupStringList;	// List of all groups (name,gid,mem)
	
	// pwentry
	QString pw_name;
	QString pw_passwd;
	int pw_uid;
	int pw_gid;
	QString pw_gecos;
	QString pw_dir;
	QString pw_shell;

	// grentry
	QString gr_name;
	int gr_gid;
	QStringList gr_mem;
	
	Passwd(void);
	~Passwd(void);
	bool open(void);
	bool close(void);
	char *crypt_make_salt(void);
	void splitPasswdEntry(QString &userString);
	void splitGroupEntry(QString &groupString);
	bool findUser(const char *username);
	bool findUser(int uid);
	bool 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 updateUser(QString login);
	bool delUser(const char *username, bool delGroup=true);
	bool delUser(int uid, bool delGroup=true);
	bool findGroup(const char *groupname);
	bool findGroup(int gid);
	bool addGroup(QString gr_name, int gr_gid);
	bool updateGroup(int gid);
	bool delGroup(const char *groupname);
	bool delGroup(int gid);
	bool addGroupMember(QString groupname,QString member);
	bool delGroupMember(QString groupname,QString member);

private:
	QString userString;
	QString groupString;
	
	int i64c(int i);
	bool searchUser(QRegExp &userRegExp);
	bool deleteUser(QRegExp &userRegExp, bool delGroup);
	bool searchGroup(QRegExp &groupRegExp);
	bool deleteGroup(QRegExp &groupRegExp);
	QStringList userdataStringList;
	QStringList groupdataStringList;
	
	QFile *passwd_file;
	QFile *group_file;
};

extern Passwd *accounts;	// Create a global object.

#endif