~ubuntu-branches/ubuntu/natty/kdenetwork/natty-proposed

« back to all changes in this revision

Viewing changes to .pc/kubuntu_05_samba_sharing.diff/filesharing/advanced/kcm_sambaconf/passwd.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-02-21 14:26:58 UTC
  • Revision ID: package-import@ubuntu.com-20110221142658-mzt9flk82tzdunxj
Tags: 4:4.6.0-0ubuntu4
Update kubuntu_05_samba_sharing.diff to match master

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 ***************************************************************************/
 
8
 
 
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
 ******************************************************************************/
 
28
 
 
29
 
 
30
#include <sys/types.h>
 
31
#include <pwd.h>
 
32
#include <grp.h>
 
33
#include <iostream>
 
34
 
 
35
#include "passwd.h"
 
36
 
 
37
UnixUserList getUnixUserList()
 
38
{
 
39
  UnixUserList list;
 
40
 
 
41
  struct passwd* p;
 
42
 
 
43
  while ((p = getpwent()))
 
44
  {
 
45
    if (!p) continue;
 
46
 
 
47
    UnixUser *u = new UnixUser();
 
48
    u->name = p->pw_name;
 
49
    u->uid = p->pw_uid;
 
50
    list.append(u);
 
51
  }
 
52
 
 
53
  endpwent();
 
54
 
 
55
  list.sort();
 
56
 
 
57
  return list;
 
58
}
 
59
 
 
60
QStringList getUnixUsers()
 
61
{
 
62
  QStringList list;
 
63
 
 
64
  struct passwd* p;
 
65
 
 
66
  while ((p = getpwent()))
 
67
  {
 
68
    if (p)
 
69
       list.append(QString(p->pw_name));
 
70
  }
 
71
 
 
72
  endpwent();
 
73
 
 
74
  list.sort();
 
75
 
 
76
  return list;
 
77
}
 
78
 
 
79
QStringList getUnixGroups()
 
80
{
 
81
  QStringList list;
 
82
 
 
83
  struct group* g;
 
84
 
 
85
  while ((g = getgrent()))
 
86
  {
 
87
    if (g)
 
88
       list.append(QString(g->gr_name));
 
89
  }
 
90
 
 
91
  endgrent();
 
92
 
 
93
  list.sort();
 
94
 
 
95
  return list;
 
96
}
 
97
 
 
98
int getUserUID(const QString & name)
 
99
{
 
100
  if (name.isNull()) return -1;
 
101
 
 
102
  struct passwd* p;
 
103
 
 
104
  p = getpwnam(name.toLocal8Bit());
 
105
 
 
106
  if (p)
 
107
     return p->pw_uid;
 
108
 
 
109
  return -1;
 
110
}
 
111
 
 
112
int getUserGID(const QString & name)
 
113
{
 
114
  if (name.isNull()) return -1;
 
115
 
 
116
  struct passwd* p;
 
117
 
 
118
  p = getpwnam(name.toLocal8Bit());
 
119
 
 
120
  if (p)
 
121
    return p->pw_gid;
 
122
 
 
123
  return -1;
 
124
}
 
125
 
 
126
int getGroupGID(const QString & name)
 
127
{
 
128
  if (name.isNull()) return -1;
 
129
 
 
130
  struct group* g;
 
131
 
 
132
  g = getgrnam(name.toLocal8Bit());
 
133
 
 
134
  if (g)
 
135
    return g->gr_gid;
 
136
 
 
137
  return -1;
 
138
}
 
139
 
 
140
bool isUserInGroup(const QString & user, const QString & group) {
 
141
  struct group* g;
 
142
 
 
143
  while ((g = getgrent()))
 
144
  {
 
145
    if (g && QString(g->gr_name) == group) {
 
146
       char** names = g->gr_mem;
 
147
 
 
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;
 
155
          }
 
156
          name = names[i];
 
157
       }
 
158
       break;
 
159
    }
 
160
  }
 
161
 
 
162
  endgrent();
 
163
  return false;
 
164
}