| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 |
|
|---|
| 4 | Winbind client API
|
|---|
| 5 |
|
|---|
| 6 | Copyright (C) Gerald (Jerry) Carter 2007
|
|---|
| 7 | Copyright (C) Guenther Deschner 2008
|
|---|
| 8 | Copyright (C) Volker Lendecke 2009
|
|---|
| 9 |
|
|---|
| 10 | This library is free software; you can redistribute it and/or
|
|---|
| 11 | modify it under the terms of the GNU Lesser General Public
|
|---|
| 12 | License as published by the Free Software Foundation; either
|
|---|
| 13 | version 3 of the License, or (at your option) any later version.
|
|---|
| 14 |
|
|---|
| 15 | This library is distributed in the hope that it will be useful,
|
|---|
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 18 | Library General Public License for more details.
|
|---|
| 19 |
|
|---|
| 20 | You should have received a copy of the GNU Lesser General Public License
|
|---|
| 21 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 22 | */
|
|---|
| 23 |
|
|---|
| 24 | /* Required Headers */
|
|---|
| 25 |
|
|---|
| 26 | #include "replace.h"
|
|---|
| 27 | #include "libwbclient.h"
|
|---|
| 28 |
|
|---|
| 29 | /* Authenticate a username/password pair */
|
|---|
| 30 | wbcErr wbcAuthenticateUser(const char *username,
|
|---|
| 31 | const char *password)
|
|---|
| 32 | {
|
|---|
| 33 | wbcErr wbc_status = WBC_ERR_SUCCESS;
|
|---|
| 34 | struct wbcAuthUserParams params;
|
|---|
| 35 |
|
|---|
| 36 | ZERO_STRUCT(params);
|
|---|
| 37 |
|
|---|
| 38 | params.account_name = username;
|
|---|
| 39 | params.level = WBC_AUTH_USER_LEVEL_PLAIN;
|
|---|
| 40 | params.password.plaintext = password;
|
|---|
| 41 |
|
|---|
| 42 | wbc_status = wbcAuthenticateUserEx(¶ms, NULL, NULL);
|
|---|
| 43 | BAIL_ON_WBC_ERROR(wbc_status);
|
|---|
| 44 |
|
|---|
| 45 | done:
|
|---|
| 46 | return wbc_status;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | static wbcErr wbc_create_auth_info(TALLOC_CTX *mem_ctx,
|
|---|
| 50 | const struct winbindd_response *resp,
|
|---|
| 51 | struct wbcAuthUserInfo **_i)
|
|---|
| 52 | {
|
|---|
| 53 | wbcErr wbc_status = WBC_ERR_SUCCESS;
|
|---|
| 54 | struct wbcAuthUserInfo *i;
|
|---|
| 55 | struct wbcDomainSid domain_sid;
|
|---|
| 56 | char *p;
|
|---|
| 57 | uint32_t sn = 0;
|
|---|
| 58 | uint32_t j;
|
|---|
| 59 |
|
|---|
| 60 | i = talloc(mem_ctx, struct wbcAuthUserInfo);
|
|---|
| 61 | BAIL_ON_PTR_ERROR(i, wbc_status);
|
|---|
| 62 |
|
|---|
| 63 | i->user_flags = resp->data.auth.info3.user_flgs;
|
|---|
| 64 |
|
|---|
| 65 | i->account_name = talloc_strdup(i, resp->data.auth.info3.user_name);
|
|---|
| 66 | BAIL_ON_PTR_ERROR(i->account_name, wbc_status);
|
|---|
| 67 | i->user_principal= NULL;
|
|---|
| 68 | i->full_name = talloc_strdup(i, resp->data.auth.info3.full_name);
|
|---|
| 69 | BAIL_ON_PTR_ERROR(i->full_name, wbc_status);
|
|---|
| 70 | i->domain_name = talloc_strdup(i, resp->data.auth.info3.logon_dom);
|
|---|
| 71 | BAIL_ON_PTR_ERROR(i->domain_name, wbc_status);
|
|---|
| 72 | i->dns_domain_name= NULL;
|
|---|
| 73 |
|
|---|
| 74 | i->acct_flags = resp->data.auth.info3.acct_flags;
|
|---|
| 75 | memcpy(i->user_session_key,
|
|---|
| 76 | resp->data.auth.user_session_key,
|
|---|
| 77 | sizeof(i->user_session_key));
|
|---|
| 78 | memcpy(i->lm_session_key,
|
|---|
| 79 | resp->data.auth.first_8_lm_hash,
|
|---|
| 80 | sizeof(i->lm_session_key));
|
|---|
| 81 |
|
|---|
| 82 | i->logon_count = resp->data.auth.info3.logon_count;
|
|---|
| 83 | i->bad_password_count = resp->data.auth.info3.bad_pw_count;
|
|---|
| 84 |
|
|---|
| 85 | i->logon_time = resp->data.auth.info3.logon_time;
|
|---|
| 86 | i->logoff_time = resp->data.auth.info3.logoff_time;
|
|---|
| 87 | i->kickoff_time = resp->data.auth.info3.kickoff_time;
|
|---|
| 88 | i->pass_last_set_time = resp->data.auth.info3.pass_last_set_time;
|
|---|
| 89 | i->pass_can_change_time = resp->data.auth.info3.pass_can_change_time;
|
|---|
| 90 | i->pass_must_change_time= resp->data.auth.info3.pass_must_change_time;
|
|---|
| 91 |
|
|---|
| 92 | i->logon_server = talloc_strdup(i, resp->data.auth.info3.logon_srv);
|
|---|
| 93 | BAIL_ON_PTR_ERROR(i->logon_server, wbc_status);
|
|---|
| 94 | i->logon_script = talloc_strdup(i, resp->data.auth.info3.logon_script);
|
|---|
| 95 | BAIL_ON_PTR_ERROR(i->logon_script, wbc_status);
|
|---|
| 96 | i->profile_path = talloc_strdup(i, resp->data.auth.info3.profile_path);
|
|---|
| 97 | BAIL_ON_PTR_ERROR(i->profile_path, wbc_status);
|
|---|
| 98 | i->home_directory= talloc_strdup(i, resp->data.auth.info3.home_dir);
|
|---|
| 99 | BAIL_ON_PTR_ERROR(i->home_directory, wbc_status);
|
|---|
| 100 | i->home_drive = talloc_strdup(i, resp->data.auth.info3.dir_drive);
|
|---|
| 101 | BAIL_ON_PTR_ERROR(i->home_drive, wbc_status);
|
|---|
| 102 |
|
|---|
| 103 | i->num_sids = 2;
|
|---|
| 104 | i->num_sids += resp->data.auth.info3.num_groups;
|
|---|
| 105 | i->num_sids += resp->data.auth.info3.num_other_sids;
|
|---|
| 106 |
|
|---|
| 107 | i->sids = talloc_array(i, struct wbcSidWithAttr, i->num_sids);
|
|---|
| 108 | BAIL_ON_PTR_ERROR(i->sids, wbc_status);
|
|---|
| 109 |
|
|---|
| 110 | wbc_status = wbcStringToSid(resp->data.auth.info3.dom_sid,
|
|---|
| 111 | &domain_sid);
|
|---|
| 112 | BAIL_ON_WBC_ERROR(wbc_status);
|
|---|
| 113 |
|
|---|
| 114 | #define _SID_COMPOSE(s, d, r, a) { \
|
|---|
| 115 | (s).sid = d; \
|
|---|
| 116 | if ((s).sid.num_auths < WBC_MAXSUBAUTHS) { \
|
|---|
| 117 | (s).sid.sub_auths[(s).sid.num_auths++] = r; \
|
|---|
| 118 | } else { \
|
|---|
| 119 | wbc_status = WBC_ERR_INVALID_SID; \
|
|---|
| 120 | BAIL_ON_WBC_ERROR(wbc_status); \
|
|---|
| 121 | } \
|
|---|
| 122 | (s).attributes = a; \
|
|---|
| 123 | } while (0)
|
|---|
| 124 |
|
|---|
| 125 | sn = 0;
|
|---|
| 126 | _SID_COMPOSE(i->sids[sn], domain_sid,
|
|---|
| 127 | resp->data.auth.info3.user_rid,
|
|---|
| 128 | 0);
|
|---|
| 129 | sn++;
|
|---|
| 130 | _SID_COMPOSE(i->sids[sn], domain_sid,
|
|---|
| 131 | resp->data.auth.info3.group_rid,
|
|---|
| 132 | 0);
|
|---|
| 133 | sn++;
|
|---|
| 134 |
|
|---|
| 135 | p = (char *)resp->extra_data.data;
|
|---|
| 136 | if (!p) {
|
|---|
| 137 | wbc_status = WBC_ERR_INVALID_RESPONSE;
|
|---|
| 138 | BAIL_ON_WBC_ERROR(wbc_status);
|
|---|
| 139 | }
|
|---|
|
|---|