| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#include "tests.h" |
| 28 |
|
| 29 |
#define PR_TEST_AUTH_NAME "testsuite_user" |
| 30 |
#define PR_TEST_AUTH_NOBODY "testsuite_nobody" |
| 31 |
#define PR_TEST_AUTH_NOBODY2 "testsuite_nobody2" |
| 32 |
#define PR_TEST_AUTH_NOGROUP "testsuite_nogroup" |
| 33 |
#define PR_TEST_AUTH_UID 500 |
| 34 |
#define PR_TEST_AUTH_UID_STR "500" |
| 35 |
#define PR_TEST_AUTH_NOUID 666 |
| 36 |
#define PR_TEST_AUTH_NOUID2 667 |
| 37 |
#define PR_TEST_AUTH_GID 500 |
| 38 |
#define PR_TEST_AUTH_GID_STR "500" |
| 39 |
#define PR_TEST_AUTH_NOGID 666 |
| 40 |
#define PR_TEST_AUTH_HOME "/tmp" |
| 41 |
#define PR_TEST_AUTH_SHELL "/bin/bash" |
| 42 |
#define PR_TEST_AUTH_PASSWD "password" |
| 43 |
|
| 44 |
static pool *p = NULL; |
| 45 |
static server_rec *test_server = NULL; |
| 46 |
|
| 47 |
static struct passwd test_pwd; |
| 48 |
static struct group test_grp; |
| 49 |
|
| 50 |
static unsigned int setpwent_count = 0; |
| 51 |
static unsigned int endpwent_count = 0; |
| 52 |
static unsigned int getpwent_count = 0; |
| 53 |
static unsigned int getpwnam_count = 0; |
| 54 |
static unsigned int getpwuid_count = 0; |
| 55 |
static unsigned int name2uid_count = 0; |
| 56 |
static unsigned int uid2name_count = 0; |
| 57 |
|
| 58 |
static unsigned int setgrent_count = 0; |
| 59 |
static unsigned int endgrent_count = 0; |
| 60 |
static unsigned int getgrent_count = 0; |
| 61 |
static unsigned int getgrnam_count = 0; |
| 62 |
static unsigned int getgrgid_count = 0; |
| 63 |
static unsigned int name2gid_count = 0; |
| 64 |
static unsigned int gid2name_count = 0; |
| 65 |
static unsigned int getgroups_count = 0; |
| 66 |
|
| 67 |
static module testsuite_module = { |
| 68 |
NULL, NULL, |
| 69 |
|
| 70 |
|
| 71 |
0x20, |
| 72 |
|
| 73 |
|
| 74 |
"testsuite", |
| 75 |
|
| 76 |
|
| 77 |
NULL, |
| 78 |
|
| 79 |
|
| 80 |
NULL, |
| 81 |
|
| 82 |
|
| 83 |
NULL, |
| 84 |
|
| 85 |
|
| 86 |
NULL, |
| 87 |
|
| 88 |
|
| 89 |
NULL |
| 90 |
}; |
| 91 |
|
| 92 |
MODRET handle_setpwent(cmd_rec *cmd) { |
| 93 |
setpwent_count++; |
| 94 |
return PR_HANDLED(cmd); |
| 95 |
} |
| 96 |
|
| 97 |
MODRET handle_endpwent(cmd_rec *cmd) { |
| 98 |
endpwent_count++; |
| 99 |
return PR_HANDLED(cmd); |
| 100 |
} |
| 101 |
|
| 102 |
MODRET handle_getpwent(cmd_rec *cmd) { |
| 103 |
getpwent_count++; |
| 104 |
|
| 105 |
if (getpwent_count == 1) { |
| 106 |
test_pwd.pw_uid = PR_TEST_AUTH_UID; |
| 107 |
test_pwd.pw_gid = PR_TEST_AUTH_GID; |
| 108 |
return mod_create_data(cmd, &test_pwd); |
| 109 |
} |
| 110 |
|
| 111 |
if (getpwent_count == 2) { |
| 112 |
test_pwd.pw_uid = (uid_t) -1; |
| 113 |
test_pwd.pw_gid = PR_TEST_AUTH_GID; |
| 114 |
return mod_create_data(cmd, &test_pwd); |
| 115 |
} |
| 116 |
|
| 117 |
if (getpwent_count == 3) { |
| 118 |
test_pwd.pw_uid = PR_TEST_AUTH_UID; |
| 119 |
test_pwd.pw_gid = (gid_t) -1; |
| 120 |
return mod_create_data(cmd, &test_pwd); |
| 121 |
} |
| 122 |
|
| 123 |
return PR_DECLINED(cmd); |
| 124 |
} |
| 125 |
|
| 126 |
MODRET handle_getpwnam(cmd_rec *cmd) { |
| 127 |
const char *name; |
| 128 |
|
| 129 |
name = cmd->argv[0]; |
| 130 |
getpwnam_count++; |
| 131 |
|
| 132 |
if (strcmp(name, PR_TEST_AUTH_NAME) == 0) { |
| 133 |
test_pwd.pw_uid = PR_TEST_AUTH_UID; |
| 134 |
test_pwd.pw_gid = PR_TEST_AUTH_GID; |
| 135 |
return mod_create_data(cmd, &test_pwd); |
| 136 |
} |
| 137 |
|
| 138 |
if (strcmp(name, PR_TEST_AUTH_NOBODY) == 0) { |
| 139 |
test_pwd.pw_uid = (uid_t) -1; |
| 140 |
test_pwd.pw_gid = PR_TEST_AUTH_GID; |
| 141 |
return mod_create_data(cmd, &test_pwd); |
| 142 |
} |
| 143 |
|
| 144 |
if (strcmp(name, PR_TEST_AUTH_NOBODY2) == 0) { |
| 145 |
test_pwd.pw_uid = PR_TEST_AUTH_UID; |
| 146 |
test_pwd.pw_gid = (gid_t) -1; |
| 147 |
return mod_create_data(cmd, &test_pwd); |
| 148 |
} |
| 149 |
|
| 150 |
return PR_DECLINED(cmd); |
| 151 |
} |
| 152 |
|
| 153 |
MODRET handle_getpwuid(cmd_rec *cmd) { |
| 154 |
uid_t uid; |
| 155 |
|
| 156 |
uid = *((uid_t *) cmd->argv[0]); |
| 157 |
getpwuid_count++; |
| 158 |
|
| 159 |
if (uid == PR_TEST_AUTH_UID) { |
| 160 |
test_pwd.pw_uid = PR_TEST_AUTH_UID; |
| 161 |
test_pwd.pw_gid = PR_TEST_AUTH_GID; |
| 162 |
return mod_create_data(cmd, &test_pwd); |
| 163 |
} |
| 164 |
|
| 165 |
if (uid == PR_TEST_AUTH_NOUID) { |
| 166 |
test_pwd.pw_uid = (uid_t) -1; |
| 167 |
test_pwd.pw_gid = PR_TEST_AUTH_GID; |
| 168 |
return mod_create_data(cmd, &test_pwd); |
| 169 |
} |
| 170 |
|
| 171 |
if (uid == PR_TEST_AUTH_NOUID2) { |
| 172 |
test_pwd.pw_uid = PR_TEST_AUTH_UID; |
| 173 |
test_pwd.pw_gid = (gid_t) -1; |
| 174 |
return mod_create_data(cmd, &test_pwd); |
| 175 |
} |
| 176 |
|
| 177 |
return PR_DECLINED(cmd); |
| 178 |
} |
| 179 |
|
| 180 |
MODRET decline_name2uid(cmd_rec *cmd) { |
| 181 |
name2uid_count++; |
| 182 |
return PR_DECLINED(cmd); |
| 183 |
} |
| 184 |
|
| 185 |
MODRET handle_name2uid(cmd_rec *cmd) { |
| 186 |
const char *name; |
| 187 |
|
| 188 |
name = cmd->argv[0]; |
| 189 |
name2uid_count++; |
| 190 |
|
| 191 |
if (strcmp(name, PR_TEST_AUTH_NAME) != 0) { |
| 192 |
return PR_DECLINED(cmd); |
| 193 |
} |
| 194 |
|
| 195 |
return mod_create_data(cmd, (void *) &(test_pwd.pw_uid)); |
| 196 |
} |
| 197 |
|
| 198 |
MODRET decline_uid2name(cmd_rec *cmd) { |
| 199 |
uid2name_count++; |
| 200 |
return PR_DECLINED(cmd); |
| 201 |
} |
| 202 |
|
| 203 |
MODRET handle_uid2name(cmd_rec *cmd) { |
| 204 |
uid_t uid; |
| 205 |
|
| 206 |
uid = *((uid_t *) cmd->argv[0]); |
| 207 |
uid2name_count++; |
| 208 |
|
| 209 |
if (uid != PR_TEST_AUTH_UID) { |
| 210 |
return PR_DECLINED(cmd); |
| 211 |
} |
| 212 |
|
| 213 |
return mod_create_data(cmd, test_pwd.pw_name); |
| 214 |
} |
| 215 |
|
| 216 |
MODRET handle_setgrent(cmd_rec *cmd) { |
| 217 |
setgrent_count++; |
| 218 |
return PR_HANDLED(cmd); |
| 219 |
} |
| 220 |
|
| 221 |
MODRET handle_endgrent(cmd_rec *cmd) { |
| 222 |
endgrent_count++; |
| 223 |
return PR_HANDLED(cmd); |
| 224 |
} |
| 225 |
|
| 226 |
MODRET handle_getgrent(cmd_rec *cmd) { |
| 227 |
getgrent_count++; |
| 228 |
|
| 229 |
if (getgrent_count == 1) { |
| 230 |
test_grp.gr_gid = PR_TEST_AUTH_GID; |
| 231 |
return mod_create_data(cmd, &test_grp); |
| 232 |
} |
| 233 |
|
| 234 |
if (getgrent_count == 2) { |
| 235 |
test_grp.gr_gid = (gid_t) -1; |
| 236 |
return mod_create_data(cmd, &test_grp); |
| 237 |
} |
| 238 |
|
| 239 |
return PR_DECLINED(cmd); |
| 240 |
} |
| 241 |
|
| 242 |
MODRET handle_getgrnam(cmd_rec *cmd) { |
| 243 |
const char *name; |
| 244 |
|
| 245 |
name = cmd->argv[0]; |
| 246 |
getgrnam_count++; |
| 247 |
|
| 248 |
if (strcmp(name, PR_TEST_AUTH_NAME) == 0) { |
| 249 |
test_grp.gr_gid = PR_TEST_AUTH_GID; |
| 250 |
return mod_create_data(cmd, &test_grp); |
| 251 |
} |
| 252 |
|
| 253 |
if (strcmp(name, PR_TEST_AUTH_NOGROUP) == 0) { |
| 254 |
test_grp.gr_gid = (gid_t) -1; |
| 255 |
return mod_create_data(cmd, &test_grp); |
| 256 |
} |
| 257 |
|
| 258 |
return PR_DECLINED(cmd); |
| 259 |
} |
| 260 |
|
| 261 |
MODRET handle_getgrgid(cmd_rec *cmd) { |
| 262 |
gid_t gid; |
| 263 |
|
| 264 |
gid = *((gid_t *) cmd->argv[0]); |
| 265 |
getgrgid_count++; |
| 266 |
|
| 267 |
if (gid == PR_TEST_AUTH_GID) { |
| 268 |
test_grp.gr_gid = PR_TEST_AUTH_GID; |
| 269 |
return mod_create_data(cmd, &test_grp); |
| 270 |
} |
| 271 |
|
| 272 |
if (gid == PR_TEST_AUTH_NOGID) { |
| 273 |
test_grp.gr_gid = (gid_t) -1; |
| 274 |
return mod_create_data(cmd, &test_grp); |
| 275 |
} |
| 276 |
|
| 277 |
return PR_DECLINED(cmd); |
| 278 |
} |
| 279 |
|
| 280 |
MODRET decline_name2gid(cmd_rec *cmd) { |
| 281 |
name2gid_count++; |
| 282 |
return PR_DECLINED(cmd); |
| 283 |
} |
| 284 |
|
| 285 |
MODRET handle_name2gid(cmd_rec *cmd) { |
| 286 |
const char *name; |
| 287 |
|
| 288 |
name = cmd->argv[0]; |
| 289 |
name2gid_count++; |
| 290 |
|
| 291 |
if (strcmp(name, PR_TEST_AUTH_NAME) != 0) { |
| 292 |
return PR_DECLINED(cmd); |
| 293 |
} |
| 294 |
|
| 295 |
return mod_create_data(cmd, (void *) &(test_grp.gr_gid)); |
| 296 |
} |
| 297 |
|
| 298 |
MODRET decline_gid2name(cmd_rec *cmd) { |
| 299 |
gid2name_count++; |
| 300 |
return PR_DECLINED(cmd); |
| 301 |
} |
| 302 |
|
| 303 |
MODRET handle_gid2name(cmd_rec *cmd) { |
| 304 |
gid_t gid; |
| 305 |
|
| 306 |
gid = *((gid_t *) cmd->argv[0]); |
| 307 |
gid2name_count++; |
| 308 |
|
| 309 |
if (gid != PR_TEST_AUTH_GID) { |
| 310 |
return PR_DECLINED(cmd); |
| 311 |
} |
| 312 |
|
| 313 |
return mod_create_data(cmd, test_grp.gr_name); |
| 314 |
} |
| 315 |
|
| 316 |
MODRET handle_getgroups(cmd_rec *cmd) { |
| 317 |
const char *name; |
| 318 |
array_header *gids = NULL, *names = NULL; |
| 319 |
|
| 320 |
name = (char *) cmd->argv[0]; |
| 321 |
|
| 322 |
if (cmd->argv[1]) { |
| 323 |
gids = (array_header *) cmd->argv[1]; |
| 324 |
} |
| 325 |
|
| 326 |
if (cmd->argv[2]) { |
| 327 |
names = (array_header *) cmd->argv[2]; |
| 328 |
} |
| 329 |
|
| 330 |
getgroups_count++; |
| 331 |
|
| 332 |
if (strcmp(name, PR_TEST_AUTH_NAME) != 0) { |
| 333 |
return PR_DECLINED(cmd); |
| 334 |
} |
| 335 |
|
| 336 |
if (gids != NULL) { |
| 337 |
*((gid_t *) push_array(gids)) = PR_TEST_AUTH_GID; |
| 338 |
} |
| 339 |
|
| 340 |
if (names != NULL) { |
| 341 |
*((char **) push_array(names)) = pstrdup(p, PR_TEST_AUTH_NAME); |
| 342 |
} |
| 343 |
|
| 344 |
return mod_create_data(cmd, (void *) &gids->nelts); |
| 345 |
} |
| 346 |
|
| 347 |
static int authn_rfc2228 = FALSE; |
| 348 |
|
| 349 |
MODRET handle_authn(cmd_rec *cmd) { |
| 350 |
const char *user, *cleartext_passwd; |
| 351 |
|
| 352 |
user = cmd->argv[0]; |
| 353 |
cleartext_passwd = cmd->argv[1]; |
| 354 |
|
| 355 |
if (strcmp(user, PR_TEST_AUTH_NAME) == 0) { |
| 356 |
if (strcmp(cleartext_passwd, PR_TEST_AUTH_PASSWD) == 0) { |
| 357 |
if (authn_rfc2228) { |
| 358 |
authn_rfc2228 = FALSE; |
| 359 |
return mod_create_data(cmd, (void *) PR_AUTH_RFC2228_OK); |
| 360 |
} |
| 361 |
|
| 362 |
return PR_HANDLED(cmd); |
| 363 |
} |
| 364 |
|
| 365 |
return PR_ERROR_INT(cmd, PR_AUTH_BADPWD); |
| 366 |
} |
| 367 |
|
| 368 |
return PR_DECLINED(cmd); |
| 369 |
} |
| 370 |
|
| 371 |
MODRET handle_authz(cmd_rec *cmd) { |
| 372 |
const char *user; |
| 373 |
|
| 374 |
user = cmd->argv[0]; |
| 375 |
|
| 376 |
if (strcmp(user, PR_TEST_AUTH_NAME) == 0) { |
| 377 |
return PR_HANDLED(cmd); |
| 378 |
} |
| 379 |
|
| 380 |
return PR_ERROR_INT(cmd, PR_AUTH_NOPWD); |
| 381 |
} |
| 382 |
|
| 383 |
static int check_rfc2228 = FALSE; |
| 384 |
|
| 385 |
MODRET handle_check(cmd_rec *cmd) { |
| 386 |
const char *user, *cleartext_passwd, *ciphertext_passwd; |
| 387 |
|
| 388 |
ciphertext_passwd = cmd->argv[0]; |
| 389 |
user = cmd->argv[1]; |
| 390 |
cleartext_passwd = cmd->argv[2]; |
| 391 |
|
| 392 |
if (strcmp(user, PR_TEST_AUTH_NAME) == 0) { |
| 393 |
if (ciphertext_passwd != NULL && |
| 394 |
strcmp(ciphertext_passwd, cleartext_passwd) == 0) { |
| 395 |
if (check_rfc2228) { |
| 396 |
check_rfc2228 = FALSE; |
| 397 |
return mod_create_data(cmd, (void *) PR_AUTH_RFC2228_OK); |
| 398 |
} |
| 399 |
|
| 400 |
return PR_HANDLED(cmd); |
| 401 |
} |
| 402 |
|
| 403 |
return PR_ERROR_INT(cmd, PR_AUTH_BADPWD); |
| 404 |
} |
| 405 |
|
| 406 |
return PR_DECLINED(cmd); |
| 407 |
} |
| 408 |
|
| 409 |
MODRET handle_requires_pass(cmd_rec *cmd) { |
| 410 |
const char *name; |
| 411 |
|
| 412 |
name = cmd->argv[0]; |
| 413 |
|
| 414 |
if (strcmp(name, PR_TEST_AUTH_NAME) == 0) { |
| 415 |
return mod_create_data(cmd, (void *) PR_AUTH_RFC2228_OK); |
| 416 |
} |
| 417 |
|
| 418 |
return PR_DECLINED(cmd); |
| 419 |
} |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
static void set_up(void) { |
| 424 |
if (p == NULL) { |
| 425 |
p = permanent_pool = make_sub_pool(NULL); |
| 426 |
} |
| 427 |
|
| 428 |
init_stash(); |
| 429 |
init_auth(); |
| 430 |
(void) pr_auth_cache_set(TRUE, PR_AUTH_CACHE_FL_DEFAULT); |
| 431 |
|
| 432 |
if (getenv("TEST_VERBOSE") != NULL) { |
| 433 |
pr_trace_set_levels("auth", 1, 20); |
| 434 |
} |
| 435 |
|
| 436 |
test_server = pcalloc(p, sizeof(server_rec)); |
| 437 |
tests_stubs_set_main_server(test_server); |
| 438 |
|
| 439 |
test_pwd.pw_name = PR_TEST_AUTH_NAME; |
| 440 |
test_pwd.pw_uid = PR_TEST_AUTH_UID; |
| 441 |
test_pwd.pw_gid = PR_TEST_AUTH_GID; |
| 442 |
test_pwd.pw_dir = PR_TEST_AUTH_HOME; |
| 443 |
test_pwd.pw_shell = PR_TEST_AUTH_SHELL; |
| 444 |
|
| 445 |
test_grp.gr_name = PR_TEST_AUTH_NAME; |
| 446 |
test_grp.gr_gid = PR_TEST_AUTH_GID; |
| 447 |
|
| 448 |
|
| 449 |
setpwent_count = 0; |
| 450 |
endpwent_count = 0; |
| 451 |
getpwent_count = 0; |
| 452 |
getpwnam_count = 0; |
| 453 |
getpwuid_count = 0; |
| 454 |
name2uid_count = 0; |
| 455 |
uid2name_count = 0; |
| 456 |
|
| 457 |
setgrent_count = 0; |
| 458 |
endgrent_count = 0; |
| 459 |
getgrent_count = 0; |
| 460 |
getgrnam_count = 0; |
| 461 |
getgrgid_count = 0; |
| 462 |
name2gid_count = 0; |
| 463 |
gid2name_count = 0; |
| 464 |
getgroups_count = 0; |
| 465 |
|
| 466 |
pr_auth_cache_clear(); |
| 467 |
} |
| 468 |
|
| 469 |
static void tear_down(void) { |
| 470 |
(void) pr_auth_cache_set(TRUE, PR_AUTH_CACHE_FL_DEFAULT); |
| 471 |
|
| 472 |
if (getenv("TEST_VERBOSE") != NULL) { |
| 473 |
pr_trace_set_levels("auth", 0, 0); |
| 474 |
} |
| 475 |
|
| 476 |
if (p != NULL) { |
| 477 |
destroy_pool(p); |
| 478 |
p = session.pool = permanent_pool = NULL; |
| 479 |
} |
| 480 |
|
| 481 |
test_server = NULL; |
| 482 |
tests_stubs_set_main_server(NULL); |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
START_TEST (auth_setpwent_test) { |
| 488 |
int res; |
| 489 |
authtable authtab; |
| 490 |
char *sym_name = "setpwent"; |
| 491 |
|
| 492 |
pr_auth_setpwent(p); |
| 493 |
ck_assert_msg(setpwent_count == 0, "Expected call count 0, got %u", |
| 494 |
setpwent_count); |
| 495 |
mark_point(); |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
memset(&authtab, 0, sizeof(authtab)); |
| 500 |
authtab.name = sym_name; |
| 501 |
authtab.handler = handle_setpwent; |
| 502 |
authtab.m = &testsuite_module; |
| 503 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 504 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 505 |
strerror(errno)); |
| 506 |
|
| 507 |
pr_auth_setpwent(p); |
| 508 |
ck_assert_msg(setpwent_count == 1, "Expected call count 1, got %u", |
| 509 |
setpwent_count); |
| 510 |
|
| 511 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 512 |
} |
| 513 |
END_TEST |
| 514 |
|
| 515 |
START_TEST (auth_endpwent_test) { |
| 516 |
int res; |
| 517 |
authtable authtab; |
| 518 |
char *sym_name = "endpwent"; |
| 519 |
|
| 520 |
pr_auth_endpwent(p); |
| 521 |
ck_assert_msg(endpwent_count == 0, "Expected call count 0, got %u", |
| 522 |
endpwent_count); |
| 523 |
mark_point(); |
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
memset(&authtab, 0, sizeof(authtab)); |
| 528 |
authtab.name = sym_name; |
| 529 |
authtab.handler = handle_endpwent; |
| 530 |
authtab.m = &testsuite_module; |
| 531 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 532 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 533 |
strerror(errno)); |
| 534 |
|
| 535 |
pr_auth_endpwent(p); |
| 536 |
ck_assert_msg(endpwent_count == 1, "Expected call count 1, got %u", |
| 537 |
endpwent_count); |
| 538 |
|
| 539 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 540 |
} |
| 541 |
END_TEST |
| 542 |
|
| 543 |
START_TEST (auth_getpwent_test) { |
| 544 |
int res; |
| 545 |
struct passwd *pw; |
| 546 |
authtable authtab; |
| 547 |
char *sym_name = "getpwent"; |
| 548 |
|
| 549 |
getpwent_count = 0; |
| 550 |
|
| 551 |
pw = pr_auth_getpwent(NULL); |
| 552 |
ck_assert_msg(pw == NULL, "Found pwent unexpectedly"); |
| 553 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 554 |
errno, strerror(errno)); |
| 555 |
|
| 556 |
pw = pr_auth_getpwent(p); |
| 557 |
ck_assert_msg(pw == NULL, "Found pwent unexpectedly"); |
| 558 |
ck_assert_msg(getpwent_count == 0, "Expected call count 0, got %u", |
| 559 |
getpwent_count); |
| 560 |
mark_point(); |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
memset(&authtab, 0, sizeof(authtab)); |
| 565 |
authtab.name = sym_name; |
| 566 |
authtab.handler = handle_getpwent; |
| 567 |
authtab.m = &testsuite_module; |
| 568 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 569 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 570 |
strerror(errno)); |
| 571 |
|
| 572 |
pw = pr_auth_getpwent(p); |
| 573 |
ck_assert_msg(pw != NULL, "Failed to find pwent: %s", strerror(errno)); |
| 574 |
ck_assert_msg(getpwent_count == 1, "Expected call count 1, got %u", |
| 575 |
getpwent_count); |
| 576 |
|
| 577 |
pw = pr_auth_getpwent(p); |
| 578 |
ck_assert_msg(pw == NULL, "Failed to avoid pwent with bad UID"); |
| 579 |
ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT, |
| 580 |
strerror(errno), errno); |
| 581 |
ck_assert_msg(getpwent_count == 2, "Expected call count 2, got %u", |
| 582 |
getpwent_count); |
| 583 |
|
| 584 |
pw = pr_auth_getpwent(p); |
| 585 |
ck_assert_msg(pw == NULL, "Failed to avoid pwent with bad GID"); |
| 586 |
ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT, |
| 587 |
strerror(errno), errno); |
| 588 |
ck_assert_msg(getpwent_count == 3, "Expected call count 3, got %u", |
| 589 |
getpwent_count); |
| 590 |
|
| 591 |
pr_auth_endpwent(p); |
| 592 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 593 |
} |
| 594 |
END_TEST |
| 595 |
|
| 596 |
START_TEST (auth_getpwnam_test) { |
| 597 |
int res; |
| 598 |
struct passwd *pw; |
| 599 |
authtable authtab; |
| 600 |
char *sym_name = "getpwnam"; |
| 601 |
|
| 602 |
pw = pr_auth_getpwnam(NULL, NULL); |
| 603 |
ck_assert_msg(pw == NULL, "Found pwnam unexpectedly"); |
| 604 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 605 |
errno, strerror(errno)); |
| 606 |
|
| 607 |
pw = pr_auth_getpwnam(p, PR_TEST_AUTH_NAME); |
| 608 |
ck_assert_msg(pw == NULL, "Found pwnam unexpectedly"); |
| 609 |
ck_assert_msg(getpwnam_count == 0, "Expected call count 0, got %u", |
| 610 |
getpwnam_count); |
| 611 |
mark_point(); |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
memset(&authtab, 0, sizeof(authtab)); |
| 616 |
authtab.name = sym_name; |
| 617 |
authtab.handler = handle_getpwnam; |
| 618 |
authtab.m = &testsuite_module; |
| 619 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 620 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 621 |
strerror(errno)); |
| 622 |
|
| 623 |
mark_point(); |
| 624 |
|
| 625 |
pw = pr_auth_getpwnam(p, PR_TEST_AUTH_NOBODY); |
| 626 |
ck_assert_msg(pw == NULL, "Found user '%s' unexpectedly", PR_TEST_AUTH_NOBODY); |
| 627 |
ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT, |
| 628 |
strerror(errno), errno); |
| 629 |
|
| 630 |
pw = pr_auth_getpwnam(p, PR_TEST_AUTH_NOBODY2); |
| 631 |
ck_assert_msg(pw == NULL, "Found user '%s' unexpectedly", PR_TEST_AUTH_NOBODY2); |
| 632 |
ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT, |
| 633 |
strerror(errno), errno); |
| 634 |
|
| 635 |
pw = pr_auth_getpwnam(p, PR_TEST_AUTH_NAME); |
| 636 |
ck_assert_msg(pw != NULL, "Failed to find user '%s': %s", PR_TEST_AUTH_NAME, |
| 637 |
strerror(errno)); |
| 638 |
ck_assert_msg(getpwnam_count == 3, "Expected call count 3, got %u", |
| 639 |
getpwnam_count); |
| 640 |
|
| 641 |
pw = pr_auth_getpwnam(p, PR_TEST_AUTH_NAME); |
| 642 |
ck_assert_msg(pw != NULL, "Failed to find user '%s': %s", PR_TEST_AUTH_NAME, |
| 643 |
strerror(errno)); |
| 644 |
ck_assert_msg(getpwnam_count == 4, "Expected call count 4, got %u", |
| 645 |
getpwnam_count); |
| 646 |
|
| 647 |
mark_point(); |
| 648 |
|
| 649 |
pw = pr_auth_getpwnam(p, "other"); |
| 650 |
ck_assert_msg(pw == NULL, "Found pwnam for user 'other' unexpectedly"); |
| 651 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 652 |
errno, strerror(errno)); |
| 653 |
ck_assert_msg(getpwnam_count == 5, "Expected call count 5, got %u", |
| 654 |
getpwnam_count); |
| 655 |
|
| 656 |
pr_auth_endpwent(p); |
| 657 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 658 |
} |
| 659 |
END_TEST |
| 660 |
|
| 661 |
START_TEST (auth_getpwuid_test) { |
| 662 |
int res; |
| 663 |
struct passwd *pw; |
| 664 |
authtable authtab; |
| 665 |
char *sym_name = "getpwuid"; |
| 666 |
|
| 667 |
pw = pr_auth_getpwuid(NULL, -1); |
| 668 |
ck_assert_msg(pw == NULL, "Found pwuid unexpectedly"); |
| 669 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 670 |
errno, strerror(errno)); |
| 671 |
|
| 672 |
pw = pr_auth_getpwuid(p, PR_TEST_AUTH_UID); |
| 673 |
ck_assert_msg(pw == NULL, "Found pwuid unexpectedly"); |
| 674 |
ck_assert_msg(getpwuid_count == 0, "Expected call count 0, got %u", |
| 675 |
getpwuid_count); |
| 676 |
mark_point(); |
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
memset(&authtab, 0, sizeof(authtab)); |
| 681 |
authtab.name = sym_name; |
| 682 |
authtab.handler = handle_getpwuid; |
| 683 |
authtab.m = &testsuite_module; |
| 684 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 685 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 686 |
strerror(errno)); |
| 687 |
|
| 688 |
mark_point(); |
| 689 |
|
| 690 |
pw = pr_auth_getpwuid(p, PR_TEST_AUTH_UID); |
| 691 |
ck_assert_msg(pw != NULL, "Failed to find pwuid: %s", strerror(errno)); |
| 692 |
ck_assert_msg(getpwuid_count == 1, "Expected call count 1, got %u", |
| 693 |
getpwuid_count); |
| 694 |
|
| 695 |
pw = pr_auth_getpwuid(p, PR_TEST_AUTH_NOUID); |
| 696 |
ck_assert_msg(pw == NULL, "Found pwuid for NOUID unexpectedly"); |
| 697 |
ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT, |
| 698 |
strerror(errno), errno); |
| 699 |
|
| 700 |
pw = pr_auth_getpwuid(p, PR_TEST_AUTH_NOUID2); |
| 701 |
ck_assert_msg(pw == NULL, "Found pwuid for NOUID2 unexpectedly"); |
| 702 |
ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT, |
| 703 |
strerror(errno), errno); |
| 704 |
|
| 705 |
mark_point(); |
| 706 |
|
| 707 |
pw = pr_auth_getpwuid(p, 5); |
| 708 |
ck_assert_msg(pw == NULL, "Found pwuid for UID 5 unexpectedly"); |
| 709 |
ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT, |
| 710 |
strerror(errno), errno); |
| 711 |
|
| 712 |
ck_assert_msg(getpwuid_count == 4, "Expected call count 4, got %u", |
| 713 |
getpwuid_count); |
| 714 |
|
| 715 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 716 |
} |
| 717 |
END_TEST |
| 718 |
|
| 719 |
START_TEST (auth_name2uid_test) { |
| 720 |
int res; |
| 721 |
uid_t uid; |
| 722 |
authtable authtab; |
| 723 |
char *sym_name = "name2uid"; |
| 724 |
|
| 725 |
pr_auth_cache_set(FALSE, PR_AUTH_CACHE_FL_BAD_NAME2UID); |
| 726 |
|
| 727 |
uid = pr_auth_name2uid(NULL, NULL); |
| 728 |
ck_assert_msg(uid == (uid_t) -1, "Found UID unexpectedly"); |
| 729 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 730 |
errno, strerror(errno)); |
| 731 |
|
| 732 |
uid = pr_auth_name2uid(p, PR_TEST_AUTH_NAME); |
| 733 |
ck_assert_msg(uid == (uid_t) -1, "Found UID unexpectedly"); |
| 734 |
ck_assert_msg(name2uid_count == 0, "Expected call count 0, got %u", |
| 735 |
name2uid_count); |
| 736 |
mark_point(); |
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
memset(&authtab, 0, sizeof(authtab)); |
| 741 |
authtab.name = sym_name; |
| 742 |
authtab.handler = handle_name2uid; |
| 743 |
authtab.m = &testsuite_module; |
| 744 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 745 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 746 |
strerror(errno)); |
| 747 |
|
| 748 |
mark_point(); |
| 749 |
|
| 750 |
uid = pr_auth_name2uid(p, PR_TEST_AUTH_NAME); |
| 751 |
ck_assert_msg(uid == PR_TEST_AUTH_UID, "Expected UID %lu, got %lu", |
| 752 |
(unsigned long) PR_TEST_AUTH_UID, (unsigned long) uid); |
| 753 |
ck_assert_msg(name2uid_count == 1, "Expected call count 1, got %u", |
| 754 |
name2uid_count); |
| 755 |
|
| 756 |
mark_point(); |
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
uid = pr_auth_name2uid(p, PR_TEST_AUTH_NAME); |
| 761 |
ck_assert_msg(uid == PR_TEST_AUTH_UID, "Expected UID %lu, got %lu", |
| 762 |
(unsigned long) PR_TEST_AUTH_UID, (unsigned long) uid); |
| 763 |
ck_assert_msg(name2uid_count == 1, "Expected call count 1, got %u", |
| 764 |
name2uid_count); |
| 765 |
|
| 766 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 767 |
} |
| 768 |
END_TEST |
| 769 |
|
| 770 |
START_TEST (auth_uid2name_test) { |
| 771 |
int res; |
| 772 |
const char *name; |
| 773 |
authtable authtab; |
| 774 |
char *sym_name = "uid2name"; |
| 775 |
|
| 776 |
pr_auth_cache_set(FALSE, PR_AUTH_CACHE_FL_BAD_UID2NAME); |
| 777 |
|
| 778 |
name = pr_auth_uid2name(NULL, -1); |
| 779 |
ck_assert_msg(name == NULL, "Found name unexpectedly: %s", name); |
| 780 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 781 |
errno, strerror(errno)); |
| 782 |
mark_point(); |
| 783 |
|
| 784 |
name = pr_auth_uid2name(p, PR_TEST_AUTH_UID); |
| 785 |
ck_assert_msg(name != NULL, "Failed to find name for UID %lu: %s", |
| 786 |
(unsigned long) PR_TEST_AUTH_UID, strerror(errno)); |
| 787 |
ck_assert_msg(strcmp(name, PR_TEST_AUTH_UID_STR) == 0, |
| 788 |
"Expected name '%s', got '%s'", PR_TEST_AUTH_UID_STR, name); |
| 789 |
ck_assert_msg(uid2name_count == 0, "Expected call count 0, got %u", |
| 790 |
uid2name_count); |
| 791 |
mark_point(); |
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
memset(&authtab, 0, sizeof(authtab)); |
| 796 |
authtab.name = sym_name; |
| 797 |
authtab.handler = handle_uid2name; |
| 798 |
authtab.m = &testsuite_module; |
| 799 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 800 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 801 |
strerror(errno)); |
| 802 |
|
| 803 |
mark_point(); |
| 804 |
|
| 805 |
name = pr_auth_uid2name(p, PR_TEST_AUTH_UID); |
| 806 |
ck_assert_msg(name != NULL, "Expected name, got null"); |
| 807 |
ck_assert_msg(strcmp(name, PR_TEST_AUTH_NAME) == 0, |
| 808 |
"Expected name '%s', got '%s'", PR_TEST_AUTH_NAME, name); |
| 809 |
ck_assert_msg(uid2name_count == 1, "Expected call count 1, got %u", |
| 810 |
uid2name_count); |
| 811 |
|
| 812 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 813 |
} |
| 814 |
END_TEST |
| 815 |
|
| 816 |
START_TEST (auth_setgrent_test) { |
| 817 |
int res; |
| 818 |
authtable authtab; |
| 819 |
char *sym_name = "setgrent"; |
| 820 |
|
| 821 |
pr_auth_setgrent(p); |
| 822 |
ck_assert_msg(setgrent_count == 0, "Expected call count 0, got %u", |
| 823 |
setgrent_count); |
| 824 |
mark_point(); |
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
memset(&authtab, 0, sizeof(authtab)); |
| 829 |
authtab.name = sym_name; |
| 830 |
authtab.handler = handle_setgrent; |
| 831 |
authtab.m = &testsuite_module; |
| 832 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 833 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 834 |
strerror(errno)); |
| 835 |
|
| 836 |
pr_auth_setgrent(p); |
| 837 |
ck_assert_msg(setgrent_count == 1, "Expected call count 1, got %u", |
| 838 |
setgrent_count); |
| 839 |
|
| 840 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 841 |
} |
| 842 |
END_TEST |
| 843 |
|
| 844 |
START_TEST (auth_endgrent_test) { |
| 845 |
int res; |
| 846 |
authtable authtab; |
| 847 |
char *sym_name = "endgrent"; |
| 848 |
|
| 849 |
pr_auth_endgrent(p); |
| 850 |
ck_assert_msg(endgrent_count == 0, "Expected call count 0, got %u", |
| 851 |
endgrent_count); |
| 852 |
mark_point(); |
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
memset(&authtab, 0, sizeof(authtab)); |
| 857 |
authtab.name = sym_name; |
| 858 |
authtab.handler = handle_endgrent; |
| 859 |
authtab.m = &testsuite_module; |
| 860 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 861 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 862 |
strerror(errno)); |
| 863 |
|
| 864 |
pr_auth_endgrent(p); |
| 865 |
ck_assert_msg(endgrent_count == 1, "Expected call count 1, got %u", |
| 866 |
endgrent_count); |
| 867 |
|
| 868 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 869 |
} |
| 870 |
END_TEST |
| 871 |
|
| 872 |
START_TEST (auth_getgrent_test) { |
| 873 |
int res; |
| 874 |
struct group *gr; |
| 875 |
authtable authtab; |
| 876 |
char *sym_name = "getgrent"; |
| 877 |
|
| 878 |
gr = pr_auth_getgrent(NULL); |
| 879 |
ck_assert_msg(gr == NULL, "Found grent unexpectedly"); |
| 880 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 881 |
errno, strerror(errno)); |
| 882 |
|
| 883 |
gr = pr_auth_getgrent(p); |
| 884 |
ck_assert_msg(gr == NULL, "Found grent unexpectedly"); |
| 885 |
ck_assert_msg(getgrent_count == 0, "Expected call count 0, got %u", |
| 886 |
getgrent_count); |
| 887 |
mark_point(); |
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
memset(&authtab, 0, sizeof(authtab)); |
| 892 |
authtab.name = sym_name; |
| 893 |
authtab.handler = handle_getgrent; |
| 894 |
authtab.m = &testsuite_module; |
| 895 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 896 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 897 |
strerror(errno)); |
| 898 |
|
| 899 |
gr = pr_auth_getgrent(p); |
| 900 |
ck_assert_msg(gr != NULL, "Failed to find grent: %s", strerror(errno)); |
| 901 |
ck_assert_msg(getgrent_count == 1, "Expected call count 1, got %u", |
| 902 |
getgrent_count); |
| 903 |
|
| 904 |
gr = pr_auth_getgrent(p); |
| 905 |
ck_assert_msg(gr == NULL, "Failed to avoid grent with bad GID"); |
| 906 |
ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT, |
| 907 |
strerror(errno), errno); |
| 908 |
ck_assert_msg(getgrent_count == 2, "Expected call count 2, got %u", |
| 909 |
getgrent_count); |
| 910 |
|
| 911 |
pr_auth_endgrent(p); |
| 912 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 913 |
} |
| 914 |
END_TEST |
| 915 |
|
| 916 |
START_TEST (auth_getgrnam_test) { |
| 917 |
int res; |
| 918 |
struct group *gr; |
| 919 |
authtable authtab; |
| 920 |
char *sym_name = "getgrnam"; |
| 921 |
|
| 922 |
gr = pr_auth_getgrnam(NULL, NULL); |
| 923 |
ck_assert_msg(gr == NULL, "Found grnam unexpectedly"); |
| 924 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 925 |
errno, strerror(errno)); |
| 926 |
|
| 927 |
gr = pr_auth_getgrnam(p, PR_TEST_AUTH_NAME); |
| 928 |
ck_assert_msg(gr == NULL, "Found grnam unexpectedly"); |
| 929 |
ck_assert_msg(getgrnam_count == 0, "Expected call count 0, got %u", |
| 930 |
getgrnam_count); |
| 931 |
mark_point(); |
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
memset(&authtab, 0, sizeof(authtab)); |
| 936 |
authtab.name = sym_name; |
| 937 |
authtab.handler = handle_getgrnam; |
| 938 |
authtab.m = &testsuite_module; |
| 939 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 940 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 941 |
strerror(errno)); |
| 942 |
|
| 943 |
mark_point(); |
| 944 |
|
| 945 |
gr = pr_auth_getgrnam(p, PR_TEST_AUTH_NOGROUP); |
| 946 |
ck_assert_msg(gr == NULL, "Found group '%s' unexpectedly", |
| 947 |
PR_TEST_AUTH_NOGROUP); |
| 948 |
ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT, |
| 949 |
strerror(errno), errno); |
| 950 |
|
| 951 |
gr = pr_auth_getgrnam(p, PR_TEST_AUTH_NAME); |
| 952 |
ck_assert_msg(gr != NULL, "Failed to find grnam: %s", strerror(errno)); |
| 953 |
ck_assert_msg(getgrnam_count == 2, "Expected call count 2, got %u", |
| 954 |
getgrnam_count); |
| 955 |
|
| 956 |
mark_point(); |
| 957 |
|
| 958 |
gr = pr_auth_getgrnam(p, "other"); |
| 959 |
ck_assert_msg(gr == NULL, "Found grnam for user 'other' unexpectedly"); |
| 960 |
ck_assert_msg(errno == ENOENT, "Failed to set errno to ENOENT, got %d (%s)", |
| 961 |
errno, strerror(errno)); |
| 962 |
ck_assert_msg(getgrnam_count == 3, "Expected call count 3, got %u", |
| 963 |
getgrnam_count); |
| 964 |
|
| 965 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 966 |
} |
| 967 |
END_TEST |
| 968 |
|
| 969 |
START_TEST (auth_getgrgid_test) { |
| 970 |
int res; |
| 971 |
struct group *gr; |
| 972 |
authtable authtab; |
| 973 |
char *sym_name = "getgrgid"; |
| 974 |
|
| 975 |
gr = pr_auth_getgrgid(NULL, -1); |
| 976 |
ck_assert_msg(gr == NULL, "Found grgid unexpectedly"); |
| 977 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 978 |
errno, strerror(errno)); |
| 979 |
|
| 980 |
gr = pr_auth_getgrgid(p, PR_TEST_AUTH_GID); |
| 981 |
ck_assert_msg(gr == NULL, "Found grgid unexpectedly"); |
| 982 |
ck_assert_msg(getgrgid_count == 0, "Expected call count 0, got %u", |
| 983 |
getgrgid_count); |
| 984 |
mark_point(); |
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
memset(&authtab, 0, sizeof(authtab)); |
| 989 |
authtab.name = sym_name; |
| 990 |
authtab.handler = handle_getgrgid; |
| 991 |
authtab.m = &testsuite_module; |
| 992 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 993 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 994 |
strerror(errno)); |
| 995 |
|
| 996 |
mark_point(); |
| 997 |
|
| 998 |
gr = pr_auth_getgrgid(p, PR_TEST_AUTH_GID); |
| 999 |
ck_assert_msg(gr != NULL, "Failed to find grgid: %s", strerror(errno)); |
| 1000 |
ck_assert_msg(getgrgid_count == 1, "Expected call count 1, got %u", |
| 1001 |
getgrgid_count); |
| 1002 |
|
| 1003 |
gr = pr_auth_getgrgid(p, PR_TEST_AUTH_NOGID); |
| 1004 |
ck_assert_msg(gr == NULL, "Found grgid for NOGID unexpectedly"); |
| 1005 |
ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT, |
| 1006 |
strerror(errno), errno); |
| 1007 |
|
| 1008 |
mark_point(); |
| 1009 |
|
| 1010 |
gr = pr_auth_getgrgid(p, 5); |
| 1011 |
ck_assert_msg(gr == NULL, "Found grgid for GID 5 unexpectedly"); |
| 1012 |
ck_assert_msg(errno == ENOENT, "Expected ENOENT (%d), got %s (%d)", ENOENT, |
| 1013 |
strerror(errno), errno); |
| 1014 |
|
| 1015 |
ck_assert_msg(getgrgid_count == 3, "Expected call count 3, got %u", |
| 1016 |
getgrgid_count); |
| 1017 |
|
| 1018 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 1019 |
} |
| 1020 |
END_TEST |
| 1021 |
|
| 1022 |
START_TEST (auth_name2gid_test) { |
| 1023 |
int res; |
| 1024 |
gid_t gid; |
| 1025 |
authtable authtab; |
| 1026 |
char *sym_name = "name2gid"; |
| 1027 |
|
| 1028 |
pr_auth_cache_set(FALSE, PR_AUTH_CACHE_FL_BAD_NAME2GID); |
| 1029 |
|
| 1030 |
gid = pr_auth_name2gid(NULL, NULL); |
| 1031 |
ck_assert_msg(gid == (gid_t) -1, "Found GID unexpectedly"); |
| 1032 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 1033 |
errno, strerror(errno)); |
| 1034 |
|
| 1035 |
gid = pr_auth_name2gid(p, PR_TEST_AUTH_NAME); |
| 1036 |
ck_assert_msg(gid == (gid_t) -1, "Found GID unexpectedly"); |
| 1037 |
ck_assert_msg(name2gid_count == 0, "Expected call count 0, got %u", |
| 1038 |
name2gid_count); |
| 1039 |
mark_point(); |
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
memset(&authtab, 0, sizeof(authtab)); |
| 1044 |
authtab.name = sym_name; |
| 1045 |
authtab.handler = handle_name2gid; |
| 1046 |
authtab.m = &testsuite_module; |
| 1047 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 1048 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 1049 |
strerror(errno)); |
| 1050 |
|
| 1051 |
mark_point(); |
| 1052 |
|
| 1053 |
gid = pr_auth_name2gid(p, PR_TEST_AUTH_NAME); |
| 1054 |
ck_assert_msg(gid == PR_TEST_AUTH_GID, "Expected GID %lu, got %lu", |
| 1055 |
(unsigned long) PR_TEST_AUTH_GID, (unsigned long) gid); |
| 1056 |
ck_assert_msg(name2gid_count == 1, "Expected call count 1, got %u", |
| 1057 |
name2gid_count); |
| 1058 |
|
| 1059 |
mark_point(); |
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
gid = pr_auth_name2gid(p, PR_TEST_AUTH_NAME); |
| 1064 |
ck_assert_msg(gid == PR_TEST_AUTH_GID, "Expected GID %lu, got %lu", |
| 1065 |
(unsigned long) PR_TEST_AUTH_GID, (unsigned long) gid); |
| 1066 |
ck_assert_msg(name2gid_count == 1, "Expected call count 1, got %u", |
| 1067 |
name2gid_count); |
| 1068 |
|
| 1069 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 1070 |
} |
| 1071 |
END_TEST |
| 1072 |
|
| 1073 |
START_TEST (auth_gid2name_test) { |
| 1074 |
int res; |
| 1075 |
const char *name; |
| 1076 |
authtable authtab; |
| 1077 |
char *sym_name = "gid2name"; |
| 1078 |
|
| 1079 |
pr_auth_cache_set(FALSE, PR_AUTH_CACHE_FL_BAD_GID2NAME); |
| 1080 |
|
| 1081 |
name = pr_auth_gid2name(NULL, -1); |
| 1082 |
ck_assert_msg(name == NULL, "Found name unexpectedly: %s", name); |
| 1083 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 1084 |
errno, strerror(errno)); |
| 1085 |
mark_point(); |
| 1086 |
|
| 1087 |
name = pr_auth_gid2name(p, PR_TEST_AUTH_GID); |
| 1088 |
ck_assert_msg(name != NULL, "Failed to find name for GID %lu: %s", |
| 1089 |
(unsigned long) PR_TEST_AUTH_GID, strerror(errno)); |
| 1090 |
ck_assert_msg(strcmp(name, PR_TEST_AUTH_GID_STR) == 0, |
| 1091 |
"Expected name '%s', got '%s'", PR_TEST_AUTH_GID_STR, name); |
| 1092 |
ck_assert_msg(gid2name_count == 0, "Expected call count 0, got %u", |
| 1093 |
gid2name_count); |
| 1094 |
mark_point(); |
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
memset(&authtab, 0, sizeof(authtab)); |
| 1099 |
authtab.name = sym_name; |
| 1100 |
authtab.handler = handle_gid2name; |
| 1101 |
authtab.m = &testsuite_module; |
| 1102 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 1103 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 1104 |
strerror(errno)); |
| 1105 |
|
| 1106 |
mark_point(); |
| 1107 |
|
| 1108 |
name = pr_auth_gid2name(p, PR_TEST_AUTH_GID); |
| 1109 |
ck_assert_msg(name != NULL, "Expected name, got null"); |
| 1110 |
ck_assert_msg(strcmp(name, PR_TEST_AUTH_NAME) == 0, |
| 1111 |
"Expected name '%s', got '%s'", PR_TEST_AUTH_NAME, name); |
| 1112 |
ck_assert_msg(gid2name_count == 1, "Expected call count 1, got %u", |
| 1113 |
gid2name_count); |
| 1114 |
|
| 1115 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 1116 |
} |
| 1117 |
END_TEST |
| 1118 |
|
| 1119 |
START_TEST (auth_getgroups_test) { |
| 1120 |
int res; |
| 1121 |
array_header *gids = NULL, *names = NULL; |
| 1122 |
authtable authtab; |
| 1123 |
char *sym_name = "getgroups"; |
| 1124 |
|
| 1125 |
res = pr_auth_getgroups(NULL, NULL, NULL, NULL); |
| 1126 |
ck_assert_msg(res < 0, "Failed to handle null arguments"); |
| 1127 |
ck_assert_msg(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", |
| 1128 |
errno, strerror(errno)); |
| 1129 |
|
| 1130 |
res = pr_auth_getgroups(p, PR_TEST_AUTH_NAME, &gids, NULL); |
| 1131 |
ck_assert_msg(res < 0, "Found groups for '%s' unexpectedly", PR_TEST_AUTH_NAME); |
| 1132 |
ck_assert_msg(getgroups_count == 0, "Expected call count 0, got %u", |
| 1133 |
getgroups_count); |
| 1134 |
mark_point(); |
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
memset(&authtab, 0, sizeof(authtab)); |
| 1139 |
authtab.name = sym_name; |
| 1140 |
authtab.handler = handle_getgroups; |
| 1141 |
authtab.m = &testsuite_module; |
| 1142 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 1143 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 1144 |
strerror(errno)); |
| 1145 |
|
| 1146 |
mark_point(); |
| 1147 |
|
| 1148 |
res = pr_auth_getgroups(p, PR_TEST_AUTH_NAME, &gids, &names); |
| 1149 |
ck_assert_msg(res > 0, "Expected group count 1 for '%s', got %d: %s", |
| 1150 |
PR_TEST_AUTH_NAME, res, strerror(errno)); |
| 1151 |
ck_assert_msg(getgroups_count == 1, "Expected call count 1, got %u", |
| 1152 |
getgroups_count); |
| 1153 |
|
| 1154 |
res = pr_auth_getgroups(p, "other", &gids, &names); |
| 1155 |
ck_assert_msg(res < 0, "Found groups for 'other' unexpectedly"); |
| 1156 |
ck_assert_msg(getgroups_count == 2, "Expected call count 2, got %u", |
| 1157 |
getgroups_count); |
| 1158 |
|
| 1159 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 1160 |
} |
| 1161 |
END_TEST |
| 1162 |
|
| 1163 |
START_TEST (auth_cache_uid2name_test) { |
| 1164 |
int res; |
| 1165 |
const char *name; |
| 1166 |
authtable authtab; |
| 1167 |
char *sym_name = "uid2name"; |
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
memset(&authtab, 0, sizeof(authtab)); |
| 1172 |
authtab.name = sym_name; |
| 1173 |
authtab.handler = handle_uid2name; |
| 1174 |
authtab.m = &testsuite_module; |
| 1175 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 1176 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 1177 |
strerror(errno)); |
| 1178 |
|
| 1179 |
mark_point(); |
| 1180 |
|
| 1181 |
name = pr_auth_uid2name(p, PR_TEST_AUTH_UID); |
| 1182 |
ck_assert_msg(name != NULL, "Expected name, got null"); |
| 1183 |
ck_assert_msg(strcmp(name, PR_TEST_AUTH_NAME) == 0, |
| 1184 |
"Expected name '%s', got '%s'", PR_TEST_AUTH_NAME, name); |
| 1185 |
ck_assert_msg(uid2name_count == 1, "Expected call count 1, got %u", |
| 1186 |
uid2name_count); |
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
name = pr_auth_uid2name(p, PR_TEST_AUTH_UID); |
| 1191 |
ck_assert_msg(name != NULL, "Expected name, got null"); |
| 1192 |
ck_assert_msg(strcmp(name, PR_TEST_AUTH_NAME) == 0, |
| 1193 |
"Expected name '%s', got '%s'", PR_TEST_AUTH_NAME, name); |
| 1194 |
ck_assert_msg(uid2name_count == 1, "Expected call count 1, got %u", |
| 1195 |
uid2name_count); |
| 1196 |
|
| 1197 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 1198 |
} |
| 1199 |
END_TEST |
| 1200 |
|
| 1201 |
START_TEST (auth_cache_gid2name_test) { |
| 1202 |
int res; |
| 1203 |
const char *name; |
| 1204 |
authtable authtab; |
| 1205 |
char *sym_name = "gid2name"; |
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
memset(&authtab, 0, sizeof(authtab)); |
| 1210 |
authtab.name = sym_name; |
| 1211 |
authtab.handler = handle_gid2name; |
| 1212 |
authtab.m = &testsuite_module; |
| 1213 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 1214 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 1215 |
strerror(errno)); |
| 1216 |
|
| 1217 |
mark_point(); |
| 1218 |
|
| 1219 |
name = pr_auth_gid2name(p, PR_TEST_AUTH_GID); |
| 1220 |
ck_assert_msg(name != NULL, "Expected name, got null"); |
| 1221 |
ck_assert_msg(strcmp(name, PR_TEST_AUTH_NAME) == 0, |
| 1222 |
"Expected name '%s', got '%s'", PR_TEST_AUTH_NAME, name); |
| 1223 |
ck_assert_msg(gid2name_count == 1, "Expected call count 1, got %u", |
| 1224 |
gid2name_count); |
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
name = pr_auth_gid2name(p, PR_TEST_AUTH_GID); |
| 1229 |
ck_assert_msg(name != NULL, "Expected name, got null"); |
| 1230 |
ck_assert_msg(strcmp(name, PR_TEST_AUTH_NAME) == 0, |
| 1231 |
"Expected name '%s', got '%s'", PR_TEST_AUTH_NAME, name); |
| 1232 |
ck_assert_msg(gid2name_count == 1, "Expected call count 1, got %u", |
| 1233 |
gid2name_count); |
| 1234 |
|
| 1235 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 1236 |
} |
| 1237 |
END_TEST |
| 1238 |
|
| 1239 |
START_TEST (auth_cache_uid2name_failed_test) { |
| 1240 |
int res; |
| 1241 |
const char *name; |
| 1242 |
authtable authtab; |
| 1243 |
char *sym_name = "uid2name"; |
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
memset(&authtab, 0, sizeof(authtab)); |
| 1248 |
authtab.name = sym_name; |
| 1249 |
authtab.handler = decline_uid2name; |
| 1250 |
authtab.m = &testsuite_module; |
| 1251 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 1252 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 1253 |
strerror(errno)); |
| 1254 |
|
| 1255 |
mark_point(); |
| 1256 |
|
| 1257 |
name = pr_auth_uid2name(p, PR_TEST_AUTH_UID); |
| 1258 |
ck_assert_msg(name != NULL, "Expected name, got null"); |
| 1259 |
ck_assert_msg(strcmp(name, PR_TEST_AUTH_UID_STR) == 0, |
| 1260 |
"Expected name '%s', got '%s'", PR_TEST_AUTH_UID_STR, name); |
| 1261 |
ck_assert_msg(uid2name_count == 1, "Expected call count 1, got %u", |
| 1262 |
uid2name_count); |
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
name = pr_auth_uid2name(p, PR_TEST_AUTH_UID); |
| 1267 |
ck_assert_msg(name != NULL, "Expected name, got null"); |
| 1268 |
ck_assert_msg(strcmp(name, PR_TEST_AUTH_UID_STR) == 0, |
| 1269 |
"Expected name '%s', got '%s'", PR_TEST_AUTH_UID_STR, name); |
| 1270 |
ck_assert_msg(uid2name_count == 1, "Expected call count 1, got %u", |
| 1271 |
uid2name_count); |
| 1272 |
|
| 1273 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 1274 |
} |
| 1275 |
END_TEST |
| 1276 |
|
| 1277 |
START_TEST (auth_cache_gid2name_failed_test) { |
| 1278 |
int res; |
| 1279 |
const char *name; |
| 1280 |
authtable authtab; |
| 1281 |
char *sym_name = "gid2name"; |
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
memset(&authtab, 0, sizeof(authtab)); |
| 1286 |
authtab.name = sym_name; |
| 1287 |
authtab.handler = decline_gid2name; |
| 1288 |
authtab.m = &testsuite_module; |
| 1289 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 1290 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 1291 |
strerror(errno)); |
| 1292 |
|
| 1293 |
mark_point(); |
| 1294 |
|
| 1295 |
name = pr_auth_gid2name(p, PR_TEST_AUTH_GID); |
| 1296 |
ck_assert_msg(name != NULL, "Expected name, got null"); |
| 1297 |
ck_assert_msg(strcmp(name, PR_TEST_AUTH_GID_STR) == 0, |
| 1298 |
"Expected name '%s', got '%s'", PR_TEST_AUTH_GID_STR, name); |
| 1299 |
ck_assert_msg(gid2name_count == 1, "Expected call count 1, got %u", |
| 1300 |
gid2name_count); |
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
name = pr_auth_gid2name(p, PR_TEST_AUTH_GID); |
| 1305 |
ck_assert_msg(name != NULL, "Expected name, got null"); |
| 1306 |
ck_assert_msg(strcmp(name, PR_TEST_AUTH_GID_STR) == 0, |
| 1307 |
"Expected name '%s', got '%s'", PR_TEST_AUTH_GID_STR, name); |
| 1308 |
ck_assert_msg(gid2name_count == 1, "Expected call count 1, got %u", |
| 1309 |
gid2name_count); |
| 1310 |
|
| 1311 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 1312 |
} |
| 1313 |
END_TEST |
| 1314 |
|
| 1315 |
START_TEST (auth_cache_name2uid_failed_test) { |
| 1316 |
int res; |
| 1317 |
uid_t uid; |
| 1318 |
authtable authtab; |
| 1319 |
char *sym_name = "name2uid"; |
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
memset(&authtab, 0, sizeof(authtab)); |
| 1324 |
authtab.name = sym_name; |
| 1325 |
authtab.handler = decline_name2uid; |
| 1326 |
authtab.m = &testsuite_module; |
| 1327 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 1328 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 1329 |
strerror(errno)); |
| 1330 |
|
| 1331 |
mark_point(); |
| 1332 |
|
| 1333 |
uid = pr_auth_name2uid(p, PR_TEST_AUTH_NAME); |
| 1334 |
ck_assert_msg(uid == (uid_t) -1, "Expected -1, got %lu", (unsigned long) uid); |
| 1335 |
ck_assert_msg(name2uid_count == 1, "Expected call count 1, got %u", |
| 1336 |
name2uid_count); |
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
uid = pr_auth_name2uid(p, PR_TEST_AUTH_NAME); |
| 1341 |
ck_assert_msg(uid == (uid_t) -1, "Expected -1, got %lu", (unsigned long) uid); |
| 1342 |
ck_assert_msg(name2uid_count == 1, "Expected call count 1, got %u", |
| 1343 |
name2uid_count); |
| 1344 |
|
| 1345 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 1346 |
} |
| 1347 |
END_TEST |
| 1348 |
|
| 1349 |
START_TEST (auth_cache_name2gid_failed_test) { |
| 1350 |
int res; |
| 1351 |
gid_t gid; |
| 1352 |
authtable authtab; |
| 1353 |
char *sym_name = "name2gid"; |
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
memset(&authtab, 0, sizeof(authtab)); |
| 1358 |
authtab.name = sym_name; |
| 1359 |
authtab.handler = decline_name2gid; |
| 1360 |
authtab.m = &testsuite_module; |
| 1361 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 1362 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 1363 |
strerror(errno)); |
| 1364 |
|
| 1365 |
mark_point(); |
| 1366 |
|
| 1367 |
gid = pr_auth_name2gid(p, PR_TEST_AUTH_NAME); |
| 1368 |
ck_assert_msg(gid == (gid_t) -1, "Expected -1, got %lu", (unsigned long) gid); |
| 1369 |
ck_assert_msg(name2gid_count == 1, "Expected call count 1, got %u", |
| 1370 |
name2gid_count); |
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
gid = pr_auth_name2gid(p, PR_TEST_AUTH_NAME); |
| 1375 |
ck_assert_msg(gid == (gid_t) -1, "Expected -1, got %lu", (unsigned long) gid); |
| 1376 |
ck_assert_msg(name2gid_count == 1, "Expected call count 1, got %u", |
| 1377 |
name2gid_count); |
| 1378 |
|
| 1379 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 1380 |
} |
| 1381 |
END_TEST |
| 1382 |
|
| 1383 |
START_TEST (auth_cache_clear_test) { |
| 1384 |
int res; |
| 1385 |
gid_t gid; |
| 1386 |
authtable authtab; |
| 1387 |
char *sym_name = "name2gid"; |
| 1388 |
|
| 1389 |
mark_point(); |
| 1390 |
pr_auth_cache_clear(); |
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
memset(&authtab, 0, sizeof(authtab)); |
| 1395 |
authtab.name = sym_name; |
| 1396 |
authtab.handler = decline_name2gid; |
| 1397 |
authtab.m = &testsuite_module; |
| 1398 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 1399 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 1400 |
strerror(errno)); |
| 1401 |
|
| 1402 |
mark_point(); |
| 1403 |
gid = pr_auth_name2gid(p, PR_TEST_AUTH_NAME); |
| 1404 |
ck_assert_msg(gid == (gid_t) -1, "Expected -1, got %lu", (unsigned long) gid); |
| 1405 |
ck_assert_msg(name2gid_count == 1, "Expected call count 1, got %u", |
| 1406 |
name2gid_count); |
| 1407 |
|
| 1408 |
mark_point(); |
| 1409 |
pr_auth_cache_clear(); |
| 1410 |
} |
| 1411 |
END_TEST |
| 1412 |
|
| 1413 |
START_TEST (auth_cache_set_test) { |
| 1414 |
int res; |
| 1415 |
unsigned int flags = PR_AUTH_CACHE_FL_UID2NAME|PR_AUTH_CACHE_FL_GID2NAME|PR_AUTH_CACHE_FL_AUTH_MODULE|PR_AUTH_CACHE_FL_NAME2UID|PR_AUTH_CACHE_FL_NAME2GID|PR_AUTH_CACHE_FL_BAD_UID2NAME|PR_AUTH_CACHE_FL_BAD_GID2NAME|PR_AUTH_CACHE_FL_BAD_NAME2UID|PR_AUTH_CACHE_FL_BAD_NAME2GID; |
| 1416 |
|
| 1417 |
res = pr_auth_cache_set(-1, 0); |
| 1418 |
ck_assert_msg(res < 0, "Failed to handle invalid setting"); |
| 1419 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 1420 |
strerror(errno), errno); |
| 1421 |
|
| 1422 |
res = pr_auth_cache_set(TRUE, flags); |
| 1423 |
ck_assert_msg(res == 0, "Failed to enable all auth cache settings: %s", |
| 1424 |
strerror(errno)); |
| 1425 |
|
| 1426 |
res = pr_auth_cache_set(FALSE, flags); |
| 1427 |
ck_assert_msg(res == 0, "Failed to disable all auth cache settings: %s", |
| 1428 |
strerror(errno)); |
| 1429 |
|
| 1430 |
(void) pr_auth_cache_set(TRUE, PR_AUTH_CACHE_FL_DEFAULT); |
| 1431 |
} |
| 1432 |
END_TEST |
| 1433 |
|
| 1434 |
START_TEST (auth_clear_auth_only_module_test) { |
| 1435 |
int res; |
| 1436 |
|
| 1437 |
(void) pr_auth_cache_set(TRUE, PR_AUTH_CACHE_FL_AUTH_MODULE); |
| 1438 |
|
| 1439 |
res = pr_auth_clear_auth_only_modules(); |
| 1440 |
ck_assert_msg(res < 0, "Failed to handle no auth module list"); |
| 1441 |
ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM, |
| 1442 |
strerror(errno), errno); |
| 1443 |
} |
| 1444 |
END_TEST |
| 1445 |
|
| 1446 |
START_TEST (auth_add_auth_only_module_test) { |
| 1447 |
int res; |
| 1448 |
const char *name = "foo.bar"; |
| 1449 |
|
| 1450 |
(void) pr_auth_cache_set(TRUE, PR_AUTH_CACHE_FL_AUTH_MODULE); |
| 1451 |
|
| 1452 |
res = pr_auth_add_auth_only_module(NULL); |
| 1453 |
ck_assert_msg(res < 0, "Failed to handle null arguments"); |
| 1454 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 1455 |
strerror(errno), errno); |
| 1456 |
|
| 1457 |
res = pr_auth_add_auth_only_module(name); |
| 1458 |
ck_assert_msg(res == 0, "Failed to add auth-only module '%s': %s", name, |
| 1459 |
strerror(errno)); |
| 1460 |
|
| 1461 |
res = pr_auth_add_auth_only_module(name); |
| 1462 |
ck_assert_msg(res < 0, "Failed to handle duplicate auth-only module"); |
| 1463 |
ck_assert_msg(errno == EEXIST, "Expected EEXIST (%d), got %s (%d)", EEXIST, |
| 1464 |
strerror(errno), errno); |
| 1465 |
|
| 1466 |
res = pr_auth_clear_auth_only_modules(); |
| 1467 |
ck_assert_msg(res == 0, "Failed to clear auth-only modules: %s", |
| 1468 |
strerror(errno)); |
| 1469 |
} |
| 1470 |
END_TEST |
| 1471 |
|
| 1472 |
START_TEST (auth_remove_auth_only_module_test) { |
| 1473 |
int res; |
| 1474 |
const char *name = "foo.bar"; |
| 1475 |
|
| 1476 |
(void) pr_auth_cache_set(TRUE, PR_AUTH_CACHE_FL_AUTH_MODULE); |
| 1477 |
|
| 1478 |
res = pr_auth_remove_auth_only_module(NULL); |
| 1479 |
ck_assert_msg(res < 0, "Failed to handle null arguments"); |
| 1480 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 1481 |
strerror(errno), errno); |
| 1482 |
|
| 1483 |
res = pr_auth_remove_auth_only_module(name); |
| 1484 |
ck_assert_msg(res < 0, "Failed to handle empty auth-only module list"); |
| 1485 |
ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM, |
| 1486 |
strerror(errno), errno); |
| 1487 |
|
| 1488 |
res = pr_auth_add_auth_only_module(name); |
| 1489 |
ck_assert_msg(res == 0, "Failed to add auth-only module '%s': %s", name, |
| 1490 |
strerror(errno)); |
| 1491 |
|
| 1492 |
res = pr_auth_remove_auth_only_module(name); |
| 1493 |
ck_assert_msg(res == 0, "Failed to remove auth-only module '%s': %s", name, |
| 1494 |
strerror(errno)); |
| 1495 |
|
| 1496 |
(void) pr_auth_clear_auth_only_modules(); |
| 1497 |
} |
| 1498 |
END_TEST |
| 1499 |
|
| 1500 |
START_TEST (auth_authenticate_test) { |
| 1501 |
int res; |
| 1502 |
authtable authtab; |
| 1503 |
char *sym_name = "auth"; |
| 1504 |
|
| 1505 |
res = pr_auth_authenticate(NULL, NULL, NULL); |
| 1506 |
ck_assert_msg(res < 0, "Failed to handle null arguments"); |
| 1507 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 1508 |
strerror(errno), errno); |
| 1509 |
|
| 1510 |
res = pr_auth_authenticate(p, NULL, NULL); |
| 1511 |
ck_assert_msg(res < 0, "Failed to handle null name"); |
| 1512 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 1513 |
strerror(errno), errno); |
| 1514 |
|
| 1515 |
res = pr_auth_authenticate(p, PR_TEST_AUTH_NAME, NULL); |
| 1516 |
ck_assert_msg(res < 0, "Failed to handle null password"); |
| 1517 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 1518 |
strerror(errno), errno); |
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
memset(&authtab, 0, sizeof(authtab)); |
| 1523 |
authtab.name = sym_name; |
| 1524 |
authtab.handler = handle_authn; |
| 1525 |
authtab.m = &testsuite_module; |
| 1526 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 1527 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 1528 |
strerror(errno)); |
| 1529 |
|
| 1530 |
res = pr_auth_authenticate(p, "other", "foobar"); |
| 1531 |
ck_assert_msg(res == PR_AUTH_NOPWD, |
| 1532 |
"Authenticated user 'other' unexpectedly (expected %d, got %d)", |
| 1533 |
PR_AUTH_NOPWD, res); |
| 1534 |
|
| 1535 |
res = pr_auth_authenticate(p, PR_TEST_AUTH_NAME, "foobar"); |
| 1536 |
ck_assert_msg(res == PR_AUTH_BADPWD, |
| 1537 |
"Authenticated user '%s' unexpectedly (expected %d, got %d)", |
| 1538 |
PR_TEST_AUTH_NAME, PR_AUTH_BADPWD, res); |
| 1539 |
|
| 1540 |
res = pr_auth_authenticate(p, PR_TEST_AUTH_NAME, PR_TEST_AUTH_PASSWD); |
| 1541 |
ck_assert_msg(res == PR_AUTH_OK, |
| 1542 |
"Failed to authenticate user '%s' (expected %d, got %d)", |
| 1543 |
PR_TEST_AUTH_NAME, PR_AUTH_OK, res); |
| 1544 |
|
| 1545 |
authtab.auth_flags |= PR_AUTH_FL_REQUIRED; |
| 1546 |
res = pr_auth_authenticate(p, PR_TEST_AUTH_NAME, PR_TEST_AUTH_PASSWD); |
| 1547 |
ck_assert_msg(res == PR_AUTH_OK, |
| 1548 |
"Failed to authenticate user '%s' (expected %d, got %d)", |
| 1549 |
PR_TEST_AUTH_NAME, PR_AUTH_OK, res); |
| 1550 |
authtab.auth_flags &= ~PR_AUTH_FL_REQUIRED; |
| 1551 |
|
| 1552 |
(void) pr_auth_cache_set(TRUE, PR_AUTH_CACHE_FL_AUTH_MODULE); |
| 1553 |
|
| 1554 |
res = pr_auth_add_auth_only_module("foo.bar"); |
| 1555 |
ck_assert_msg(res == 0, "Failed to add auth-only module: %s", strerror(errno)); |
| 1556 |
|
| 1557 |
res = pr_auth_add_auth_only_module("mod_testsuite.c"); |
| 1558 |
ck_assert_msg(res == 0, "Failed to add auth-only module: %s", strerror(errno)); |
| 1559 |
|
| 1560 |
res = pr_module_load(&testsuite_module); |
| 1561 |
ck_assert_msg(res == 0, "Failed to load module: %s", strerror(errno)); |
| 1562 |
|
| 1563 |
res = pr_auth_authenticate(p, "foo", "bar"); |
| 1564 |
ck_assert_msg(res == PR_AUTH_NOPWD, |
| 1565 |
"Failed to handle unknown user 'foo' (expected %d, got %d)", PR_AUTH_NOPWD, |
| 1566 |
res); |
| 1567 |
|
| 1568 |
res = pr_auth_authenticate(p, PR_TEST_AUTH_NAME, "bar"); |
| 1569 |
ck_assert_msg(res == PR_AUTH_BADPWD, |
| 1570 |
"Failed to handle user '%s' with bad password (expected %d, got %d)", |
| 1571 |
PR_TEST_AUTH_NAME, PR_AUTH_BADPWD, res); |
| 1572 |
|
| 1573 |
res = pr_auth_authenticate(p, PR_TEST_AUTH_NAME, PR_TEST_AUTH_PASSWD); |
| 1574 |
ck_assert_msg(res == PR_AUTH_OK, |
| 1575 |
"Failed to authenticate user '%s' (expected %d, got %d)", |
| 1576 |
PR_TEST_AUTH_NAME, PR_AUTH_OK, res); |
| 1577 |
|
| 1578 |
authn_rfc2228 = TRUE; |
| 1579 |
res = pr_auth_authenticate(p, PR_TEST_AUTH_NAME, PR_TEST_AUTH_PASSWD); |
| 1580 |
ck_assert_msg(res == PR_AUTH_RFC2228_OK, |
| 1581 |
"Failed to authenticate user '%s' (expected %d, got %d)", |
| 1582 |
PR_TEST_AUTH_NAME, PR_AUTH_RFC2228_OK, res); |
| 1583 |
|
| 1584 |
pr_auth_clear_auth_only_modules(); |
| 1585 |
pr_module_unload(&testsuite_module); |
| 1586 |
|
| 1587 |
authn_rfc2228 = TRUE; |
| 1588 |
res = pr_auth_authenticate(p, PR_TEST_AUTH_NAME, PR_TEST_AUTH_PASSWD); |
| 1589 |
ck_assert_msg(res == PR_AUTH_RFC2228_OK, |
| 1590 |
"Failed to authenticate user '%s' (expected %d, got %d)", |
| 1591 |
PR_TEST_AUTH_NAME, PR_AUTH_RFC2228_OK, res); |
| 1592 |
|
| 1593 |
authn_rfc2228 = FALSE; |
| 1594 |
} |
| 1595 |
END_TEST |
| 1596 |
|
| 1597 |
START_TEST (auth_authorize_test) { |
| 1598 |
int res; |
| 1599 |
authtable authtab; |
| 1600 |
char *sym_name = "authorize"; |
| 1601 |
|
| 1602 |
res = pr_auth_authorize(NULL, NULL); |
| 1603 |
ck_assert_msg(res < 0, "Failed to handle null arguments"); |
| 1604 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 1605 |
strerror(errno), errno); |
| 1606 |
|
| 1607 |
res = pr_auth_authorize(p, NULL); |
| 1608 |
ck_assert_msg(res < 0, "Failed to handle null name"); |
| 1609 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 1610 |
strerror(errno), errno); |
| 1611 |
|
| 1612 |
res = pr_auth_authorize(p, PR_TEST_AUTH_NAME); |
| 1613 |
ck_assert_msg(res > 0, "Failed to handle missing handler"); |
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
memset(&authtab, 0, sizeof(authtab)); |
| 1618 |
authtab.name = sym_name; |
| 1619 |
authtab.handler = handle_authz; |
| 1620 |
authtab.m = &testsuite_module; |
| 1621 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 1622 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 1623 |
strerror(errno)); |
| 1624 |
|
| 1625 |
res = pr_auth_authorize(p, "other"); |
| 1626 |
ck_assert_msg(res == PR_AUTH_NOPWD, |
| 1627 |
"Authorized user 'other' unexpectedly (expected %d, got %d)", |
| 1628 |
PR_AUTH_NOPWD, res); |
| 1629 |
|
| 1630 |
res = pr_auth_authorize(p, PR_TEST_AUTH_NAME); |
| 1631 |
ck_assert_msg(res == PR_AUTH_OK, |
| 1632 |
"Failed to authorize user '%s' (expected %d, got %d)", |
| 1633 |
PR_TEST_AUTH_NAME, PR_AUTH_OK, res); |
| 1634 |
|
| 1635 |
(void) pr_auth_cache_set(TRUE, PR_AUTH_CACHE_FL_AUTH_MODULE); |
| 1636 |
|
| 1637 |
res = pr_auth_add_auth_only_module("foo.bar"); |
| 1638 |
ck_assert_msg(res == 0, "Failed to add auth-only module: %s", strerror(errno)); |
| 1639 |
|
| 1640 |
res = pr_auth_add_auth_only_module(testsuite_module.name); |
| 1641 |
ck_assert_msg(res == 0, "Failed to add auth-only module: %s", strerror(errno)); |
| 1642 |
|
| 1643 |
res = pr_auth_authorize(p, PR_TEST_AUTH_NAME); |
| 1644 |
ck_assert_msg(res == PR_AUTH_OK, |
| 1645 |
"Failed to authorize user '%s' (expected %d, got %d)", |
| 1646 |
PR_TEST_AUTH_NAME, PR_AUTH_OK, res); |
| 1647 |
|
| 1648 |
(void) pr_auth_clear_auth_only_modules(); |
| 1649 |
} |
| 1650 |
END_TEST |
| 1651 |
|
| 1652 |
static int test_check_errorcode = PR_AUTH_BADPWD; |
| 1653 |
|
| 1654 |
MODRET handle_check_error(cmd_rec *cmd) { |
| 1655 |
return PR_ERROR_INT(cmd, test_check_errorcode); |
| 1656 |
} |
| 1657 |
|
| 1658 |
START_TEST (auth_check_errors_test) { |
| 1659 |
register unsigned int i; |
| 1660 |
int res; |
| 1661 |
const char *cleartext_passwd, *name; |
| 1662 |
authtable authtab; |
| 1663 |
char *sym_name = "check"; |
| 1664 |
int test_errorcodes[] = { |
| 1665 |
PR_AUTH_ERROR, |
| 1666 |
PR_AUTH_NOPWD, |
| 1667 |
PR_AUTH_BADPWD, |
| 1668 |
PR_AUTH_AGEPWD, |
| 1669 |
PR_AUTH_DISABLEDPWD, |
| 1670 |
PR_AUTH_CRED_INSUFFICIENT, |
| 1671 |
PR_AUTH_CRED_UNAVAIL, |
| 1672 |
PR_AUTH_CRED_ERROR, |
| 1673 |
PR_AUTH_INFO_UNAVAIL, |
| 1674 |
PR_AUTH_MAX_ATTEMPTS_EXCEEDED, |
| 1675 |
PR_AUTH_INIT_ERROR, |
| 1676 |
PR_AUTH_NEW_TOKEN_REQUIRED, |
| 1677 |
0 |
| 1678 |
}; |
| 1679 |
|
| 1680 |
mark_point(); |
| 1681 |
res = pr_auth_check(NULL, NULL, NULL, NULL); |
| 1682 |
ck_assert_msg(res < 0, "Failed to handle null arguments"); |
| 1683 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 1684 |
strerror(errno), errno); |
| 1685 |
|
| 1686 |
mark_point(); |
| 1687 |
res = pr_auth_check(p, NULL, NULL, NULL); |
| 1688 |
ck_assert_msg(res < 0, "Failed to handle null name"); |
| 1689 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 1690 |
strerror(errno), errno); |
| 1691 |
|
| 1692 |
mark_point(); |
| 1693 |
name = PR_TEST_AUTH_NAME; |
| 1694 |
res = pr_auth_check(p, NULL, name, NULL); |
| 1695 |
ck_assert_msg(res < 0, "Failed to handle null cleartext password"); |
| 1696 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 1697 |
strerror(errno), errno); |
| 1698 |
|
| 1699 |
mark_point(); |
| 1700 |
cleartext_passwd = PR_TEST_AUTH_PASSWD; |
| 1701 |
res = pr_auth_check(p, NULL, name, cleartext_passwd); |
| 1702 |
ck_assert_msg(res == PR_AUTH_BADPWD, "Expected %d, got %d", PR_AUTH_BADPWD, |
| 1703 |
res); |
| 1704 |
|
| 1705 |
res = pr_module_load(&testsuite_module); |
| 1706 |
ck_assert_msg(res == 0, "Failed to load module: %s", strerror(errno)); |
| 1707 |
|
| 1708 |
memset(&authtab, 0, sizeof(authtab)); |
| 1709 |
authtab.name = sym_name; |
| 1710 |
authtab.handler = handle_check_error; |
| 1711 |
authtab.m = &testsuite_module; |
| 1712 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 1713 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 1714 |
strerror(errno)); |
| 1715 |
|
| 1716 |
(void) pr_auth_cache_set(TRUE, PR_AUTH_CACHE_FL_AUTH_MODULE); |
| 1717 |
res = pr_auth_add_auth_only_module("mod_testsuite.c"); |
| 1718 |
ck_assert_msg(res == 0, "Failed to add auth-only module: %s", strerror(errno)); |
| 1719 |
|
| 1720 |
for (i = 0; test_errorcodes[i] != 0; i++) { |
| 1721 |
mark_point(); |
| 1722 |
test_check_errorcode = test_errorcodes[i]; |
| 1723 |
res = pr_auth_check(p, "", name, cleartext_passwd); |
| 1724 |
ck_assert_msg(res == test_check_errorcode, "Expected %d, got %d", |
| 1725 |
test_check_errorcode, res); |
| 1726 |
} |
| 1727 |
|
| 1728 |
mark_point(); |
| 1729 |
test_check_errorcode = PR_AUTH_OK_NO_PASS; |
| 1730 |
res = pr_auth_check(p, "", name, cleartext_passwd); |
| 1731 |
ck_assert_msg(res == test_check_errorcode, "Expected %d, got %d", |
| 1732 |
test_check_errorcode, res); |
| 1733 |
|
| 1734 |
res = pr_module_unload(&testsuite_module); |
| 1735 |
ck_assert_msg(res == 0, "Failed to unload module: %s", strerror(errno)); |
| 1736 |
(void) pr_auth_clear_auth_only_modules(); |
| 1737 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 1738 |
} |
| 1739 |
END_TEST |
| 1740 |
|
| 1741 |
START_TEST (auth_check_valid_test) { |
| 1742 |
int res; |
| 1743 |
const char *cleartext_passwd, *ciphertext_passwd, *name; |
| 1744 |
authtable authtab; |
| 1745 |
char *sym_name = "check"; |
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
memset(&authtab, 0, sizeof(authtab)); |
| 1750 |
authtab.name = sym_name; |
| 1751 |
authtab.handler = handle_check; |
| 1752 |
authtab.m = &testsuite_module; |
| 1753 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 1754 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 1755 |
strerror(errno)); |
| 1756 |
|
| 1757 |
mark_point(); |
| 1758 |
cleartext_passwd = PR_TEST_AUTH_PASSWD; |
| 1759 |
res = pr_auth_check(p, NULL, "other", cleartext_passwd); |
| 1760 |
ck_assert_msg(res == PR_AUTH_BADPWD, "Expected %d, got %d", PR_AUTH_BADPWD, |
| 1761 |
res); |
| 1762 |
|
| 1763 |
mark_point(); |
| 1764 |
name = PR_TEST_AUTH_NAME; |
| 1765 |
res = pr_auth_check(p, "foo", name, cleartext_passwd); |
| 1766 |
ck_assert_msg(res == PR_AUTH_BADPWD, "Expected %d, got %d", PR_AUTH_BADPWD, |
| 1767 |
res); |
| 1768 |
|
| 1769 |
mark_point(); |
| 1770 |
res = pr_auth_check(p, NULL, name, cleartext_passwd); |
| 1771 |
ck_assert_msg(res == PR_AUTH_BADPWD, "Expected %d, got %d", PR_AUTH_BADPWD, |
| 1772 |
res); |
| 1773 |
|
| 1774 |
mark_point(); |
| 1775 |
ciphertext_passwd = PR_TEST_AUTH_PASSWD; |
| 1776 |
res = pr_auth_check(p, ciphertext_passwd, name, cleartext_passwd); |
| 1777 |
ck_assert_msg(res == PR_AUTH_OK, "Expected %d, got %d", PR_AUTH_OK, res); |
| 1778 |
|
| 1779 |
(void) pr_auth_cache_set(TRUE, PR_AUTH_CACHE_FL_AUTH_MODULE); |
| 1780 |
|
| 1781 |
res = pr_auth_add_auth_only_module("foo.bar"); |
| 1782 |
ck_assert_msg(res == 0, "Failed to add auth-only module: %s", strerror(errno)); |
| 1783 |
|
| 1784 |
res = pr_auth_add_auth_only_module("mod_testsuite.c"); |
| 1785 |
ck_assert_msg(res == 0, "Failed to add auth-only module: %s", strerror(errno)); |
| 1786 |
|
| 1787 |
mark_point(); |
| 1788 |
check_rfc2228 = TRUE; |
| 1789 |
res = pr_auth_check(p, ciphertext_passwd, name, cleartext_passwd); |
| 1790 |
ck_assert_msg(res == PR_AUTH_RFC2228_OK, |
| 1791 |
"Failed to check user '%s' (expected %d, got %d)", name, |
| 1792 |
PR_AUTH_RFC2228_OK, res); |
| 1793 |
|
| 1794 |
(void) pr_auth_clear_auth_only_modules(); |
| 1795 |
pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &testsuite_module); |
| 1796 |
} |
| 1797 |
END_TEST |
| 1798 |
|
| 1799 |
START_TEST (auth_requires_pass_test) { |
| 1800 |
int res; |
| 1801 |
const char *name; |
| 1802 |
authtable authtab; |
| 1803 |
char *sym_name = "requires_pass"; |
| 1804 |
|
| 1805 |
res = pr_auth_requires_pass(NULL, NULL); |
| 1806 |
ck_assert_msg(res < 0, "Failed to handle null arguments"); |
| 1807 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 1808 |
strerror(errno), errno); |
| 1809 |
|
| 1810 |
res = pr_auth_requires_pass(p, NULL); |
| 1811 |
ck_assert_msg(res < 0, "Failed to handle null name"); |
| 1812 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 1813 |
strerror(errno), errno); |
| 1814 |
|
| 1815 |
name = "other"; |
| 1816 |
res = pr_auth_requires_pass(p, name); |
| 1817 |
ck_assert_msg(res == TRUE, "Unknown users should require passwords (got %d)", |
| 1818 |
res); |
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
memset(&authtab, 0, sizeof(authtab)); |
| 1823 |
authtab.name = sym_name; |
| 1824 |
authtab.handler = handle_requires_pass; |
| 1825 |
authtab.m = &testsuite_module; |
| 1826 |
res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); |
| 1827 |
ck_assert_msg(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, |
| 1828 |
strerror(errno)); |
| 1829 |
|
| 1830 |
res = pr_auth_requires_pass(p, name); |
| 1831 |
ck_assert_msg(res == TRUE, "Unknown users should require passwords (got %d)", |
| 1832 |
res); |
| 1833 |
|
| 1834 |
name = PR_TEST_AUTH_NAME; |
| 1835 |
res = pr_auth_requires_pass(p, name); |
| 1836 |
ck_assert_msg(res == FALSE, "Known users should NOT require passwords (got %d)", |
| 1837 |
res); |
| 1838 |
} |
| 1839 |
END_TEST |
| 1840 |
|
| 1841 |
START_TEST (auth_get_anon_config_test) { |
| 1842 |
config_rec *anon_config, *c, *c2, *res; |
| 1843 |
const char *login_user = "test"; |
| 1844 |
char *real_user = NULL, *anon_user = NULL; |
| 1845 |
|
| 1846 |
mark_point(); |
| 1847 |
login_user = "test"; |
| 1848 |
res = pr_auth_get_anon_config(NULL, NULL, NULL, NULL); |
| 1849 |
ck_assert_msg(res == NULL, "Failed to handle null arguments"); |
| 1850 |
|
| 1851 |
mark_point(); |
| 1852 |
|
| 1853 |
c = add_config_param_set(&(test_server->conf), "UserAlias", 2, NULL, NULL); |
| 1854 |
c->argv[0] = pstrdup(c->pool, "bar"); |
| 1855 |
c->argv[1] = pstrdup(c->pool, "foo"); |
| 1856 |
|
| 1857 |
c2 = add_config_param_set(&(test_server->conf), "AuthAliasOnly", 1, NULL); |
| 1858 |
c2->argv[0] = palloc(c2->pool, sizeof(unsigned char)); |
| 1859 |
*((unsigned char *) c2->argv[0]) = TRUE; |
| 1860 |
|
| 1861 |
login_user = "test"; |
| 1862 |
anon_user = "anon"; |
| 1863 |
res = pr_auth_get_anon_config(p, &login_user, &real_user, &anon_user); |
| 1864 |
ck_assert_msg(res == NULL, "Failed to handle UserAlias with mismatched alias"); |
| 1865 |
ck_assert_msg(login_user == NULL, "Failed to set login_user to null"); |
| 1866 |
ck_assert_msg(anon_user == NULL, "Failed to set anon_user to null"); |
| 1867 |
|
| 1868 |
mark_point(); |
| 1869 |
login_user = "test"; |
| 1870 |
c->argv[0] = pstrdup(c->pool, "*"); |
| 1871 |
res = pr_auth_get_anon_config(p, &login_user, &real_user, &anon_user); |
| 1872 |
ck_assert_msg(res == NULL, "Failed to handle UserAlias with globbed alias"); |
| 1873 |
|
| 1874 |
mark_point(); |
| 1875 |
login_user = "test"; |
| 1876 |
c->argv[0] = pstrdup(c->pool, login_user); |
| 1877 |
res = pr_auth_get_anon_config(p, &login_user, &real_user, &anon_user); |
| 1878 |
ck_assert_msg(res == NULL, "Failed to handle UserAlias with matching alias"); |
| 1879 |
|
| 1880 |
mark_point(); |
| 1881 |
login_user = "test"; |
| 1882 |
anon_config = pcalloc(p, sizeof(config_rec)); |
| 1883 |
anon_config->config_type = CONF_ANON; |
| 1884 |
c2 = add_config_param_set(&(anon_config->subset), "AuthAliasOnly", 1, NULL); |
| 1885 |
c2->argv[0] = palloc(c2->pool, sizeof(unsigned char)); |
| 1886 |
*((unsigned char *) c2->argv[0]) = TRUE; |
| 1887 |
c->parent = anon_config; |
| 1888 |
res = pr_auth_get_anon_config(p, &login_user, &real_user, &anon_user); |
| 1889 |
ck_assert_msg(res != NULL, "Failed to handle UserAlias with matching alias and <Anonymous> config"); |
| 1890 |
ck_assert_msg(res == anon_config, "Expected <Anonymous> config %p, got %p", |
| 1891 |
anon_config, res); |
| 1892 |
|
| 1893 |
mark_point(); |
| 1894 |
login_user = "test"; |
| 1895 |
real_user = "foo"; |
| 1896 |
|
| 1897 |
c2 = add_config_param_set(&(anon_config->subset), "UserName", 1, NULL); |
| 1898 |
c2->argv[0] = pstrdup(c2->pool, "BAZ"); |
| 1899 |
res = pr_auth_get_anon_config(p, &login_user, &real_user, &anon_user); |
| 1900 |
|
| 1901 |
ck_assert_msg(res != NULL, "Failed to handle UserAlias with matching alias and <Anonymous> config"); |
| 1902 |
ck_assert_msg(res == anon_config, "Expected <Anonymous> config %p, got %p", |
| 1903 |
anon_config, res); |
| 1904 |
ck_assert_msg(real_user != NULL, "Expected real_user, got NULL"); |
| 1905 |
ck_assert_msg(strcmp(real_user, "BAZ") == 0, "Expected real_user 'BAZ', got '%s'", real_user); |
| 1906 |
|
| 1907 |
(void) remove_config(test_server->conf, "AuthAliasOnly", TRUE); |
| 1908 |
(void) remove_config(test_server->conf, "UserAlias", FALSE); |
| 1909 |
} |
| 1910 |
END_TEST |
| 1911 |
|
| 1912 |
START_TEST (auth_chroot_test) { |
| 1913 |
int res; |
| 1914 |
const char *path; |
| 1915 |
|
| 1916 |
mark_point(); |
| 1917 |
res = pr_auth_chroot(NULL); |
| 1918 |
ck_assert_msg(res < 0, "Failed to handle null argument"); |
| 1919 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 1920 |
strerror(errno), errno); |
| 1921 |
|
| 1922 |
mark_point(); |
| 1923 |
path = "tmp"; |
| 1924 |
res = pr_auth_chroot(path); |
| 1925 |
ck_assert_msg(res < 0, "Failed to chroot to '%s': %s", path, strerror(errno)); |
| 1926 |
ck_assert_msg(errno == EINVAL || errno == ENOENT, |
| 1927 |
"Expected EINVAL (%d) or ENOENT (%d), got %s (%d)", EINVAL, ENOENT, |
| 1928 |
strerror(errno), errno); |
| 1929 |
|
| 1930 |
|
| 1931 |
|
| 1932 |
|
| 1933 |
mark_point(); |
| 1934 |
path = "/tmp"; |
| 1935 |
res = pr_auth_chroot(path); |
| 1936 |
ck_assert_msg(res < 0, "Failed to chroot to '%s': %s", path, strerror(errno)); |
| 1937 |
ck_assert_msg(errno == ENOENT || errno == EPERM || errno == EINVAL, |
| 1938 |
"Expected ENOENT (%d), EPERM (%d) or EINVAL (%d), got %s (%d)", |
| 1939 |
ENOENT, EPERM, EINVAL, strerror(errno), errno); |
| 1940 |
|
| 1941 |
|
| 1942 |
mark_point(); |
| 1943 |
session.pool = p; |
| 1944 |
path = "/tmp"; |
| 1945 |
res = pr_auth_chroot(path); |
| 1946 |
ck_assert_msg(res < 0, "Failed to chroot to '%s': %s", path, strerror(errno)); |
| 1947 |
ck_assert_msg(errno == ENOENT || errno == EPERM || errno == EINVAL, |
| 1948 |
"Expected ENOENT (%d), EPERM (%d) or EINVAL (%d), got %s (%d)", |
| 1949 |
ENOENT, EPERM, EINVAL, strerror(errno), errno); |
| 1950 |
|
| 1951 |
|
| 1952 |
mark_point(); |
| 1953 |
path = "/tmp"; |
| 1954 |
res = pr_auth_chroot(path); |
| 1955 |
ck_assert_msg(res < 0, "Failed to chroot to '%s': %s", path, strerror(errno)); |
| 1956 |
ck_assert_msg(errno == ENOENT || errno == EPERM || errno == EINVAL, |
| 1957 |
"Expected ENOENT (%d), EPERM (%d) or EINVAL (%d), got %s (%d)", |
| 1958 |
ENOENT, EPERM, EINVAL, strerror(errno), errno); |
| 1959 |
|
| 1960 |
session.pool = NULL; |
| 1961 |
} |
| 1962 |
END_TEST |
| 1963 |
|
| 1964 |
START_TEST (auth_banned_by_ftpusers_test) { |
| 1965 |
const char *name; |
| 1966 |
int res; |
| 1967 |
config_rec *c; |
| 1968 |
|
| 1969 |
mark_point(); |
| 1970 |
res = pr_auth_banned_by_ftpusers(NULL, NULL); |
| 1971 |
ck_assert_msg(res == FALSE, "Failed to handle null arguments"); |
| 1972 |
|
| 1973 |
mark_point(); |
| 1974 |
res = pr_auth_banned_by_ftpusers(test_server->conf, NULL); |
| 1975 |
ck_assert_msg(res == FALSE, "Failed to handle null user"); |
| 1976 |
|
| 1977 |
mark_point(); |
| 1978 |
name = "testsuite"; |
| 1979 |
res = pr_auth_banned_by_ftpusers(test_server->conf, name); |
| 1980 |
ck_assert_msg(res == FALSE, "Expected FALSE, got %d", res); |
| 1981 |
|
| 1982 |
|
| 1983 |
mark_point(); |
| 1984 |
c = add_config_param_set(&(test_server->conf), "UseFtpUsers", 1, NULL); |
| 1985 |
c->argv[0] = pcalloc(c->pool, sizeof(unsigned char)); |
| 1986 |
*((unsigned char *) c->argv[0]) = FALSE; |
| 1987 |
|
| 1988 |
res = pr_auth_banned_by_ftpusers(test_server->conf, name); |
| 1989 |
ck_assert_msg(res == FALSE, "Failed to handle UseFtpUsers off (got %d)", |
| 1990 |
res); |
| 1991 |
|
| 1992 |
(void) remove_config(test_server->conf, "UseFtpUsers", FALSE); |
| 1993 |
} |
| 1994 |
END_TEST |
| 1995 |
|
| 1996 |
START_TEST (auth_is_valid_shell_test) { |
| 1997 |
const char *shell; |
| 1998 |
int res; |
| 1999 |
config_rec *c; |
| 2000 |
|
| 2001 |
mark_point(); |
| 2002 |
res = pr_auth_is_valid_shell(NULL, NULL); |
| 2003 |
ck_assert_msg(res == TRUE, "Failed to handle null arguments"); |
| 2004 |
|
| 2005 |
mark_point(); |
| 2006 |
res = pr_auth_is_valid_shell(test_server->conf, NULL); |
| 2007 |
ck_assert_msg(res == TRUE, "Failed to handle null shell"); |
| 2008 |
|
| 2009 |
shell = "/foo/bar"; |
| 2010 |
res = pr_auth_is_valid_shell(test_server->conf, shell); |
| 2011 |
ck_assert_msg(res == FALSE, "Failed to handle invalid shell '%s' (got %d)", |
| 2012 |
shell, res); |
| 2013 |
|
| 2014 |
mark_point(); |
| 2015 |
shell = "/bin/sh"; |
| 2016 |
res = pr_auth_is_valid_shell(test_server->conf, shell); |
| 2017 |
ck_assert_msg(res == TRUE, "Failed to handle valid shell '%s' (got %d)", |
| 2018 |
shell, res); |
| 2019 |
|
| 2020 |
|
| 2021 |
mark_point(); |
| 2022 |
c = add_config_param_set(&(test_server->conf), "RequireValidShell", 1, NULL); |
| 2023 |
c->argv[0] = pcalloc(c->pool, sizeof(unsigned char)); |
| 2024 |
*((unsigned char *) c->argv[0]) = FALSE; |
| 2025 |
|
| 2026 |
shell = "/foo/bar"; |
| 2027 |
res = pr_auth_is_valid_shell(test_server->conf, shell); |
| 2028 |
ck_assert_msg(res == TRUE, "Failed to handle RequireValidShell off (got %d)", |
| 2029 |
res); |
| 2030 |
|
| 2031 |
(void) remove_config(test_server->conf, "RequireValidShell", FALSE); |
| 2032 |
} |
| 2033 |
END_TEST |
| 2034 |
|
| 2035 |
START_TEST (auth_set_groups_test) { |
| 2036 |
int res; |
| 2037 |
|
| 2038 |
if (getuid() == PR_ROOT_UID) { |
| 2039 |
gid_t gid; |
| 2040 |
|
| 2041 |
gid = getgid(); |
| 2042 |
|
| 2043 |
mark_point(); |
| 2044 |
res = set_groups(NULL, 0, NULL); |
| 2045 |
ck_assert_msg(res == 0, "Failed to handle zero primary gid: %s", |
| 2046 |
strerror(errno)); |
| 2047 |
|
| 2048 |
mark_point(); |
| 2049 |
res = set_groups(p, 0, NULL); |
| 2050 |
ck_assert_msg(res == 0, "Failed to handle zero primary gid: %s", |
| 2051 |
strerror(errno)); |
| 2052 |
|
| 2053 |
mark_point(); |
| 2054 |
res = set_groups(NULL, gid, NULL); |
| 2055 |
ck_assert_msg(res == 0, "Failed to handle current primary gid: %s", |
| 2056 |
strerror(errno)); |
| 2057 |
|
| 2058 |
} else { |
| 2059 |
mark_point(); |
| 2060 |
res = set_groups(NULL, 0, NULL); |
| 2061 |
ck_assert_msg(res < 0, "Failed to handle zero primary gid: %s", |
| 2062 |
strerror(errno)); |
| 2063 |
ck_assert_msg(errno == ENOSYS, "Expected ENOSYS (%d), got %s (%d)", ENOSYS, |
| 2064 |
strerror(errno), errno); |
| 2065 |
|
| 2066 |
mark_point(); |
| 2067 |
res = set_groups(p, 0, NULL); |
| 2068 |
ck_assert_msg(res < 0, "Failed to handle zero primary gid: %s", |
| 2069 |
strerror(errno)); |
| 2070 |
ck_assert_msg(errno == ENOSYS, "Expected ENOSYS (%d), got %s (%d)", ENOSYS, |
| 2071 |
strerror(errno), errno); |
| 2072 |
|
| 2073 |
mark_point(); |
| 2074 |
res = set_groups(p, 1, NULL); |
| 2075 |
ck_assert_msg(res < 0, "Failed to handle non-root primary gid: %s", |
| 2076 |
strerror(errno)); |
| 2077 |
ck_assert_msg(errno == ENOSYS, "Expected ENOSYS (%d), got %s (%d)", ENOSYS, |
| 2078 |
strerror(errno), errno); |
| 2079 |
|
| 2080 |
mark_point(); |
| 2081 |
res = set_groups(p, getgid(), NULL); |
| 2082 |
ck_assert_msg(res < 0, "Failed to handle current primary gid: %s", |
| 2083 |
strerror(errno)); |
| 2084 |
ck_assert_msg(errno == ENOSYS, "Expected ENOSYS (%d), got %s (%d)", ENOSYS, |
| 2085 |
strerror(errno), errno); |
| 2086 |
} |
| 2087 |
} |
| 2088 |
END_TEST |
| 2089 |
|
| 2090 |
START_TEST (auth_get_home_test) { |
| 2091 |
const char *home, *res; |
| 2092 |
config_rec *c; |
| 2093 |
|
| 2094 |
res = pr_auth_get_home(NULL, NULL); |
| 2095 |
ck_assert_msg(res == NULL, "Failed to handle null arguments"); |
| 2096 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 2097 |
strerror(errno), errno); |
| 2098 |
|
| 2099 |
res = pr_auth_get_home(p, NULL); |
| 2100 |
ck_assert_msg(res == NULL, "Failed to handle null home"); |
| 2101 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, |
| 2102 |
strerror(errno), errno); |
| 2103 |
|
| 2104 |
home = "/testsuite"; |
| 2105 |
res = pr_auth_get_home(p, home); |
| 2106 |
ck_assert_msg(res != NULL, "Failed to get home: %s", strerror(errno)); |
| 2107 |
ck_assert_msg(strcmp(home, res) == 0, "Expected '%s', got '%s'", home, res); |
| 2108 |
|
| 2109 |
|
| 2110 |
mark_point(); |
| 2111 |
c = add_config_param_set(&(test_server->conf), "RewriteHome", 1); |
| 2112 |
c->argv[0] = pcalloc(c->pool, sizeof(unsigned char)); |
| 2113 |
*((int *) c->argv[0]) = FALSE; |
| 2114 |
|
| 2115 |
res = pr_auth_get_home(p, home); |
| 2116 |
ck_assert_msg(res != NULL, "Failed to get home: %s", strerror(errno)); |
| 2117 |
ck_assert_msg(strcmp(home, res) == 0, |
| 2118 |
"Failed to handle RewriteHome off, got '%s'", res); |
| 2119 |
|
| 2120 |
|
| 2121 |
mark_point(); |
| 2122 |
*((int *) c->argv[0]) = TRUE; |
| 2123 |
res = pr_auth_get_home(p, home); |
| 2124 |
ck_assert_msg(res != NULL, "Failed to get home: %s", strerror(errno)); |
| 2125 |
ck_assert_msg(strcmp(home, res) == 0, |
| 2126 |
"Failed to handle RewriteHome on, got '%s'", res); |
| 2127 |
|
| 2128 |
mark_point(); |
| 2129 |
session.notes = pr_table_alloc(p, 2); |
| 2130 |
res = pr_auth_get_home(p, home); |
| 2131 |
ck_assert_msg(res != NULL, "Failed to get home: %s", strerror(errno)); |
| 2132 |
ck_assert_msg(strcmp(home, res) == 0, |
| 2133 |
"Failed to handle RewriteHome on, got '%s'", res); |
| 2134 |
|
| 2135 |
(void) pr_table_empty(session.notes); |
| 2136 |
(void) pr_table_free(session.notes); |
| 2137 |
session.notes = NULL; |
| 2138 |
|
| 2139 |
(void) remove_config(test_server->conf, "RewriteHome", FALSE); |
| 2140 |
} |
| 2141 |
END_TEST |
| 2142 |
|
| 2143 |
START_TEST (auth_set_max_password_len_test) { |
| 2144 |
int checked; |
| 2145 |
size_t res; |
| 2146 |
|
| 2147 |
res = pr_auth_set_max_password_len(p, 1); |
| 2148 |
ck_assert_msg(res == PR_TUNABLE_PASSWORD_MAX, |
| 2149 |
"Expected %lu, got %lu", (unsigned long) PR_TUNABLE_PASSWORD_MAX, |
| 2150 |
(unsigned long) res); |
| 2151 |
|
| 2152 |
checked = pr_auth_check(p, NULL, PR_TEST_AUTH_NAME, PR_TEST_AUTH_PASSWD); |
| 2153 |
ck_assert_msg(checked < 0, "Failed to reject too-long password"); |
| 2154 |
ck_assert_msg(errno == EPERM, "Expected EPERM (%d), got %s (%d)", EPERM, |
| 2155 |
strerror(errno), errno); |
| 2156 |
|
| 2157 |
res = pr_auth_set_max_password_len(p, 0); |
| 2158 |
ck_assert_msg(res == 1, "Expected %d, got %lu", 1, (unsigned long) res); |
| 2159 |
|
| 2160 |
res = pr_auth_set_max_password_len(p, 0); |
| 2161 |
ck_assert_msg(res == PR_TUNABLE_PASSWORD_MAX, |
| 2162 |
"Expected %lu, got %lu", (unsigned long) PR_TUNABLE_PASSWORD_MAX, |
| 2163 |
(unsigned long) res); |
| 2164 |
} |
| 2165 |
END_TEST |
| 2166 |
|
| 2167 |
START_TEST (auth_bcrypt_test) { |
| 2168 |
char *res; |
| 2169 |
size_t hashed_len; |
| 2170 |
|
| 2171 |
res = pr_auth_bcrypt(NULL, NULL, NULL, NULL); |
| 2172 |
ck_assert_msg(res == NULL, "Failed to handle null pool argument"); |
| 2173 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got '%s' (%d)", EINVAL, |
| 2174 |
strerror(errno), errno); |
| 2175 |
|
| 2176 |
res = pr_auth_bcrypt(p, NULL, NULL, NULL); |
| 2177 |
ck_assert_msg(res == NULL, "Failed to handle null key argument"); |
| 2178 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got '%s' (%d)", EINVAL, |
| 2179 |
strerror(errno), errno); |
| 2180 |
|
| 2181 |
res = pr_auth_bcrypt(p, "", NULL, NULL); |
| 2182 |
ck_assert_msg(res == NULL, "Failed to handle null salt argument"); |
| 2183 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got '%s' (%d)", EINVAL, |
| 2184 |
strerror(errno), errno); |
| 2185 |
|
| 2186 |
res = pr_auth_bcrypt(p, "", "", NULL); |
| 2187 |
ck_assert_msg(res == NULL, "Failed to handle null hashed_len argument"); |
| 2188 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got '%s' (%d)", EINVAL, |
| 2189 |
strerror(errno), errno); |
| 2190 |
|
| 2191 |
res = pr_auth_bcrypt(p, "", "", &hashed_len); |
| 2192 |
ck_assert_msg(res == NULL, "Failed to handle empty strings"); |
| 2193 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got '%s' (%d)", EINVAL, |
| 2194 |
strerror(errno), errno); |
| 2195 |
|
| 2196 |
res = pr_auth_bcrypt(p, "foo", "$1", &hashed_len); |
| 2197 |
ck_assert_msg(res == NULL, "Failed to handle invalid salt"); |
| 2198 |
ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got '%s' (%d)", EINVAL, |
| 2199 |
strerror(errno), errno); |
| 2200 |
|
| 2201 |
|
| 2202 |
|
| 2203 |
|
| 2204 |
|
| 2205 |
res = pr_auth_bcrypt(p, "password", |
| 2206 |
"$2b$12$IoFxXvbRQUKssPqFacJFFuZl1KXl5ULppqf0aLFjwCFnLRh3NbYSG", |
| 2207 |
&hashed_len); |
| 2208 |
ck_assert_msg(res != NULL, "Failed to handle valid key and salt"); |
| 2209 |
} |
| 2210 |
END_TEST |
| 2211 |
|
| 2212 |
Suite *tests_get_auth_suite(void) { |
| 2213 |
Suite *suite; |
| 2214 |
TCase *testcase; |
| 2215 |
|
| 2216 |
suite = suite_create("auth"); |
| 2217 |
|
| 2218 |
testcase = tcase_create("base"); |
| 2219 |
tcase_add_checked_fixture(testcase, set_up, tear_down); |
| 2220 |
|
| 2221 |
|
| 2222 |
tcase_add_test(testcase, auth_setpwent_test); |
| 2223 |
tcase_add_test(testcase, auth_endpwent_test); |
| 2224 |
tcase_add_test(testcase, auth_getpwent_test); |
| 2225 |
tcase_add_test(testcase, auth_getpwnam_test); |
| 2226 |
tcase_add_test(testcase, auth_getpwuid_test); |
| 2227 |
tcase_add_test(testcase, auth_name2uid_test); |
| 2228 |
tcase_add_test(testcase, auth_uid2name_test); |
| 2229 |
|
| 2230 |
|
| 2231 |
tcase_add_test(testcase, auth_setgrent_test); |
| 2232 |
tcase_add_test(testcase, auth_endgrent_test); |
| 2233 |
tcase_add_test(testcase, auth_getgrent_test); |
| 2234 |
tcase_add_test(testcase, auth_getgrnam_test); |
| 2235 |
tcase_add_test(testcase, auth_getgrgid_test); |
| 2236 |
tcase_add_test(testcase, auth_gid2name_test); |
| 2237 |
tcase_add_test(testcase, auth_name2gid_test); |
| 2238 |
tcase_add_test(testcase, auth_getgroups_test); |
| 2239 |
|
| 2240 |
|
| 2241 |
tcase_add_test(testcase, auth_cache_uid2name_test); |
| 2242 |
tcase_add_test(testcase, auth_cache_gid2name_test); |
| 2243 |
tcase_add_test(testcase, auth_cache_uid2name_failed_test); |
| 2244 |
tcase_add_test(testcase, auth_cache_gid2name_failed_test); |
| 2245 |
tcase_add_test(testcase, auth_cache_name2uid_failed_test); |
| 2246 |
tcase_add_test(testcase, auth_cache_name2gid_failed_test); |
| 2247 |
tcase_add_test(testcase, auth_cache_clear_test); |
| 2248 |
tcase_add_test(testcase, auth_cache_set_test); |
| 2249 |
|
| 2250 |
|
| 2251 |
tcase_add_test(testcase, auth_clear_auth_only_module_test); |
| 2252 |
tcase_add_test(testcase, auth_add_auth_only_module_test); |
| 2253 |
tcase_add_test(testcase, auth_remove_auth_only_module_test); |
| 2254 |
|
| 2255 |
|
| 2256 |
tcase_add_test(testcase, auth_authenticate_test); |
| 2257 |
tcase_add_test(testcase, auth_authorize_test); |
| 2258 |
tcase_add_test(testcase, auth_check_errors_test); |
| 2259 |
tcase_add_test(testcase, auth_check_valid_test); |
| 2260 |
tcase_add_test(testcase, auth_requires_pass_test); |
| 2261 |
|
| 2262 |
|
| 2263 |
tcase_add_test(testcase, auth_get_anon_config_test); |
| 2264 |
tcase_add_test(testcase, auth_chroot_test); |
| 2265 |
tcase_add_test(testcase, auth_banned_by_ftpusers_test); |
| 2266 |
tcase_add_test(testcase, auth_is_valid_shell_test); |
| 2267 |
tcase_add_test(testcase, auth_set_groups_test); |
| 2268 |
tcase_add_test(testcase, auth_get_home_test); |
| 2269 |
tcase_add_test(testcase, auth_set_max_password_len_test); |
| 2270 |
tcase_add_test(testcase, auth_bcrypt_test); |
| 2271 |
|
| 2272 |
suite_add_tcase(suite, testcase); |
| 2273 |
return suite; |
| 2274 |
} |