~lefteris-nikoltsios/+junk/samba-lp1016895

« back to all changes in this revision

Viewing changes to source3/utils/net_rpc_audit.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
#include "includes.h"
20
20
#include "utils/net.h"
21
 
#include "../librpc/gen_ndr/cli_lsa.h"
 
21
#include "rpc_client/rpc_client.h"
 
22
#include "../librpc/gen_ndr/ndr_lsa_c.h"
 
23
#include "rpc_client/cli_lsarpc.h"
22
24
 
23
25
/********************************************************************
24
26
********************************************************************/
55
57
********************************************************************/
56
58
 
57
59
static NTSTATUS rpc_audit_get_internal(struct net_context *c,
58
 
                                       const DOM_SID *domain_sid,
 
60
                                       const struct dom_sid *domain_sid,
59
61
                                       const char *domain_name,
60
62
                                       struct cli_state *cli,
61
63
                                       struct rpc_pipe_client *pipe_hnd,
64
66
                                       const char **argv)
65
67
{
66
68
        struct policy_handle pol;
67
 
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
 
69
        NTSTATUS status, result;
68
70
        union lsa_PolicyInformation *info = NULL;
69
71
        int i;
70
72
        uint32_t audit_category;
 
73
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
71
74
 
72
75
        if (argc < 1 || argc > 2) {
73
76
                d_printf(_("insufficient arguments\n"));
80
83
                return NT_STATUS_INVALID_PARAMETER;
81
84
        }
82
85
 
83
 
        result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
 
86
        status = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
84
87
                                        SEC_FLAG_MAXIMUM_ALLOWED,
85
88
                                        &pol);
86
89
 
87
 
        if (!NT_STATUS_IS_OK(result)) {
 
90
        if (!NT_STATUS_IS_OK(status)) {
88
91
                goto done;
89
92
        }
90
93
 
91
 
        result = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
 
94
        status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
92
95
                                            &pol,
93
96
                                            LSA_POLICY_INFO_AUDIT_EVENTS,
94
 
                                            &info);
95
 
 
 
97
                                            &info,
 
98
                                            &result);
 
99
        if (!NT_STATUS_IS_OK(status)) {
 
100
                goto done;
 
101
        }
96
102
        if (!NT_STATUS_IS_OK(result)) {
 
103
                status = result;
97
104
                goto done;
98
105
        }
99
106
 
111
118
        }
112
119
 
113
120
 done:
114
 
        if (!NT_STATUS_IS_OK(result)) {
 
121
        if (!NT_STATUS_IS_OK(status)) {
115
122
                d_printf(_("failed to get auditing policy: %s\n"),
116
 
                        nt_errstr(result));
 
123
                        nt_errstr(status));
117
124
        }
118
125
 
119
 
        return result;
 
126
        return status;
120
127
}
121
128
 
122
129
/********************************************************************
123
130
********************************************************************/
124
131
 
125
132
static NTSTATUS rpc_audit_set_internal(struct net_context *c,
126
 
                                       const DOM_SID *domain_sid,
 
133
                                       const struct dom_sid *domain_sid,
127
134
                                       const char *domain_name,
128
135
                                       struct cli_state *cli,
129
136
                                       struct rpc_pipe_client *pipe_hnd,
132
139
                                       const char **argv)
133
140
{
134
141
        struct policy_handle pol;
135
 
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
 
142
        NTSTATUS status, result;
136
143
        union lsa_PolicyInformation *info = NULL;
137
144
        uint32_t audit_policy, audit_category;
 
145
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
138
146
 
139
147
        if (argc < 2 || argc > 3) {
140
148
                d_printf(_("insufficient arguments\n"));
162
170
                return NT_STATUS_INVALID_PARAMETER;
163
171
        }
164
172
 
165
 
        result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
 
173
        status = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
166
174
                                        SEC_FLAG_MAXIMUM_ALLOWED,
167
175
                                        &pol);
168
176
 
