16
16
* Authored by: Ken VanDine <ken.vandine@canonical.com>
19
#include <QCoreApplication>
20
25
#include <QtDBus/QDBusMessage>
21
26
#include <QtDBus/QDBusConnection>
26
28
#include <nih/alloc.h>
27
29
#include <nih-dbus/dbus_util.h>
31
33
#include "com/ubuntu/content/type.h"
32
34
#include <unistd.h>
36
#include <sys/apparmor.h>
37
/* need to be exposed in libapparmor but for now ... */
38
#define AA_CLASS_FILE 2
39
#define AA_MAY_READ (1 << 2)
34
41
namespace cuc = com::ubuntu::content;
181
int query_file(const char *label, const char *path, int *allowed)
186
/* + 1 for null separator and then + 1 AA_CLASS_FILE */
187
int label_size = strlen(label);
188
int size = label_size + 1 + strlen(path) + AA_QUERY_CMD_LABEL_SIZE + 1;
189
/* +1 for null terminator used by strcpy, yes we could drop this
191
query = (char*)malloc(size + 1);
194
/* we want the null terminator here */
195
strcpy(query + AA_QUERY_CMD_LABEL_SIZE, label);
196
query[AA_QUERY_CMD_LABEL_SIZE + label_size + 1] = AA_CLASS_FILE;
197
strcpy(query + AA_QUERY_CMD_LABEL_SIZE + label_size + 2, path);
198
rc = aa_query_label(AA_MAY_READ, query, size , allowed, &audited);
203
bool check_profile_read(QString profile, QString path)
205
TRACE() << Q_FUNC_INFO << "PROFILE:" << profile;
208
if (query_file(profile.toStdString().c_str(), path.toStdString().c_str(), &allowed) == -1) {
209
qWarning() << "error:" << strerror(errno) << path;
214
TRACE() << "ALLOWED:" << QString::number(allowed);
217
TRACE() << "NOT ALLOWED:" << QString::number(allowed);