~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to changehat/mod_apparmor/mod_apparmor.c

  • Committer: Package Import Robot
  • Author(s): Jamie Strandboge
  • Date: 2014-09-08 16:13:10 UTC
  • mto: This revision was merged to the branch mainline in revision 76.
  • Revision ID: package-import@ubuntu.com-20140908161310-zf42uss925jnp56t
Tags: upstream-2.8.96~2652
ImportĀ upstreamĀ versionĀ 2.8.96~2652

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *   Copyright (c) 2004, 2005, 2006 NOVELL (All rights reserved)
 
3
 *   Copyright (c) 2014 Canonical, Ltd. (All rights reserved)
3
4
 *
4
5
 *    The mod_apparmor module is licensed under the terms of the GNU
5
6
 *    Lesser General Public License, version 2.1. Please see the file
6
7
 *    COPYING.LGPL.
7
8
 *
8
9
 * mod_apparmor - (apache 2.0.x)
9
 
 * Author: Steve Beattie <sbeattie@suse.de>
 
10
 * Author: Steve Beattie <steve@nxnw.org>
10
11
 *
11
12
 * This currently only implements change_hat functionality, but could be
12
13
 * extended for other stuff we decide to do.
51
52
static int inside_default_hat = 0;
52
53
 
53
54
typedef struct {
54
 
        const char * hat_name;
55
 
        char * path;
56
 
} immunix_dir_cfg;
 
55
        const char *hat_name;
 
56
        char *path;
 
57
} apparmor_dir_cfg;
57
58
 
58
59
typedef struct {
59
 
        const char * hat_name;
60
 
        int is_initialized;
61
 
} immunix_srv_cfg;
 
60
        const char *hat_name;
 
61
        int is_initialized;
 
62
} apparmor_srv_cfg;
62
63
 
63
 
/* immunix_init() gets invoked in the post_config stage of apache.
 
64
/* aa_init() gets invoked in the post_config stage of apache.
64
65
 * Unfortunately, apache reads its config once when it starts up, then
65
66
 * it re-reads it when goes into its restart loop, where it starts it's
66
67
 * children. This means we cannot call change_hat here, as the modules
67
68
 * memory will be wiped out, and the magic_token will be lost, so apache
68
69
 * wouldn't be able to change_hat back out. */
69
 
static int 
70
 
immunix_init (apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
 
70
static int
 
71
aa_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
71
72
{
72
 
    apr_file_t * file;
73
 
    apr_size_t size = sizeof (magic_token);
 
73
    apr_file_t *file;
 
74
    apr_size_t size = sizeof(magic_token);
74
75
    int ret;
75
76
 
76
77
    ret = apr_file_open (&file, "/dev/urandom", APR_READ, APR_OS_DEFAULT, p);
77
78
    if (!ret) {
78
 
        apr_file_read (file, (void *) &magic_token, &size);
79
 
        apr_file_close (file);
 
79
        apr_file_read(file, (void *) &magic_token, &size);
 
80
        apr_file_close(file);
80
81
    } else {
81
82
        ap_log_error(APLOG_MARK, APLOG_ERR, errno, ap_server_conf,
82
 
                        "Failed to open /dev/urandom");
 
83
                     "Failed to open /dev/urandom");
83
84
    }
84
 
    ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, ap_server_conf, "Opened /dev/urandom successfully");
 
85
    ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, ap_server_conf,
 
86
                 "Opened /dev/urandom successfully");
85
87
 
86
88
    return OK;
87
89
}
88
 
    
 
90
 
89
91
/* As each child starts up, we'll change_hat into a default hat, mostly
90
92
 * to protect ourselves from bugs in parsing network input, but before
91
93
 * we change_hat to the uri specific hat. */
92
 
static void 
93
 
immunix_child_init (apr_pool_t *p, server_rec *s)
 
94
static void
 
95
aa_child_init(apr_pool_t *p, server_rec *s)
94
96
{
95
97
    int ret;
96
98
 
97
99
    ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, ap_server_conf,
98
 
                    "init: calling change_hat with '%s'", DEFAULT_HAT);
 