169
 
        if (!NT_STATUS_IS_OK(result)) {
 
177
        if (!NT_STATUS_IS_OK(status)) {
170
178
                goto done;
171
179
        }
172
180
 
173
 
        result = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
 
181
        status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
174
182
                                            &pol,
175
183
                                            LSA_POLICY_INFO_AUDIT_EVENTS,
176
 
                                            &info);
177
 
 
 
184
                                            &info,
 
185
                                            &result);
 
186
        if (!NT_STATUS_IS_OK(status)) {
 
187
                goto done;
 
188
        }
178
189
        if (!NT_STATUS_IS_OK(result)) {
 
190
                status = result;
179
191
                goto done;
180
192
        }
181
193
 
182
194
        info->audit_events.settings[audit_category] = audit_policy;
183
195
 
184
 
        result = rpccli_lsa_SetInfoPolicy(pipe_hnd, mem_ctx,
 
196
        status = dcerpc_lsa_SetInfoPolicy(b, mem_ctx,
185
197
                                          &pol,
186
198
                                          LSA_POLICY_INFO_AUDIT_EVENTS,
187
 
                                          info);
188
 
 
 
199
                                          info,
 
200
                                          &result);
 
201
        if (!NT_STATUS_IS_OK(status)) {
 
202
                goto done;
 
203
        }
189
204
        if (!NT_STATUS_IS_OK(result)) {
 
205
                status = result;
190
206
                goto done;
191
207
        }
192
208
 
193
 
        result = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
 
209
        status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
194
210
                                            &pol,
195
211
                                            LSA_POLICY_INFO_AUDIT_EVENTS,
196
 
                                            &info);
 
212
                                            &info,
 
213
                                            &result);
 
214
        if (!NT_STATUS_IS_OK(status)) {
 
215
                goto done;
 
216
        }
 
217
 
 
218
        status = result;
 
219
 
197
220
        {
198
221
                const char *val = audit_policy_str(mem_ctx, info->audit_events.settings[audit_category]);
199
222
                const char *policy = audit_description_str(audit_category);
201
224
        }
202
225
 
203
226
 done:
204
 
        if (!NT_STATUS_IS_OK(result)) {
 
227
        if (!NT_STATUS_IS_OK(status)) {
205
228
                d_printf(_("failed to set audit policy: %s\n"),
206
 
                         nt_errstr(result));
 
229
                         nt_errstr(status));
207
230
        }
208
231
 
209
 
        return result;
 
232
        return status;
210
233
}
211
234
 
212
235
/********************************************************************
219
242
                                              bool enable)
220
243
{
221
244
        struct policy_handle pol;
222
 
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
 
245
        NTSTATUS status, result;
223
246
        union lsa_PolicyInformation *info = NULL;
 
247
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
224
248
 
225
 
        result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
 
249
        status = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
226
250
                                        SEC_FLAG_MAXIMUM_ALLOWED,
227
251
                                        &pol);
228
252
 
229
 
        if (!NT_STATUS_IS_OK(result)) {
 
253
        if (!NT_STATUS_IS_OK(status)) {
230
254
                goto done;
231
255
        }
232
256
 
233
 
        result = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
 
257
        status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
234
258
                                            &pol,
235
259
                                            LSA_POLICY_INFO_AUDIT_EVENTS,
236
 
                                            &info);
 
260
                                            &info,
 
261
                                            &result);
 
262
        if (!NT_STATUS_IS_OK(status)) {
 
263
                goto done;
 
264
        }
237
265
        if (!NT_STATUS_IS_OK(result)) {
 
266
                status = result;
238
267
                goto done;
239
268
        }
240
269
 
241
270
        info->audit_events.auditing_mode = enable;
242
271
 
243
 
        result = rpccli_lsa_SetInfoPolicy(pipe_hnd, mem_ctx,
 
272
        status = dcerpc_lsa_SetInfoPolicy(b, mem_ctx,
244
273
                                          &pol,
245
274
                                          LSA_POLICY_INFO_AUDIT_EVENTS,
246
 
                                          info);
247
 
 
 
275
                                          info,
 
276
                                          &result);
 
277
        if (!NT_STATUS_IS_OK(status)) {
 
278
                goto done;
 
279
        }
248
280
        if (!NT_STATUS_IS_OK(result)) {
 
281
                status = result;
249
282
                goto done;
250
283
        }
251
284
 
252
285
 done:
253
 
        if (!NT_STATUS_IS_OK(result)) {
 
286
        if (!NT_STATUS_IS_OK(status)) {
254
287
                d_printf(_("%s: %s\n"),
255
288
                        enable ? _("failed to enable audit policy"):
256
289
                                 _("failed to disable audit policy"),
257
 
                        nt_errstr(result));
 
290
                        nt_errstr(status));
258
291
        }
259
292
 
260
 
        return result;
 
293
        return status;
261
294
}
262
295
 
263
296
/********************************************************************
264
297
********************************************************************/
265
298
 
