source: src-qt4/pc-usermanager/user.cpp @ 87d35b7

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2
Last change on this file since 87d35b7 was 87d35b7, checked in by Kris Moore <kris@…>, 12 months ago

Add ability to PEFS encrypt users home-directories when we
create a new user via the user-manager GUI

  • Property mode set to 100755
File size: 4.3 KB
Line 
1/***************************************************************************
2 *   Copyright (C) 2005, 2012 by Tim McCormick   *
3 *   tim@pcbsd.org   *
4 *                                                                         *
5 *   Permission is hereby granted, free of charge, to any person obtaining *
6 *   a copy of this software and associated documentation files (the       *
7 *   "Software"), to deal in the Software without restriction, including   *
8 *   without limitation the rights to use, copy, modify, merge, publish,   *
9 *   distribute, sublicense, and/or sell copies of the Software, and to    *
10 *   permit persons to whom the Software is furnished to do so, subject to *
11 *   the following conditions:                                             *
12 *                                                                         *
13 *   The above copyright notice and this permission notice shall be        *
14 *   included in all copies or substantial portions of the Software.       *
15 *                                                                         *
16 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       *
17 *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    *
18 *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *
20 *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
21 *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
22 *   OTHER DEALINGS IN THE SOFTWARE.                                       *
23 ***************************************************************************/
24
25#include <unistd.h>
26       
27#include "user.h"
28#include <QDebug>
29
30User::User() {
31    username = "Not set";
32    uid = -1;
33    gid = -1;
34    home = "Not set";
35    shell = "Not set";
36    fullname = "Not set";
37    enc = false;
38    status = 0;
39    password = "";
40    deleteHome = false;
41}
42
43User::User(QString username, int uid, int gid, QString home, QString shell, QString fullname) {
44    this->username = username;
45    this->uid = uid;
46    this->gid = gid;
47    this->home = home;
48    if ( QFile::exists(home + "/.pefs.db"))
49      this->enc = true; 
50    else
51      this->enc = false; 
52    this->shell = shell;
53    this->fullname = fullname;
54    status = 0;
55    this->password = "";
56}
57
58User::User(QString username, QString home, QString shell, QString fullname, QString password, int gid, bool isNew, int uid)
59{
60    this->username = username;
61    this->home = home;
62    this->shell = shell;
63    this->fullname = fullname;
64    this->enc = false;
65    status = 0;
66    if (isNew) { status = 2; }
67    this->uid = uid;
68    this->gid = gid;
69    this->clearPass = password;
70   
71    setPassword(password);
72}
73
74User::~User() {
75   
76}
77
78QString User::getUsername() {
79    return username;
80}
81
82int User::getUid() {
83    return uid;
84}
85
86int User::getGid() {
87    return gid;
88}
89
90bool User::getEnc() {
91    return enc;
92}
93
94void User::setEnc(bool Enc) {
95    this->enc = Enc;
96}
97
98QString User::getHome() {
99    return home;
100}
101
102QString User::getShell() {
103    return shell;
104}
105
106QString User::getFullname() {
107    return fullname;
108}
109
110bool User::getChanges() {
111    return status == 1;
112}
113
114void User::setChanges() {
115    if (status == 0) { status = 1; }
116}
117
118void User::setGid(int gid) {
119    this->gid = gid;
120}
121
122void User::setHome(QString home) {
123    this->home = home;
124}
125
126void User::setShell(QString shell) {
127    this->shell = shell;
128}
129
130void User::setFullname(QString fullname) {
131    this->fullname = fullname;
132}
133
134bool User::getNew()
135{
136    return status == 2;
137}
138
139void User::setNew()
140{
141    status = 2;
142}
143
144void User::setPassword(QString password)
145{
146    this->password = crypt(password.toAscii(), "KG");
147    qDebug("Done with crypt now........");
148    setChanges();
149}
150
151QString User::getPassword()
152{
153    return password;
154}
155
156QString User::getClearPassword()
157{
158    return clearPass;
159}
160
161bool User::getDeleted()
162{
163    return status == 3;
164}
165
166void User::setDeleted()
167{
168    status = 3;
169}
170
171uint User::getStatus()
172{
173    return status;
174}
175
176void User::setStatus(uint status)
177{
178    this->status = status;
179}
180
181/**
182 * @param deleteHome is true if the home directory should be deleted
183 */
184void User::setDeleteHome(bool deleteHome)
185{
186    this->deleteHome = deleteHome;
187}
188
189/**
190  * @return true if the home directory should be deleted
191  */
192bool User::getDeleteHome()
193{
194    return deleteHome;
195}
Note: See TracBrowser for help on using the repository browser.