100
                 "init: calling change_hat with '%s'", DEFAULT_HAT);
99
101
    ret = aa_change_hat(DEFAULT_HAT, magic_token);
100
102
    if (ret < 0) {
101
103
        ap_log_error(APLOG_MARK, APLOG_ERR, errno, ap_server_conf,
102
 
                        "Failed to change_hat to '%s'", DEFAULT_HAT);
 
104
                     "Failed to change_hat to '%s'", DEFAULT_HAT);
103
105
    } else {
104
106
        inside_default_hat = 1;
105
107
    }
106
 
}                        
 
108
}
107
109
 
108
110
static void
109
111
debug_dump_uri(request_rec *r)
110
112
{
111
113
    apr_uri_t *uri = &r->parsed_uri;
112
114
    if (uri)
113
 
        ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "Dumping uri info "
114
 
                  "scheme='%s' host='%s' path='%s' query='%s' fragment='%s'",
115
 
                  uri->scheme, uri->hostname, uri->path, uri->query,
116
 
                  uri->fragment);
 
115
        ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "Dumping uri info "
 
116
                      "scheme='%s' host='%s' path='%s' query='%s' fragment='%s'",
 
117
                      uri->scheme, uri->hostname, uri->path, uri->query,
 
118
                      uri->fragment);
117
119
    else
118
 
        ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "Asked to dump NULL uri");
 
120
        ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "Asked to dump NULL uri");
119
121
 
120
122
}
121
123
 
122
 
/* 
123
 
   immunix_enter_hat will attempt to change_hat in the following order:
 
124
/*
 
125
   aa_enter_hat will attempt to change_hat in the following order:
124
126
   (1) to a hatname in a location directive
125
 
   (2) to the uri
126
 
   (3) to a per-server default 
127
 
   (4) to DEFAULT_URI
128
 
   (5) back to the parent profile
 
127
   (2) to the server name or a defined per-server default
 
128
   (3) to the server name + "-" + uri
 
129
   (4) to the uri
 
130
   (5) to DEFAULT_URI
 
131
   (6) back to the parent profile
129
132
*/
130
 
static int 
131
 
immunix_enter_hat (request_rec *r)
 
133
static int
 
134
aa_enter_hat(request_rec *r)
132
135
{
133
 
    int sd_ret = -1;
134
 
    immunix_dir_cfg * dcfg = (immunix_dir_cfg *) 
135
 
                ap_get_module_config (r->per_dir_config, &apparmor_module);
136
 
    immunix_srv_cfg * scfg = (immunix_srv_cfg *) 
137
 
                ap_get_module_config (r->server->module_config, &apparmor_module);
138
 
    const char *aa_hat_array[5] = { NULL, NULL, NULL, NULL, NULL };
 
136
    int aa_ret = -1;
 
137
    apparmor_dir_cfg *dcfg = (apparmor_dir_cfg *)
 
138
                    ap_get_module_config(r->per_dir_config, &apparmor_module);
 
139
    apparmor_srv_cfg *scfg = (apparmor_srv_cfg *)
 
140
                    ap_get_module_config(r->server->module_config, &apparmor_module);
 
141
    const char *aa_hat_array[6] = { NULL, NULL, NULL, NULL, NULL, NULL };
139
142
    int i = 0;
140
143
    char *aa_con, *aa_mode, *aa_hat;
 
144
    const char *vhost_uri;
141
145
 
142
146
    debug_dump_uri(r);
143
 
    ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "in immunix_enter_hat (%s) n:0x%lx p:0x%lx main:0x%lx",
144
 
        dcfg->path, (unsigned long) r->next, (unsigned long) r->prev, 
145
 
        (unsigned long) r->main);
 
147
    ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "aa_enter_hat (%s) n:0x%lx p:0x%lx main:0x%lx",
 
148
                  dcfg->path, (unsigned long) r->next, (unsigned long) r->prev,
 
149
                  (unsigned long) r->main);
146
150
 
147
151
    /* We only call change_hat for the main request, not subrequests */
148
 
    if (r->main) 
149
 
        return OK;
 
152
    if (r->main)
 
153
        return OK;
150
154
 
