~ubuntu-branches/ubuntu/vivid/nfs4-acl-tools/vivid-proposed

« back to all changes in this revision

Viewing changes to GUI/nfs4-acl-editor/nfs4acleditor.h

  • Committer: Bazaar Package Importer
  • Author(s): Timo Aaltonen
  • Date: 2009-05-12 13:53:04 UTC
  • Revision ID: james.westby@ubuntu.com-20090512135304-b4hyk0en3a0v8r3p
Tags: upstream-0.3.3
ImportĀ upstreamĀ versionĀ 0.3.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  Copyright (c) 2006 The Regents of the University of Michigan.
 
2
 *  All rights reserved.
 
3
 *
 
4
 *  David M. Richter <richterd@citi.umich.edu>
 
5
 *  Alexis Mackenzie <allamack@citi.umich.edu>
 
6
 *
 
7
 *  Redistribution and use in source and binary forms, with or without
 
8
 *  modification, are permitted provided that the following conditions
 
9
 *  are met:
 
10
 *
 
11
 *  1. Redistributions of source code must retain the above copyright
 
12
 *     notice, this list of conditions and the following disclaimer.
 
13
 *  2. Redistributions in binary form must reproduce the above copyright
 
14
 *     notice, this list of conditions and the following disclaimer in the
 
15
 *     documentation and/or other materials provided with the distribution.
 
16
 *  3. Neither the name of the University nor the names of its
 
17
 *     contributors may be used to endorse or promote products derived
 
18
 *     from this software without specific prior written permission.
 
19
 *
 
20
 *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
 
21
 *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 
22
 *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
23
 *  DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 
24
 *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
25
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
26
 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 
27
 *  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 
28
 *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 
29
 *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
30
 *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
31
 */
 
32
 
 
33
#ifndef NFS4_ACL_EDITOR_H
 
34
#define NFS4_ACL_EDITOR_H 1
 
35
 
 
36
extern "C" {
 
37
#include "nfs4.h"
 
38
#include "libacl_nfs4.h"
 
39
}
 
40
 
 
41
#include <QApplication>
 
42
#include <QMainWindow>
 
43
#include <QVBoxLayout>
 
44
#include <QButtonGroup>
 
45
#include <QGroupBox>
 
46
#include <QCheckBox>
 
47
#include <QPushButton>
 
48
#include <QRadioButton>
 
49
#include <QLabel>
 
50
#include <QApplication>
 
51
#include <QtCore/qlist.h>
 
52
#include <QTableWidget>
 
53
#include <QTableWidgetItem>
 
54
#include <QGridLayout>
 
55
#include <QStringList>
 
56
#include <QHeaderView>
 
57
#include <QComboBox>
 
58
#include <QLineEdit>
 
59
#include <QFrame>
 
60
#include <QPixmap>
 
61
#include <QBitmap>
 
62
#include <QMenu>
 
63
#include <QMenuBar>
 
64
#include <QKeySequence>
 
65
#include <QFileDialog>
 
66
#include <QMap>
 
67
#include <QListWidget>
 
68
#include <QStringList>
 
69
#include <QKeyEvent>
 
70
#include <QPalette>
 
71
#include <QColor>
 
72
#include <QStackedWidget>
 
73
#include <QEvent>
 
74
 
 
75
#include "dirfiledialog.h"
 
76
 
 
77
//#define DEBUG 1
 
78
#ifdef DEBUG
 
79
#define dprintf(format, args...) printf(format, ## args)
 
80
#else
 
81
#define dprintf(format, args...)
 
82
#endif
 
83
 
 
84
#define isGroupFlag(f) (f & NFS4_ACE_IDENTIFIER_GROUP)
 
85
#define isGroupACE(a)  (isGroupFlag(a->flag))
 
86
#define isSpecialGroup(s) (!strncmp(qPrintable(s), "GROUP@", NFS4_MAX_PRINCIPALSIZE))
 
87
#define isEveryone(s) (!strncmp(qPrintable(s), "EVERYONE@", NFS4_MAX_PRINCIPALSIZE))
 
