~ubuntu-branches/ubuntu/maverick/samba/maverick-security

« back to all changes in this revision

Viewing changes to source/lib/smbconf/testsuite.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2009-05-18 13:26:04 UTC
  • mfrom: (0.28.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090518132604-ebyuqimgymtr3h0k
Tags: 2:3.3.4-2ubuntu1
* Merge from debian unstable, remaining changes:
  + debian/patches/VERSION.patch:
    - setup SAMBA_VERSION_SUFFIX to Ubuntu.
  + 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/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted (LP: #312449)
  + debian/mksambapasswd.awk:
    - Do not add user with UID less than 1000 to smbpasswd.
  + debian/control:
    - Make libwbclient0 replace/conflict with hardy's likewise-open.
    - Don't build against ctdb.
    - Add suggests keyutils for smbfs. (LP: #300221)
  + debian/rules:
    - enable "native" PIE hardening.
    - remove --with-ctdb and --with-cluster-support=yes
  + Add ufw integration:
    - Created debian/samba.ufw profile.
    - debian/rules, debian/samba.dirs, debian/samba.files: install 
      profile
    - debian/control: have samba sugguest ufw.
* Dropped patches:
  + debian/patches/fix-upstream-bug-6186.patch: Merged upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
        char **includes = NULL;
42
42
        TALLOC_CTX *mem_ctx = talloc_stackframe();
43
43
 
44
 
        printf("test: get_includes\n");
 
44
        printf("TEST: get_includes\n");
45
45
        werr = smbconf_get_global_includes(ctx, mem_ctx,
46
46
                                           &num_includes, &includes);
47
47
        if (!W_ERROR_IS_OK(werr)) {
48
 
                printf("failure: get_includes - %s\n", dos_errstr(werr));
 
48
                printf("FAIL: get_includes - %s\n", dos_errstr(werr));
49
49
                goto done;
50
50
        }
51
51
 
53
53
               (num_includes > 0) ? ":" : ".");
54
54
        print_strings("", num_includes, (const char **)includes);
55
55
 
56
 
        printf("success: get_includes\n");
 
56
        printf("OK: get_includes\n");
57
57
        ret = true;
58
58
 
59
59
done:
60
 
        TALLOC_FREE(mem_ctx);
 
60
        talloc_free(mem_ctx);
61
61
        return ret;
62
62
}
63
63
 
75
75
        uint32_t get_num_includes = 0;
76
76
        TALLOC_CTX *mem_ctx = talloc_stackframe();
77
77
 
78
 
        printf("test: set_get_includes\n");
 
78
        printf("TEST: set_get_includes\n");
79
79
 
80
80
        werr = smbconf_set_global_includes(ctx, set_num_includes, set_includes);
81
81
        if (!W_ERROR_IS_OK(werr)) {
82
 
                printf("failure: get_set_includes (setting includes) - %s\n",
 
82
                printf("FAIL: get_set_includes (setting includes) - %s\n",
83
83
                       dos_errstr(werr));
84
84
                goto done;
85
85
        }
87
87
        werr = smbconf_get_global_includes(ctx, mem_ctx, &get_num_includes,
88
88
                                           &get_includes);
89
89
        if (!W_ERROR_IS_OK(werr)) {
90
 
                printf("failure: get_set_includes (getting includes) - %s\n",
 
90
                printf("FAIL: get_set_includes (getting includes) - %s\n",
91
91
                       dos_errstr(werr));
92
92
                goto done;
93
93
        }
94
94
 
95
95
        if (get_num_includes != set_num_includes) {
96
 
                printf("failure: get_set_includes - set %d includes, got %d\n",
 
96
                printf("FAIL: get_set_includes - set %d includes, got %d\n",
97
97
                       set_num_includes, get_num_includes);
98
98
                goto done;
99
99
        }
105
105
                        printf("got: \n");
106
106
                        print_strings("* ", get_num_includes,
107
107
                                      (const char **)get_includes);
108
 
                        printf("failure: get_set_includes - data mismatch:\n");
 
108
                        printf("FAIL: get_set_includes - data mismatch:\n");
109
109
                        goto done;
110
110
                }
111
111
        }
112
112
 
113
 
        printf("success: set_includes\n");
 
113
        printf("OK: set_includes\n");
114
114
        ret = true;
115
115
 
116
116
done:
117
 
        TALLOC_FREE(mem_ctx);
 
117
        talloc_free(mem_ctx);
118
118
        return ret;
119
119
}
120
120
 
130
130
        uint32_t get_num_includes = 0;
131
131
        TALLOC_CTX *mem_ctx = talloc_stackframe();
132
132
 
133
 
        printf("test: delete_includes\n");
 
133
        printf("TEST: delete_includes\n");
134
134
 
135
135
        werr = smbconf_set_global_includes(ctx, set_num_includes, set_includes);
136
136
        if (!W_ERROR_IS_OK(werr)) {
137
 
                printf("failure: delete_includes (setting includes) - %s\n",
 
137
                printf("FAIL: delete_includes (setting includes) - %s\n",
138
138
                       dos_errstr(werr));
139
139
                goto done;
140
140
        }
141
141
 
142
142
        werr = smbconf_delete_global_includes(ctx);
143
143
        if (!W_ERROR_IS_OK(werr)) {
144
 
                printf("failure: delete_includes (deleting includes) - %s\n",
 
144
                printf("FAIL: delete_includes (deleting includes) - %s\n",
145
145
                       dos_errstr(werr));
146
146
                goto done;
147
147
        }
149
149
        werr = smbconf_get_global_includes(ctx, mem_ctx, &get_num_includes,
150
150
                                           &get_includes);
151
151
        if (!W_ERROR_IS_OK(werr)) {
152
 
                printf("failure: delete_includes (getting includes) - %s\n",
 
152
                printf("FAIL: delete_includes (getting includes) - %s\n",
153
153
                       dos_errstr(werr));
154
154
                goto done;
155
155
        }
156
156
 
157
157
        if (get_num_includes != 0) {
158
 
                printf("failure: delete_includes (not empty after delete)\n");
 
158
                printf("FAIL: delete_includes (not empty after delete)\n");
159
159
                goto done;
160
160
        }
161
161
 
162
162
        werr = smbconf_delete_global_includes(ctx);
163
163
        if (!W_ERROR_IS_OK(werr)) {
164
 
                printf("failuer: delete_includes (delete empty includes) - "
 
164
                printf("FAIL: delete_includes (delete empty includes) - "
165
165
                       "%s\n", dos_errstr(werr));
166
166
                goto done;
167
167
        }
168
168
 
169
 
        printf("success: delete_includes\n");
 
169
        printf("OK: delete_includes\n");
170
170
        ret = true;
171
171
 
172
172
done:
173
173
        return ret;
174
174
}
175
175
 
 
176
static bool create_conf_file(const char *filename)
 
177
{
 
178
        FILE *f;
 
179
 
 
180
        printf("TEST: creating file\n");
 
181
        f = sys_fopen(filename, "w");
 
182
        if (!f) {
 
183
                printf("failure: failed to open %s for writing: %s\n",
 
184
                       filename, strerror(errno));
 
185
                return false;
 
186
        }
 
187
 
 
188
        fprintf(f, "[global]\n");
 
189
        fprintf(f, "\tserver string = smbconf testsuite\n");
 
190
        fprintf(f, "\tworkgroup = SAMBA\n");
 
191
        fprintf(f, "\tsecurity = user\n");
 
192
 
 
193
        fclose(f);
 
194
 
 
195
        printf("OK: create file\n");
 
196
        return true;
 
197
}
 
198
 
176
199
static bool torture_smbconf_txt(void)
177
200
{
178
201
        WERROR werr;
179
202
        bool ret = true;
 
203
        const char *filename = "/tmp/smb.conf.smbconf_testsuite";
180
204
        struct smbconf_ctx *conf_ctx = NULL;
181
205
        TALLOC_CTX *mem_ctx = talloc_stackframe();
182
206
 
183
207
        printf("test: text backend\n");
184
208
 
185
 
        printf("test: init\n");
186
 
        werr = smbconf_init_txt(mem_ctx, &conf_ctx, NULL);
 
209
        if (!create_conf_file(filename)) {
 
210
                ret = false;
 
211
                goto done;
 
212
        }
 
213
 
 
214
        printf("TEST: init\n");
 
215
        werr = smbconf_init_txt(mem_ctx, &conf_ctx, filename);
187
216
        if (!W_ERROR_IS_OK(werr)) {
188
 
                printf("failure: init failed: %s\n", dos_errstr(werr));
 
217
                printf("FAIL: text backend\[ failed: %s\n", dos_errstr(werr));
189
218
                ret = false;
190
219
                goto done;
191
220
        }
192
 
        printf("success: init\n");
 
221
        printf("OK: init\n");
193
222
 
194
223
        ret &= test_get_includes(conf_ctx);
195
224
 
196
225
        smbconf_shutdown(conf_ctx);
197
226
 
 
227
        printf("TEST: unlink file\n");
 
228
        if (unlink(filename) != 0) {
 
229
                printf("OK: unlink failed: %s\n", strerror(errno));
 
230
                ret = false;
 
231
                goto done;
 
232
        }
 
233
        printf("OK: unlink file\n");
 
234
 
 
235
done:
198
236
        printf("%s: text backend\n", ret ? "success" : "failure");
199
 
 
200
 
done:
201
 
        TALLOC_FREE(mem_ctx);
 
237
        talloc_free(mem_ctx);
202
238
        return ret;
203
239
}
204
240
 
211
247
 
212
248
        printf("test: registry backend\n");
213
249
 
214
 
        printf("test: init\n");
 
250
        printf("TEST: init\n");
215
251
        werr = smbconf_init_reg(mem_ctx, &conf_ctx, NULL);
216
252
        if (!W_ERROR_IS_OK(werr)) {
217
 
                printf("failure: init failed: %s\n", dos_errstr(werr));
 
253
                printf("FAIL: init failed: %s\n", dos_errstr(werr));
218
254
                ret = false;
219
255
                goto done;
220
256
        }
221
 
        printf("success: init\n");
 
257
        printf("OK: init\n");
222
258
 
223
259
        ret &= test_get_includes(conf_ctx);
224
260
        ret &= test_set_get_includes(conf_ctx);
226
262
 
227
263
        smbconf_shutdown(conf_ctx);
228
264
 
 
265
done:
229
266
        printf("%s: registry backend\n", ret ? "success" : "failure");
230
 
 
231
 
done:
232
 
        TALLOC_FREE(mem_ctx);
 
267
        talloc_free(mem_ctx);
233
268
        return ret;
234
269
}
235
270
 
278
313
        ret = torture_smbconf();
279
314
 
280
315
done:
281
 
        TALLOC_FREE(mem_ctx);
 
316
        talloc_free(mem_ctx);
282
317
        return ret ? 0 : -1;
283
318
}