151
155
    if (inside_default_hat) {
152
156
        aa_change_hat(NULL, magic_token);
153
 
        inside_default_hat = 0;
 
157
        inside_default_hat = 0;
154
158
    }
155
159
 
156
160
    if (dcfg != NULL && dcfg->hat_name != NULL) {
157
161
        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
158
 
                        "[dcfg] adding hat '%s' to aa_change_hat vector", dcfg->hat_name);
 
162
                      "[dcfg] adding hat '%s' to aa_change_hat vector", dcfg->hat_name);
159
163
        aa_hat_array[i++] = dcfg->hat_name;
160
164
    }
161
165
 
162
 
    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
163
 
                    "[uri] adding uri '%s' to aa_change_hat vector", r->uri);
164
 
    aa_hat_array[i++] = r->uri;
165
 
 
166
166
    if (scfg) {
167
 
        ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "Dumping scfg info: "
168
 
                  "scfg='0x%lx' scfg->hat_name='%s'",
169
 
                  (unsigned long) scfg, scfg->hat_name);
 
167
        ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "Dumping scfg info: "
 
168
                      "scfg='0x%lx' scfg->hat_name='%s'",
 
169
                      (unsigned long) scfg, scfg->hat_name);
170
170
    } else {
171
 
        ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "scfg is null");
 
171
        ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "scfg is null");
172
172
    }
173
173
    if (scfg != NULL) {
174
 
        if (scfg->hat_name != NULL) {
 
174
        if (scfg->hat_name != NULL) {
175
175
            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
176
 
                            "[scfg] adding hat '%s' to aa_change_hat vector", scfg->hat_name);
 
176
                          "[scfg] adding hat '%s' to aa_change_hat vector", scfg->hat_name);
177
177
            aa_hat_array[i++] = scfg->hat_name;
178
178
        } else {
179
179
            ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
180
 
                            "[scfg] adding server_name '%s' to aa_change_hat vector",
181
 
                            r->server->server_hostname);
 
180
                          "[scfg] adding server_name '%s' to aa_change_hat vector",
 
181
                          r->server->server_hostname);
182
182
            aa_hat_array[i++] = r->server->server_hostname;
183
 
        }
 
183
        }
 
184
 
 
185
        vhost_uri = apr_pstrcat(r->pool, r->server->server_hostname, "-", r->uri, NULL);
 
186
        ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
 
187
                      "[vhost+uri] adding vhost+uri '%s' to aa_change_hat vector", vhost_uri);
 
188
        aa_hat_array[i++] = vhost_uri;
184
189
    }
185
190
 
186
191
    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
187
 
                    "[default] adding '%s' to aa_change_hat vector", DEFAULT_URI_HAT);
 
192
                  "[uri] adding uri '%s' to aa_change_hat vector", r->uri);
 
193
    aa_hat_array[i++] = r->uri;
 
194
 
 
195
    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
 
196
                  "[default] adding '%s' to aa_change_hat vector", DEFAULT_URI_HAT);
188
197
    aa_hat_array[i++] = DEFAULT_URI_HAT;
189
198
 
190
 
    sd_ret = aa_change_hatv(aa_hat_array, magic_token);
