summaryrefslogtreecommitdiffstats
path: root/filesharing/advanced/kcm_sambaconf/smbpasswdfile.h
blob: 88eb859417e178f4318b656d9c042773d852fff9 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/***************************************************************************
                          smbpasswdfile.h  -  description
                             -------------------
    begin                : Tue June 6 2002
    copyright            : (C) 2002 by Jan Sch�fer
    email                : [email protected]
 ***************************************************************************/

/******************************************************************************
 *                                                                            *
 *  This file is part of KSambaPlugin.                                          *
 *                                                                            *
 *  KSambaPlugin 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.                                       *
 *                                                                            *
 *  KSambaPlugin is distributed in the hope that it will be useful,                 *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
 *  GNU General Public License for more details.                              *
 *                                                                            *
 *  You should have received a copy of the GNU General Public License         *
 *  along with KSambaPlugin; if not, write to the Free Software                     *
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA  *
 *                                                                            *
 ******************************************************************************/

#ifndef SMBPASSWDFILE_H
#define SMBPASSWDFILE_H


/**
  *@author Jan Sch�fer
  */

#include <tqstring.h>
#include <kurl.h>

class SambaFile;
class KProcess;

/**
 * Simple class to store a Samba User
 **/
class SambaUser
{
public:
  SambaUser(const TQString & aName = TQString::null, int anUid = -1) {name = aName; uid = anUid;};

  TQString name;
  int uid;
  int gid;
  bool isUserAccount;
  bool hasNoPassword;
  bool isDisabled;
  bool isWorkstationTrustAccount;
};

/**
 * A TQPtrList of SambaUser
 **/
class SambaUserList : public TQPtrList<SambaUser>
{
public:
  TQStringList getUserNames();
};

/**
 * This class represents the SAMBA smbpasswd file.
 * It provides :
 * - getting a list of all SAMBA users
 * - adding a new user -> uses smbpasswd program
 * - removing an existing user -> uses smbpasswd program
 **/
class SmbPasswdFile : public QObject
{
Q_OBJECT
public: 
  SmbPasswdFile();
	SmbPasswdFile(const KURL &);
	~SmbPasswdFile();

  void setUrl(const KURL &);
  
  /**
   * Returns a list of all users stored in
   * the smbpasswd file
   **/
  SambaUserList getSambaUserList();

  /**
   * Calls smbpasswd with the given arguments
   **/
  bool executeSmbpasswd(const TQStringList & args);
  
  /**
   * Tries to add the passed user to the smbpasswd file
   * returns true if successful otherwise false
   **/
  bool addUser(const SambaUser &, const TQString & password);

  /**
   * Tries to remove the passed user from the smbpasswd file
   * returns true if successful otherwise false
   **/
  bool removeUser(const SambaUser &);

  /**
   * Tries to change the password of the passed user
   * if it fails returns false otherwise true
   **/
  bool changePassword(const SambaUser &, const TQString & password);
  
  bool enableUser(const SambaUser &);
  
  bool disableUser(const SambaUser &);
  
  bool setNoPassword(const SambaUser &);
  
  bool setMachineTrustAccount(const SambaUser &);

  bool joinADomain(const TQString &, const TQString &, const TQString &, const TQString &);
  
  /**
   * Returns the Url of the smbpasswd file
   * specified in the [global] section of
   * the smb.conf file.
   * If there is no entry in the [global] section
   * it tries to guess the location.
   **/
  static KURL getUrlFromSambaFile(const SambaFile *file);
protected:
  KURL _url;
  TQString _smbpasswdOutput;

protected slots:
  void smbpasswdStdOutReceived(KProcess*,char*,int);
};

#endif