1
/* Copyright (c) 2006 The Regents of the University of Michigan.
4
* David M. Richter <richterd@citi.umich.edu>
5
* Alexis Mackenzie <allamack@citi.umich.edu>
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
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.
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.
33
#ifndef NFS4_ACL_EDITOR_H
34
#define NFS4_ACL_EDITOR_H 1
38
#include "libacl_nfs4.h"
41
#include <QApplication>
42
#include <QMainWindow>
43
#include <QVBoxLayout>
44
#include <QButtonGroup>
47
#include <QPushButton>
48
#include <QRadioButton>
50
#include <QApplication>
51
#include <QtCore/qlist.h>
52
#include <QTableWidget>
53
#include <QTableWidgetItem>
54
#include <QGridLayout>
55
#include <QStringList>
56
#include <QHeaderView>
64
#include <QKeySequence>
65
#include <QFileDialog>
67
#include <QListWidget>
68
#include <QStringList>
72
#include <QStackedWidget>
75
#include "dirfiledialog.h"
79
#define dprintf(format, args...) printf(format, ## args)
81
#define dprintf(format, args...)
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
92
typedef QList<QAbstractButton *> ButtonList;
93
typedef QList<struct nfs4_ace*> NFS4_ACL;
94
typedef QListIterator<struct nfs4_ace*> NFS4_ACL_Iterator;
96
static void nfs4_acl_to_NFS4_ACL(nfs4_acl *acl, NFS4_ACL *newacl)
98
struct nfs4_ace *ace = nfs4_get_first_ace(acl);
100
while (ace != NULL) {
102
ace = nfs4_get_next_ace(&ace);
106
struct __access_info {
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"},
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"},
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
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", ""},
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"},
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"},
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
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
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
200
class NFS4_ACL_Editor : public QMainWindow
205
NFS4_ACL_Editor(QWidget *parent, char *filearg);
206
void keyPressEvent(QKeyEvent *e);
207
void keyReleaseEvent(QKeyEvent *e);
214
QListWidgetItem *lwi;
216
QTableWidgetItem *twi;
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;
226
QPalette normal, light;
229
QVBoxLayout *vbl, *tbl, *fbl;
231
QGridLayout *gl, *dgl, *fgl, *sgl;
232
QButtonGroup *pbg, *dpbg, *fpbg, *sbg, *dsbg, *fsbg, *fbg, *tbg;
236
QString uis, gis, eis;
237
QString uils, gils, eils;
238
QString filename, formattedfilename;
240
struct nfs4_acl *nacl;
241
struct nfs4_ace *ace, *selectedACE;
244
int selectedACEIndex, selectedLogical, selectedVisual, deleting;
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);
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)
275
void updateCheckBoxesWithMask(QButtonGroup *bg, unsigned int mask);
276
void syncWho(struct nfs4_ace *ace, const char *who);
280
void doHighlight(int willDo);
281
void activationChange(QEvent *e);
282
//void changeEvent(QEvent *e);
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);