266
299
static NTSTATUS rpc_audit_disable_internal(struct net_context *c,
267
 
                                           const DOM_SID *domain_sid,
 
300
                                           const struct dom_sid *domain_sid,
268
301
                                           const char *domain_name,
269
302
                                           struct cli_state *cli,
270
303
                                           struct rpc_pipe_client *pipe_hnd,
280
313
********************************************************************/
281
314
 
282
315
static NTSTATUS rpc_audit_enable_internal(struct net_context *c,
283
 
                                          const DOM_SID *domain_sid,
 
316
                                          const struct dom_sid *domain_sid,
284
317
                                          const char *domain_name,
285
318
                                          struct cli_state *cli,
286
319
                                          struct rpc_pipe_client *pipe_hnd,
296
329
********************************************************************/
297
330
 
298
331
static NTSTATUS rpc_audit_list_internal(struct net_context *c,
299
 
                                        const DOM_SID *domain_sid,
 
332
                                        const struct dom_sid *domain_sid,
300
333
                                        const char *domain_name,
301
334
                                        struct cli_state *cli,
302
335
                                        struct rpc_pipe_client *pipe_hnd,
305
338
                                        const char **argv)
306
339
{
307
340
        struct policy_handle pol;
308
 
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
 
341
        NTSTATUS status, result;
309
342
        union lsa_PolicyInformation *info = NULL;
310
343
        int i;
 
344
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
311
345
 
312
 
        result = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
 
346
        status = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
313
347
                                        SEC_FLAG_MAXIMUM_ALLOWED,
314
348
                                        &pol);
315
349
 
316
 
        if (!NT_STATUS_IS_OK(result)) {
 
350
        if (!NT_STATUS_IS_OK(status)) {
317
351
                goto done;
318
352
        }
319
353
 
320
 
        result = rpccli_lsa_QueryInfoPolicy(pipe_hnd, mem_ctx,
 
354
        status = dcerpc_lsa_QueryInfoPolicy(b, mem_ctx,
321
355
                                            &pol,
322
356
                                            LSA_POLICY_INFO_AUDIT_EVENTS,
323
 
                                            &info);
 
357
                                            &info,
 
358
                                            &result);
 
359
        if (!NT_STATUS_IS_OK(status)) {
 
360
                goto done;
 
361
        }
324
362
        if (!NT_STATUS_IS_OK(result)) {
 
363
                status = result;
325
364
                goto done;
326
365
        }
327
366
 
350
389
        }
351
390
 
352
391
 done:
353
 
        if (!NT_STATUS_IS_OK(result)) {
 
392
        if (!NT_STATUS_IS_OK(status)) {
354
393
                d_printf(_("failed to list auditing policies: %s\n"),
355
 
                        nt_errstr(result));
 
394
                        nt_errstr(status));
356
395
        }
357
396
 
358
 
        return result;
 
397
        return status;
359
398
}
360
399
 
361
400
/********************************************************************