191
 
    if (sd_ret < 0) {
 
199
    aa_ret = aa_change_hatv(aa_hat_array, magic_token);
 
200
    if (aa_ret < 0) {
192
201
        ap_log_rerror(APLOG_MARK, APLOG_WARNING, errno, r, "aa_change_hatv call failed");
193
202
    }
194
203
 
195
204
    /* Check to see if a defined AAHatName or AADefaultHatName would
196
205
     * apply, but wasn't the hat we landed up in; report a warning if
197
206
     * that's the case. */
198
 
    sd_ret = aa_getcon(&aa_con, &aa_mode);
199
 
    if (sd_ret < 0) {
 
207
    aa_ret = aa_getcon(&aa_con, &aa_mode);
 
208
    if (aa_ret < 0) {
200
209
        ap_log_rerror(APLOG_MARK, APLOG_WARNING, errno, r, "aa_getcon call failed");
201
210
    } else {
202
 
        ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r,
203
 
                            "AA checks: aa_getcon result is '%s', mode '%s'", aa_con, aa_mode);
204
 
        /* TODO: use libapparmor get hat_name fn here once it is implemented */
205
 
        aa_hat = strstr(aa_con, "//");
206
 
        if (aa_hat != NULL && strcmp(aa_mode, "enforce") == 0) {
207
 
            aa_hat += 2;  /* skip "//" */
208
 
            ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r,
209
 
                            "AA checks: apache is in hat '%s', mode '%s'", aa_hat, aa_mode);
210
 
            if (dcfg != NULL && dcfg->hat_name != NULL) {
211
 
                if (strcmp(aa_hat, dcfg->hat_name) != 0)
212
 
                    ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
213
 
                        "AAHatName '%s' applies, but does not appear to be a hat in the apache apparmor policy",
214
 
                        dcfg->hat_name);
215
 
            } else if (scfg != NULL && scfg->hat_name != NULL) {
216
 
                if (strcmp(aa_hat, scfg->hat_name) != 0 &&
217
 
                    strcmp(aa_hat, r->uri) != 0)
218
 
                    ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
219
 
                        "AADefaultHatName '%s' applies, but does not appear to be a hat in the apache apparmor policy",
220
 
                        scfg->hat_name);
221
 
            }
222
 
        }
223
 
        free(aa_con);
 
211
        ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r,
 
212
                      "AA checks: aa_getcon result is '%s', mode '%s'", aa_con, aa_mode);
 
213
        /* TODO: use libapparmor get hat_name fn here once it is implemented */
 
214
        aa_hat = strstr(aa_con, "//");
 
215
        if (aa_hat != NULL && strcmp(aa_mode, "enforce") == 0) {
 
216
            aa_hat += 2;  /* skip "//" */
 
217
            ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r,
 
218
                          "AA checks: apache is in hat '%s', mode '%s'", aa_hat, aa_mode);
 
219
            if (dcfg != NULL && dcfg->hat_name != NULL) {
 
220
                if (strcmp(aa_hat, dcfg->hat_name) != 0)
 
221
                    ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
 
222
                        "AAHatName '%s' applies, but does not appear to be a hat in the apache apparmor policy",
 
223
                        dcfg->hat_name);
 
224
            } else if (scfg != NULL && scfg->hat_name != NULL) {
 
225
                if (strcmp(aa_hat, scfg->hat_name) != 0 &&
 
226
                    strcmp(aa_hat, r->uri) != 0)
 
227
                    ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r,
 
228
                        "AADefaultHatName '%s' applies, but does not appear to be a hat in the apache apparmor policy",
 
229
                        scfg->hat_name);
 
230
            }
 
231
        }
 
232
        free(aa_con);
224
233
    }
225
234
 
226
235
    return OK;
227
236
}
228
237
 
229
 
static int 
230
 
immunix_exit_hat (request_rec *r)
 
238
static int
 
239
aa_exit_hat(request_rec *r)
231
240
{
232
 
    int sd_ret;
233
 
    immunix_dir_cfg * dcfg = (immunix_dir_cfg *) 
234
 
                ap_get_module_config (r->per_dir_config, &apparmor_module);
235
 
    /* immunix_srv_cfg * scfg = (immunix_srv_cfg *)
236
 
                ap_get_module_config (r->server->module_config, &apparmor_module); */
 
241
    int aa_ret;
 
242
    apparmor_dir_cfg *dcfg = (apparmor_dir_cfg *)
 
243
                    ap_get_module_config(r->per_dir_config, &apparmor_module);
 
244
    /* apparmor_srv_cfg *scfg = (apparmor_srv_cfg *)
 
245
                    ap_get_module_config(r->server->module_config, &apparmor_module); */
237
246
    ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, "exiting change_hat: dir hat %s dir path %s",
238
 
                    dcfg->hat_name, dcfg->path);
 
247
                  dcfg->hat_name, dcfg->path);
239
248
 
240
249
    /* can convert the following back to aa_change_hat() when the
241
250
     * aa_change_hat() bug addressed in trunk commit 2329 lands in most
242
251
     * system libapparmors */
