|
1 | 1 | #include "common.h" |
2 | 2 |
|
| 3 | +#include <assert.h> |
| 4 | + |
3 | 5 | /* change password on server */ |
4 | 6 |
|
| 7 | +#define USER "freetds_oldpwd" |
| 8 | +#define PWD1 "TestPWD1?" |
| 9 | +#define PWD2 "OtherPWD2@" |
| 10 | + |
5 | 11 | static void |
6 | 12 | my_attrs(void) |
7 | 13 | { |
8 | | - SQLSetConnectAttr(odbc_conn, 1226 /*SQL_COPT_SS_OLDPWD */ , |
9 | | - (SQLPOINTER) common_pwd.password, SQL_NTS); |
10 | | - strcpy(common_pwd.password, "testpwd$"); |
| 14 | + SQLSetConnectAttr(odbc_conn, 1226 /* SQL_COPT_SS_OLDPWD */ , |
| 15 | + (SQLPOINTER) PWD1, SQL_NTS); |
| 16 | + strcpy(common_pwd.user, USER); |
| 17 | + strcpy(common_pwd.password, PWD2); |
11 | 18 | } |
12 | 19 |
|
13 | 20 | TEST_MAIN() |
14 | 21 | { |
| 22 | + const char *ci; |
| 23 | + char *old_user, *old_pwd; |
| 24 | + |
15 | 25 | odbc_use_version3 = true; |
| 26 | + |
| 27 | + /* Check if we are in CI */ |
| 28 | + ci = getenv("CI"); |
| 29 | + if (!ci || strcasecmp(ci, "true") != 0) { |
| 30 | + odbc_test_skipped(); |
| 31 | + return 0; |
| 32 | + } |
| 33 | + |
| 34 | + odbc_connect(); |
| 35 | + |
| 36 | + /* minimum TDS 7.2 and MSSQL 2012 */ |
| 37 | + if (odbc_tds_version() < 0x702 || odbc_db_version_int() < 0x0a000000u) { |
| 38 | + odbc_disconnect(); |
| 39 | + odbc_test_skipped(); |
| 40 | + return 0; |
| 41 | + } |
| 42 | + |
| 43 | + /* create new login for this test and disconnect */ |
| 44 | + odbc_command_with_result(odbc_stmt, "DROP LOGIN " USER); |
| 45 | + odbc_command("CREATE LOGIN " USER " WITH PASSWORD='" PWD1 "' MUST_CHANGE, " |
| 46 | + "DEFAULT_DATABASE = tempdb, CHECK_EXPIRATION = ON"); |
| 47 | + |
| 48 | + odbc_disconnect(); |
| 49 | + |
| 50 | + old_user = strdup(common_pwd.user); |
| 51 | + assert(old_user); |
| 52 | + old_pwd = strdup(common_pwd.password); |
| 53 | + assert(old_pwd); |
| 54 | + |
| 55 | + /* login with new password should fail */ |
| 56 | + strcpy(common_pwd.user, USER); |
| 57 | + strcpy(common_pwd.password, PWD1); |
| 58 | + |
| 59 | + CHKAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &odbc_env, "S"); |
| 60 | + SQLSetEnvAttr(odbc_env, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) (SQL_OV_ODBC3), SQL_IS_UINTEGER); |
| 61 | + CHKAllocHandle(SQL_HANDLE_DBC, odbc_env, &odbc_conn, "S"); |
| 62 | + CHKConnect(T(common_pwd.server), SQL_NTS, T(common_pwd.user), SQL_NTS, T(common_pwd.password), SQL_NTS, "E"); |
| 63 | + odbc_read_error(); |
| 64 | + if (strcmp(odbc_sqlstate, "42000") != 0 || |
| 65 | + strstr(odbc_err, USER) == NULL || strstr(odbc_err, "The password of the account must be changed") == NULL) { |
| 66 | + fprintf(stderr, "Unexpected sql state %s returned\n", odbc_sqlstate); |
| 67 | + odbc_disconnect(); |
| 68 | + return 1; |
| 69 | + } |
| 70 | + odbc_disconnect(); |
| 71 | + |
| 72 | + /* login and change password */ |
16 | 73 | odbc_set_conn_attr = my_attrs; |
17 | 74 | odbc_connect(); |
| 75 | + odbc_disconnect(); |
| 76 | + |
| 77 | + /* login wiht new password */ |
| 78 | + odbc_set_conn_attr = NULL; |
| 79 | + odbc_connect(); |
| 80 | + odbc_disconnect(); |
18 | 81 |
|
| 82 | + /* drop created login */ |
| 83 | + strcpy(common_pwd.user, old_user); |
| 84 | + free(old_user); |
| 85 | + strcpy(common_pwd.password, old_pwd); |
| 86 | + free(old_pwd); |
| 87 | + odbc_connect(); |
| 88 | + odbc_command("DROP LOGIN " USER); |
19 | 89 | odbc_disconnect(); |
| 90 | + |
20 | 91 | return 0; |
21 | 92 | } |
0 commit comments