~apparmor-dev/apparmor/apparmor-ubuntu-citrain-trusty

« back to all changes in this revision

Viewing changes to parser/lib.c

  • Committer: Seth Arnold
  • Date: 2014-03-12 02:05:16 UTC
  • mto: This revision was merged to the branch mainline in revision 1496.
  • Revision ID: seth.arnold@canonical.com-20140312020516-zjike3pmw6hi861h
[ Jamie Strandboge ]
 * debian/debhelper/dh_apparmor: exit with error if aa-easyprof does not
   exist
 * debian/control: drop Depends on apparmor-easyprof to Suggests for
   dh-apparmor
[ Seth Arnold, Jamie Strandboge, Steve Beattie, John Johansen, Tyler Hicks ]
* New upstream snapshot (LP: #1278702, #1061693, #1285653) dropping very
  large Ubuntu delta and fixing the following bugs:
  - Adjust fonts abstraction for libthai (LP: #1278702)
  - Support translated XDG user directories (LP: #1061693)
  - Adjust abstractions/web-data to include /var/www/html (LP: #1285653)
    Refresh 0002-add-debian-integration-to-lighttpd.patch to include
    /etc/lighttpd/conf-available/*.conf
  - Adjust debian/libapparmor1.symbols to reflect new upstream versioning
    for the aa_query_label() function
  - Raise exceptions in Python bindings when something fails
* ship new Python replacements for previous Perl-based tools
  - debian/apparmor-utils.install: remove usr/share/perl5/Immunix/*.pm and add
    usr/sbin/aa-autodep, usr/sbin/aa-cleanprof and usr/sbin/aa-mergeprof
  - debian/control:
    + remove various Perl dependencies
    + add python-apparmor and python3-apparmor
    + python3-apparmor Breaks: apparmor-easyprof to move the file since it
      ships dist-packages/apparmor/__init__.py now
  - debian/apparmor-utils.manpages: ship new manpages for aa-cleanprof and
    aa-mergeprof
  - debian/rules: build and install Python tools
* debian/apparmor.install:
  - install apparmorfs, dovecot, kernelvars, securityfs, sys,
    and xdg-user-dirs tunables and xdg-user-dirs.d directory
* debian/apparmor.dirs:
  - install /etc/apparmor.d/tunables/xdg-user-dirs.d
* debian/apparmor.postinst: create xdg-user-dirs.d
* debian/apparmor.postrm: remove xdg-user-dirs.d
* Remaining patches:
  - 0001-add-chromium-browser.patch
  - 0002-add-debian-integration-to-lighttpd.patch
  - 0003-ubuntu-manpage-updates.patch
  - 0004-libapparmor-layout-deb.patch (renamed from 0008)
  - 0005-libapparmor-mention-dbus-method-in-getcon-man.patch (renamed from
    0068)
  - 0006-etc-writable.patch (renamed from 0070)
  - 0007-aa-utils_are_bilingual.patch (renamed from 0077)
  - 0008-remove-ptrace.patch
  - 0009-convert-to-rules.patch
  - 0010-list-fns.patch
  - 0011-parse-mode.patch
  - 0012-add-decimal-interp.patch
  - 0013-policy_mediates.patch
  - 0014-fix-failpath.patch
  - 0015-feature_file.patch
  - 0016-fix-network.patch
  - 0017-aare-to-class.patch
  - 0018-add-mediation-unix.patch
  - 0019-parser_version.patch
  - 0020-caching.patch
  - 0021-label-class.patch
  - 0022-signal.patch
  - 0023-fix-lexer-debug.patch
  - 0024-ptrace.patch
  - 0025-use-diff-encode.patch
  - 0026-fix-serialize.patch
  - 0027-fix-af.patch
  - 0028-opt_arg.patch
  - 0029-tests-cond-dbus.patch
  - 0030-tests.diff
* Move manpages from libapparmor1 to libapparmor-dev
  - debian/libapparmor-dev.manpages: install aa_change_hat.2,
    aa_change_profile.2, aa_find_mountpoint.2, aa_getcon.2
  - debian/control: libapparmor-dev Replaces: and Breaks: libapparmor1
* Move /usr/lib/python3/dist-packages/apparmor/__init__.py from
  apparmor-easyprof to python3-apparmor
  - debian/control: python3-apparmor Breaks: apparmor-easyprof
  - debian/apparmor-easyprof.install: remove
    usr/lib/python*.*/site-packages/apparmor*
* New profiles and abstractions:
  - debian/apparmor.install: tunables/dovecot, tunables/kernelvars,
    tunables/xdg-user-dirs, tunables/xdg-user-dirs.d
* Test merge from upstream new pyutils branch (rev 2385)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (c) 2012
 
3
 *   Canonical Ltd. (All rights reserved)
 
4
 *
 
5
 *   This program is free software; you can redistribute it and/or
 
6
 *   modify it under the terms of version 2 of the GNU General Public
 
7
 *   License published by the Free Software Foundation.
 
8
 *
 
9
 *   This program is distributed in the hope that it will be useful,
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *   GNU General Public License for more details.
 
13
 *
 
14
 *   You should have received a copy of the GNU General Public License
 
15
 *   along with this program; if not, contact Novell, Inc. or Canonical,
 
16
 *   Ltd.
 
17
 */
 
18
 
 
19
#include <dirent.h>
 
20
#include <errno.h>
 
21
#include <fcntl.h>
 
22
#include <stdio.h>
 
23
#include <string.h>
 
24
#include <stddef.h>
 
25
#include <stdlib.h>
 
26
#include <unistd.h>
 
27
#define _(s) gettext(s)
 
28
 
 
29
#include <sys/stat.h>
 
30
#include <sys/types.h>
 
31
 
 
32
#include "parser.h"
 
33
 
 
34
/**
 
35
 * dirat_for_each: iterate over a directory calling cb for each entry
 
36
 * @dir: already opened directory (MAY BE NULL)
 
37
 * @name: name of the directory (MAY BE NULL)
 
38
 * @data: data pointer to pass to the callback fn (MAY BE NULL)
 
39
 * @cb: the callback to pass entry too (NOT NULL)
 
40
 *
 
41
 * Iterate over the entries in a directory calling cb for each entry.
 
42
 * The directory to iterate is determined by a combination of @dir and
 
43
 * @name.
 
44
 *
 
45
 * IF @name is a relative path it is determine relative to at @dir if it
 
46
 * is specified, else it the lookup is done relative to the current
 
47
 * working directory.
 
48
 *
 
49
 * If @name is not specified then @dir is used as the directory to iterate
 
50
 * over.
 
51
 *
 
52
 * It is an error if both @name and @dir are null
 
53
 *
 
54
 * The cb function is called with the DIR in use and the name of the
 
55
 * file in that directory.  If the file is to be opened it should
 
56
 * use the openat, fstatat, and related fns.
 
57
 *
 
58
 * Returns: 0 on success, else -1 and errno is set to the error code
 
59
 */
 
60
int dirat_for_each(DIR *dir, const char *name, void *data,
 
61
                   int (* cb)(DIR *, const char *, struct stat *, void *))
 
62
{
 
63
        struct dirent *dirent = NULL, *ent;
 
64
        DIR *d = NULL;
 
65
        int error = 0;
 
66
 
 
67
        if (!cb || (!dir && !name)) {
 
68
                errno = EINVAL;
 
69
                return -1;
 
70
        }
 
71
 
 
72
        if (dir && (!name || *name != '/')) {
 
73
                dirent = (struct dirent *)
 
74
                        malloc(offsetof(struct dirent, d_name) +
 
75
                               fpathconf(dirfd(dir), _PC_NAME_MAX) + 1);
 
76
        } else {
 
77
                dirent = (struct dirent *)
 
78
                        malloc(offsetof(struct dirent, d_name) +
 
79
                               pathconf(name, _PC_NAME_MAX) + 1);
 
80
        }
 
81
        if (!dirent) {
 
82
                PDEBUG("could not alloc dirent");
 
83
                return -1;
 
84
        }
 
85
 
 
86
        if (name) {
 
87
                if (dir && *name != '/') {
 
88
                        int fd = openat(dirfd(dir), name, O_RDONLY);
 
89
                        if (fd == -1)
 
90
                                goto fail;
 
91
                        d = fdopendir(fd);
 
92
                } else {
 
93
                        d = opendir(name);
 
94
                }
 
95
                PDEBUG("Open dir '%s': %s\n", name, d ? "succeeded" : "failed");
 
96
                if (!(d))
 
97
                        goto fail;
 
98
        } else { /* dir && !name */
 
99
                PDEBUG("Recieved cache directory\n");
 
100
                d = dir;
 
101
        }
 
102
 
 
103
        for (error = readdir_r(d, dirent, &ent);
 
104
             error == 0 && ent != NULL;
 
105
             error = readdir_r(d, dirent, &ent)) {
 
106
                struct stat my_stat;
 
107
 
 
108
                if (strcmp(ent->d_name, ".") == 0 ||
 
109
                    strcmp(ent->d_name, "..") == 0)
 
110
                        continue;
 
111
 
 
112
                if (fstatat(dirfd(d), ent->d_name, &my_stat, 0)) {
 
113
                        PDEBUG("stat failed for '%s'", name);
 
114
                        goto fail;
 
115
                }
 
116
 
 
117
                if (cb(d, ent->d_name, &my_stat, data)) {
 
118
                        PDEBUG("dir_for_each callback failed\n");
 
119
                        goto fail;
 
120
                }
 
121
        }
 
122
 
 
123
        if (d != dir)
 
124
                closedir(d);
 
125
        free(dirent);
 
126
 
 
127
        return error;
 
128
 
 
129
fail:
 
130
        error = errno;
 
131
        if (d && d != dir)
 
132
                closedir(d);
 
133
        free(dirent);
 
134
        errno = error;
 
135
 
 
136
        return -1;
 
137
}