243
252
    aa_change_hatv(NULL, magic_token);
244
253
 
245
 
    sd_ret = aa_change_hat(DEFAULT_HAT, magic_token);
246
 
    if (sd_ret < 0) {
 
254
    aa_ret = aa_change_hat(DEFAULT_HAT, magic_token);
 
255
    if (aa_ret < 0) {
247
256
        ap_log_rerror(APLOG_MARK, APLOG_ERR, errno, r,
248
 
                        "Failed to change_hat to '%s'", DEFAULT_HAT);
 
257
                      "Failed to change_hat to '%s'", DEFAULT_HAT);
249
258
    } else {
250
259
        inside_default_hat = 1;
251
260
    }
254
263
}
255
264
 
256
265
static const char *
257
 
aa_cmd_ch_path (cmd_parms * cmd, void * mconfig, const char * parm1)
 
266
aa_cmd_ch_path(cmd_parms *cmd, void *mconfig, const char *parm1)
258
267
{
259
268
    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, "directory config change hat %s",
260
 
                        parm1 ? parm1 : "DEFAULT");
261
 
    immunix_dir_cfg * dcfg = mconfig;
 
269
                 parm1 ? parm1 : "DEFAULT");
 
270
    apparmor_dir_cfg *dcfg = mconfig;
262
271
    if (parm1 != NULL) {
263
 
        dcfg->hat_name = parm1;
 
272
        dcfg->hat_name = parm1;
264
273
    } else {
265
 
        dcfg->hat_name = "DEFAULT";
 
274
        dcfg->hat_name = "DEFAULT";
266
275
    }
267
276
    return NULL;
268
277
}
270
279
static int path_warn_once;
271
280
 
272
281
static const char *
273
 
immunix_cmd_ch_path (cmd_parms * cmd, void * mconfig, const char * parm1)
 
282
immunix_cmd_ch_path(cmd_parms *cmd, void *mconfig, const char *parm1)
274
283
{
275
284
    if (path_warn_once == 0) {
276
 
        ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf, "ImmHatName is "
277
 
                     "deprecated, please use AAHatName instead");
278
 
        path_warn_once = 1;
 
285
        ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf, "ImmHatName is "
 
286
                     "deprecated, please use AAHatName instead");
 
287
        path_warn_once = 1;
279
288
    }
280
289
    return aa_cmd_ch_path(cmd, mconfig, parm1);
281
290
}
282
291
 
283
292
static const char *
284
 
aa_cmd_ch_srv (cmd_parms * cmd, void * mconfig, const char * parm1)
 
293
aa_cmd_ch_srv(cmd_parms *cmd, void *mconfig, const char *parm1)
285
294
{
286
295
    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, "server config change hat %s",
287
 
                        parm1 ? parm1 : "DEFAULT");
288
 
    immunix_srv_cfg * scfg = (immunix_srv_cfg *)
289
 
            ap_get_module_config(cmd->server->module_config, &apparmor_module);
 
296
                            parm1 ? parm1 : "DEFAULT");
 
297
    apparmor_srv_cfg *scfg = (apparmor_srv_cfg *)
 
298
            ap_get_module_config(cmd->server->module_config, &apparmor_module);
290
299
    if (parm1 != NULL) {
291
 
        scfg->hat_name = parm1;
 
300
        scfg->hat_name = parm1;
292
301
    } else {
293
 
        scfg->hat_name = "DEFAULT";
 
302
        scfg->hat_name = "DEFAULT";
294
303
    }
295
304
    return NULL;
296
305
}
298
307
static int srv_warn_once;
299
308
 
300
309
static const char *
301
 
immunix_cmd_ch_srv (cmd_parms * cmd, void * mconfig, const char * parm1)
 
310
immunix_cmd_ch_srv(cmd_parms *cmd, void *mconfig, const char *parm1)
302
311
{
303
312
    if (srv_warn_once == 0) {
304
 
        ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf, "ImmDefaultHatName is "
305
 
                     "deprecated, please use AADefaultHatName instead");
306
 
        srv_warn_once = 1;
 
313
        ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf, "ImmDefaultHatName is "
 
314
                     "deprecated, please use AADefaultHatName instead");
 