88
#define groupifyACE(a) a->flag |= NFS4_ACE_IDENTIFIER_GROUP
 
89
#define ungroupifyACE(a) a->flag &= ~NFS4_ACE_IDENTIFIER_GROUP
 
90
 
 
91
 
 
92
typedef QList<QAbstractButton *> ButtonList;
 
93
typedef QList<struct nfs4_ace*> NFS4_ACL;
 
94
typedef QListIterator<struct nfs4_ace*> NFS4_ACL_Iterator;
 
95
 
 
96
static void nfs4_acl_to_NFS4_ACL(nfs4_acl *acl, NFS4_ACL *newacl)
 
97
{
 
98
    struct nfs4_ace *ace = nfs4_get_first_ace(acl);
 
99
 
 
100
    while (ace != NULL) {
 
101
        newacl->append(ace);
 
102
        ace = nfs4_get_next_ace(&ace);
 
103
    }
 
104
}
 
105
 
 
106
struct __access_info {
 
107
        unsigned long mask;
 
108
        char *text;
 
109
        char *flag;
 
110
};
 
111
 
 
112
static const struct __access_info __file_perm_info[] = {
 
113
        {NFS4_ACE_READ_DATA, "read data", "r"},
 
114
        {NFS4_ACE_WRITE_DATA, "write data", "w"},
 
115
        {NFS4_ACE_APPEND_DATA, "append data", "a"},
 
116
        {NFS4_ACE_EXECUTE, "execute", "x"},
 
117
        {NFS4_ACE_DELETE, "delete", "d" },
 
118
        {NFS4_ACE_READ_ATTRIBUTES, "read attrs", "t"},
 
119
        {NFS4_ACE_WRITE_ATTRIBUTES, "write attrs", "T"},
 
120
        {NFS4_ACE_READ_NAMED_ATTRS, "read named attrs", "n"},
 
121
        {NFS4_ACE_WRITE_NAMED_ATTRS, "write named attrs", "N"},
 
122
        {NFS4_ACE_READ_ACL, "read ACL", "c"},
 
123
        {NFS4_ACE_WRITE_ACL, "write ACL", "C"},
 
124
        {NFS4_ACE_WRITE_OWNER, "write owner", "o"},
 
125
        {NFS4_ACE_SYNCHRONIZE, "synchronize", "y"},
 
126
};
 
127
 
 
128
static const struct __access_info __dir_perm_info[] = {
 
129
        //{NFS4_ACE_LIST_DIRECTORY, "list directory", "l"},
 
130
        {NFS4_ACE_LIST_DIRECTORY, "list directory", "r"},
 
131
        //{NFS4_ACE_ADD_FILE, "add file", "f"},
 
132
        {NFS4_ACE_ADD_FILE, "add file", "w"},
 
133
        //{NFS4_ACE_ADD_SUBDIRECTORY, "add subdirectory", "s"},
 
134
        {NFS4_ACE_ADD_SUBDIRECTORY, "add subdirectory", "a"},
 
135
        {NFS4_ACE_EXECUTE, "execute", "x"},
 
136
        {NFS4_ACE_DELETE_CHILD, "delete child", "D"},
 
137
        {NFS4_ACE_DELETE, "delete", "d" },
 
138
        {NFS4_ACE_READ_ATTRIBUTES, "read attrs", "t"},
 
139
        {NFS4_ACE_WRITE_ATTRIBUTES, "write attrs", "T"},
 
140
        {NFS4_ACE_READ_NAMED_ATTRS, "read named attrs", "n"},
 
141
        {NFS4_ACE_WRITE_NAMED_ATTRS, "write named attrs", "N"},
 
142
        {NFS4_ACE_READ_ACL, "read ACL", "c"},
 
143
        {NFS4_ACE_WRITE_ACL, "write ACL", "C"},
 
144
        {NFS4_ACE_WRITE_OWNER, "write owner", "o"},
 
145
        {NFS4_ACE_SYNCHRONIZE, "synchronize", "y"},
 
146
};
 
