1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the QtSystems module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL21$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 or version 3 as published by the Free
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22** following information to ensure the GNU Lesser General Public License
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** As a special exception, The Qt Company gives you certain additional
27** rights. These rights are described in The Qt Company LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** $QT_END_LICENSE$
31**
32****************************************************************************/
33
34#include "qserviceclientcredentials_p.h"
35#include "qserviceclientcredentials.h"
36#include <QDebug>
37
38QT_BEGIN_NAMESPACE
39
40/*!
41 \class QServiceClientCredentials
42 \brief The QServiceClientCredentials class holds credentials for the service client.
43
44 This class is used when implementing service security. It allows the service to check
45 the credentials of the client and then accept or reject the client.
46*/
47
48/*!
49 \internal
50*/
51QServiceClientCredentials::QServiceClientCredentials()
52 : d(new QServiceClientCredentialsPrivate)
53{
54 Q_ASSERT(d);
55}
56
57/*!
58 \internal
59*/
60QServiceClientCredentials::QServiceClientCredentials(const QServiceClientCredentials &other)
61 : d(other.d)
62{
63}
64
65/*!
66 \internal
67*/
68QServiceClientCredentials &QServiceClientCredentials::operator=(const QServiceClientCredentials &other)
69{
70 d = other.d;
71 return *this;
72}
73
74/*!
75 \internal
76*/
77QServiceClientCredentials::~QServiceClientCredentials()
78{
79}
80
81/*!
82 Returns the process identifier for the client. On Unix systems this is the PID
83 of the client process.
84*/
85qintptr QServiceClientCredentials::getProcessIdentifier() const
86{
87 return d->pid;
88}
89
90/*!
91 Returns the group identifier for the client. On Unix systems this is the GID
92 of the client process.
93*/
94qintptr QServiceClientCredentials::getGroupIdentifier() const
95{
96 return d->gid;
97}
98
99/*!
100 Returns the user identifier for the client. On Unix systems this is the UID
101 of the client process.
102*/
103qintptr QServiceClientCredentials::getUserIdentifier() const
104{
105 return d->uid;
106}
107
108/*!
109 Returns true if this object is valid.
110*/
111bool QServiceClientCredentials::isValid() const
112{
113 return d && (d->pid || d->uid || d->gid);
114}
115
116/*!
117 Called by the service to accept or reject the client. Set \a isAccepted
118 to true to accept the client.
119*/
120void QServiceClientCredentials::setClientAccepted(bool isAccepted)
121{
122 d->acceptedSet = true;
123 d->accepted = isAccepted;
124}
125
126/*!
127 Returns true if the client has been accepted, false otherwise.
128*/
129bool QServiceClientCredentials::isClientAccepted() const
130{
131 if (!d->acceptedSet) {
132 qWarning() << "SFW credentials were queried, but service never called setClientAccepted(bool). Returning default accepted. This will break in the furture.";
133 }
134 return d->accepted;
135}
136
137QT_END_NAMESPACE
138
139

source code of qtsystems/src/serviceframework/qserviceclientcredentials.cpp