315
        srv_warn_once = 1;
307
316
    }
308
317
    return aa_cmd_ch_srv(cmd, mconfig, parm1);
309
318
}
310
319
 
311
320
static void *
312
 
immunix_create_dir_config (apr_pool_t * p, char * path)
 
321
aa_create_dir_config(apr_pool_t *p, char *path)
313
322
{
314
 
    immunix_dir_cfg * newcfg = (immunix_dir_cfg *) apr_pcalloc(p, sizeof(* newcfg));
 
323
    apparmor_dir_cfg *newcfg = (apparmor_dir_cfg *) apr_pcalloc(p, sizeof(*newcfg));
315
324
 
316
 
    ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, ap_server_conf, "in immunix_create_dir (%s)", path ? path : ":no path:");
 
325
    ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, ap_server_conf,
 
326
                 "aa_create_dir_cfg (%s)", path ? path : ":no path:");
317
327
    if (newcfg == NULL) {
318
 
        ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, "immunix_create_dir: couldn't alloc dir config");
319
 
        return NULL;
 
328
        ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf,
 
329
                     "aa_create_dir_config: couldn't alloc dir config");
 
330
        return NULL;
320
331
    }
321
 
    newcfg->path = apr_pstrdup (p, path ? path : ":no path:");
 
332
    newcfg->path = apr_pstrdup(p, path ? path : ":no path:");
322
333
 
323
334
    return newcfg;
324
335
}
326
337
/* XXX: Should figure out an appropriate action to take here, if any
327
338
 
328
339
static void *
329
 
immunix_merge_dir_config (apr_pool_t * p, void * parent, void * child)
 
340
aa_merge_dir_config(apr_pool_t *p, void *parent, void *child)
330
341
{
331
 
    immunix_dir_cfg * newcfg = (immunix_dir_cfg *) apr_pcalloc(p, sizeof(* newcfg));
 
342
    apparmor_dir_cfg *newcfg = (apparmor_dir_cfg *) apr_pcalloc(p, sizeof(*newcfg));
332
343
 
333
344
    ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, ap_server_conf, "in immunix_merge_dir ()");
334
345
    if (newcfg == NULL)
335
 
        return NULL;
 
346
            return NULL;
336
347
 
337
348
    return newcfg;
338
349
}
339
350
*/
340
351
 
341
352
static void *
342
 
immunix_create_srv_config (apr_pool_t * p, server_rec * srv)
 
353
aa_create_srv_config(apr_pool_t *p, server_rec *srv)
343
354
{
344
 
    immunix_srv_cfg * newcfg = (immunix_srv_cfg *) apr_pcalloc(p, sizeof(* newcfg));
 
355
    apparmor_srv_cfg *newcfg = (apparmor_srv_cfg *) apr_pcalloc(p, sizeof(*newcfg));
345
356
 
346
 
    ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, ap_server_conf, "in immunix_create_srv");
 
357
    ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, ap_server_conf,
 
358
                 "in aa_create_srv_config");
347
359
    if (newcfg == NULL) {
348
 
        ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf, "immunix_create_srv: couldn't alloc srv config");
349
 
        return NULL;
 
360
        ap_log_error(APLOG_MARK, APLOG_ERR, 0, ap_server_conf,
 
361
                     "aa_create_srv_config: couldn't alloc srv config");
 
362
        return NULL;
350
363
    }
351
364
 
352
365
    return newcfg;
353
366
}
354
367
 
355
368
 
356
 