147
 
 
148
/*
 
149
 * generic read:  synchronize, read ACL, read attributes, read data
 
150
 * generic write: synchronize, read ACL, write ACL, write attributes, append data, write data
 
151
 * generic exec:  synchronize, read ACL, read attributes, execute
 
152
 */
 
153
static const struct __access_info __extra_perm_info[] = {
 
154
        {NFS4_ACE_GENERIC_READ, "\"read\"", ""},
 
155
        {NFS4_ACE_GENERIC_WRITE, "\"write\"", ""},
 
156
        {NFS4_ACE_GENERIC_EXECUTE, "\"exec\"", ""},
 
157
        {NFS4_ACE_MASK_ALL, "all", ""},
 
158
};
 
159
 
 
160
static const struct __access_info __ace_type_info[] = {
 
161
        {NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE, "ALLOW", "A"},
 
162
        {NFS4_ACE_ACCESS_DENIED_ACE_TYPE, "DENY", "D"},
 
163
        {NFS4_ACE_SYSTEM_AUDIT_ACE_TYPE, "AUDIT", "U"},
 
164
        {NFS4_ACE_SYSTEM_ALARM_ACE_TYPE, "ALARM", "L"},
 
165
};
 
166
 
 
167
static const struct __access_info __ace_flag_info[] = {
 
168
        {NFS4_ACE_FILE_INHERIT_ACE, "file-inherit", "f"},
 
169
        {NFS4_ACE_DIRECTORY_INHERIT_ACE, "directory-inherit", "d"},
 
170
        {NFS4_ACE_NO_PROPAGATE_INHERIT_ACE, "no-propagate-inherit", "n"},
 
171
        {NFS4_ACE_INHERIT_ONLY_ACE, "inherit-only", "i"},
 
172
        {NFS4_ACE_SUCCESSFUL_ACCESS_ACE_FLAG, "successful access", "S"},
 
173
        {NFS4_ACE_FAILED_ACCESS_ACE_FLAG, "failed access", "F"},
 
174
        {NFS4_ACE_IDENTIFIER_GROUP, "identifier group", "g"},
 
175
};
 
176
 
 
177
#define textForType(i) __ace_type_info[i].text
 
178
#define maskForType(i) __ace_type_info[i].mask
 
179
#define textForFlag(i) __ace_flag_info[i].text
 
180
#define maskForFlag(i) __ace_flag_info[i].mask
 
181
#define textForExtraPerm(i) __extra_perm_info[i].text
 
182
#define maskForExtraPerm(i) __extra_perm_info[i].mask
 
183
 
 
184
#define FILE_PERM_COUNT 13
 
185
#define FILE_PERM_COUNT1 7
 
186
#define FILE_PERM_COUNT2 6
 
187
#define DIR_PERM_COUNT  14
 
188
#define DIR_PERM_COUNT1 7
 
189
#define DIR_PERM_COUNT2 7
 
190
#define COLUMN1_PERM_COUNT 7
 
191
#define EXTRA_PERM_COUNT 4
 
192
#define TYPE_COUNT 4
 
193
#define FLAG_COUNT 6
 
194
 /* i'm thinking we'll handle isItAGroup? with the checkbox near the principal field;
 
195
  * so, i'm just skipping that last flag entry..
 
196
  * #define FLAG_COUNT 7
 
197
  */
 
198
 
 
199
 
 
200
class NFS4_ACL_Editor : public QMainWindow
 
201
{
 
202
        Q_OBJECT
 
203
 
 
204
        public:
 
205
                NFS4_ACL_Editor(QWidget *parent, char *filearg);
 
206
                void keyPressEvent(QKeyEvent *e);
 
207
                void keyReleaseEvent(QKeyEvent *e);
 
208
                void show();
 
209
 
 
210
                QWidget *w, *cw;
 
211
                QLabel *l, *fl;
 
212
                QFrame *f;
 
213
                QListWidget *lw;
 
214
                QListWidgetItem *lwi;
 
215
                QTableWidget *tw;
 
216
                QTableWidgetItem *twi;
 
217
                QStackedWidget *sw;
 
218
                QLineEdit *le;
 
219
                QCheckBox *gcb, *cb;
 
220
                QComboBox *cmb, *tcmb;
 
221
                QGroupBox *dpgb, *fpgb, *pgb, *fgb;
 
222
                QPushButton *pbu, *pbd, *pb, *rb, *sb, *ub, *db;
 
223
                QMenu *fileMenu, *actionsMenu, *editMenu, *preferencesMenu;
 
224
                DirFileDialog *dfd;
 
225
 
 
226
                QPalette normal, light;
 
227
                QColor qc;
 
228
                QColor qqc;
 
229
                QVBoxLayout *vbl, *tbl, *fbl;
 
230
                QHBoxLayout *hbl;
 
231
                QGridLayout *gl, *dgl, *fgl, *sgl;
 
232
                QButtonGroup *pbg, *dpbg, *fpbg, *sbg, *dsbg, *fsbg, *fbg, *tbg;
 
233
                QAction *a;
 
234
 
 
235
                QStringList sl;
 
236
                QString uis, gis, eis;
 
237
                QString uils, gils, eils;
 
238
                QString filename, formattedfilename;
 
239
 
 
240
                struct nfs4_acl *nacl;
 
241
                struct nfs4_ace *ace, *selectedACE;
 
242
                NFS4_ACL acl;
 
243
                char buf[16];
 
244
                int selectedACEIndex, selectedLogical, selectedVisual, deleting;
 
245
                int is_directory;
 
246
 
 
247
 
 
248
        protected:
 
249
                void reformatFilename();
 
250
                void populateMenus();
 
251
                void populateTypeWho();
 
252
                void populatePerms();
 
253
                void populatePerms(QGroupBox *qgb, QButtonGroup *qbg, int is_dir);
 
254
                void populateFlags();
 
255
                void populateButtons();
 
256
                void initWithFile(QString file);
 
257
                void initRowWithACE(int row, struct nfs4_ace *ace);
 
258
                void initRowWithList(int row, QStringList *t);
 
259
                void swapRows(int from, int to);
 
260
                QStringList *listForRow(int row);
 
261
                QIcon iconForRow(int row);
 
262
                QIcon iconForACE(struct nfs4_ace *ace);
 
263
                QIcon iconForACE(struct nfs4_ace *ace, int highlight);
 
264
                QIcon iconForPrincipal(const char *name, int is_group);
 
265
 
 
266
                #define setRowIcon(r, i) tw->verticalHeaderItem((r))->setIcon(i)
 
267
                #define setRowType(r, t) tw->item((r), 0)->setText(t)
 
268
                #define setRowPrincipal(r, p) tw->item((r), 1)->setText(p)
 
269
                #define setRowPerms(r, p) tw->item((r), 2)->setText(p)
 
270
                #define setRowFlags(r, f) tw->item((r), 3)->setText(f)
 
271
 
 
272
                void updateType();
 
273
                void updatePerms();
 
274
                void updateFlags();
 
275
                void updateCheckBoxesWithMask(QButtonGroup *bg, unsigned int mask);
 
276
                void syncWho(struct nfs4_ace *ace, const char *who);
 
277
 
 
278
                void move(int by);
 
279
 
 
280
                void doHighlight(int willDo);
 
281
                void activationChange(QEvent *e);
 
282
                //void changeEvent(QEvent *e);
 
283
 
 
284
        protected slots:
 
285
                void typeModified(int index);
 
286
                void principalModified(const QString &);
 
287
                void permsModified(QAbstractButton *a);
 
288
                void shortcutsModified(QAbstractButton *a);
 
289
                void flagsModified(QAbstractButton *a);
 
290
                void aceSelected(int row, int column, int prevrow, int prevcolumn);
 
291
                void aceMoved(int logical, int oldind, int newind);
 
292
                void moveUp();
 
293
                void moveDown();
 
294
                void getACL();
 
295
                void reloadACL();
 
296
                void newACE();
 
297
                void deleteACE();
 
298
                void setACL();
 
299
                void quit();
 
300
};
 
301
 
 
302
#endif