static const command_rec immunix_cmds[] = {
 
369
static const command_rec mod_apparmor_cmds[] = {
357
370
 
358
 
    AP_INIT_TAKE1 (
 
371
    AP_INIT_TAKE1(
359
372
        "ImmHatName",
360
 
        immunix_cmd_ch_path,
361
 
        NULL,
362
 
        ACCESS_CONF,
363
 
        ""
 
373
        immunix_cmd_ch_path,
 
374
        NULL,
 
375
        ACCESS_CONF,
 
376
        ""
364
377
    ),
365
 
    AP_INIT_TAKE1 (
 
378
    AP_INIT_TAKE1(
366
379
        "ImmDefaultHatName",
367
 
        immunix_cmd_ch_srv,
368
 
        NULL,
369
 
        RSRC_CONF,
370
 
        ""
 
380
        immunix_cmd_ch_srv,
 
381
        NULL,
 
382
        RSRC_CONF,
 
383
        ""
371
384
    ),
372
 
    AP_INIT_TAKE1 (
 
385
    AP_INIT_TAKE1(
373
386
        "AAHatName",
374
 
        aa_cmd_ch_path,
375
 
        NULL,
376
 
        ACCESS_CONF,
377
 
        ""
 
387
        aa_cmd_ch_path,
 
388
        NULL,
 
389
        ACCESS_CONF,
 
390
        ""
378
391
    ),
379
 
    AP_INIT_TAKE1 (
 
392
    AP_INIT_TAKE1(
380
393
        "AADefaultHatName",
381
 
        aa_cmd_ch_srv,
382
 
        NULL,
383
 
        RSRC_CONF,
384
 
        ""
 
394
        aa_cmd_ch_srv,
 
395
        NULL,
 
396
        RSRC_CONF,
 
397
        ""
385
398
    ),
386
399
    { NULL }
387
400
};
388
401
 
389
 
static void 
390
 
register_hooks (apr_pool_t *p)
 
402
static void
 
403
register_hooks(apr_pool_t *p)
391
404
{
392
 
    ap_hook_post_config (immunix_init, NULL, NULL, APR_HOOK_MIDDLE);
393
 
    ap_hook_child_init (immunix_child_init, NULL, NULL, APR_HOOK_MIDDLE);
394
 
    ap_hook_access_checker(immunix_enter_hat, NULL, NULL, APR_HOOK_FIRST);
395
 
    /* ap_hook_post_read_request(immunix_enter_hat, NULL, NULL, APR_HOOK_FIRST); */
396
 
    ap_hook_log_transaction(immunix_exit_hat, NULL, NULL, APR_HOOK_LAST);
 
405
    ap_hook_post_config(aa_init, NULL, NULL, APR_HOOK_MIDDLE);
 
406
    ap_hook_child_init(aa_child_init, NULL, NULL, APR_HOOK_MIDDLE);
 
407
 
 
408
#if AP_SERVER_MAJORVERSION_NUMBER == 2 && AP_SERVER_MINORVERSION_NUMBER < 3
 
409
    /* Compatibility with apache 2.2 */
 
410
    ap_hook_access_checker(aa_enter_hat, NULL, NULL, APR_HOOK_FIRST);
 
411
#else
 
412
    /* apache 2.4 mod_authz hook */
 
413
    ap_hook_check_access_ex(aa_enter_hat, NULL, NULL, APR_HOOK_FIRST, AP_AUTH_INTERNAL_PER_CONF);
 
414
#endif
 
415
 
 
416
    /* ap_hook_post_read_request(aa_enter_hat, NULL, NULL, APR_HOOK_FIRST); */
 
417
    ap_hook_log_transaction(aa_exit_hat, NULL, NULL, APR_HOOK_LAST);
397
418
}
398
419
 
399
420
module AP_MODULE_DECLARE_DATA apparmor_module = {
400
421
    STANDARD20_MODULE_STUFF,
401
 
    immunix_create_dir_config,  /* dir config creater */
402
 
    NULL,                       /* dir merger --- default is to override */
403
 
    /* immunix_merge_dir_config, */     /* dir merger --- default is to override */
404
 
    immunix_create_srv_config,  /* server config */
405
 
    NULL,                       /* merge server config */
406
 
    immunix_cmds,               /* command table */
407
 
    register_hooks              /* register hooks */
 
422
    aa_create_dir_config,        /* dir config creater */
 
423
    NULL,                        /* dir merger --- default is to override */
 
424
    /* immunix_merge_dir_config, */        /* dir merger --- default is to override */
 
425
    aa_create_srv_config,        /* server config */
 
426
    NULL,                        /* merge server config */
 
427
    mod_apparmor_cmds,           /* command table */
 
428
    register_hooks               /* register hooks */
408
429
};