pamsrv_cmd.c revision b42bb7d9dbf9a4c44a03e7bf1bab471a8a85e858
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina PAM Responder
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina Copyright (C) Simo Sorce <ssorce@redhat.com> 2009
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina Copyright (C) Sumit Bose <sbose@redhat.com> 2009
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina This program is free software; you can redistribute it and/or modify
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina it under the terms of the GNU General Public License as published by
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina the Free Software Foundation; either version 3 of the License, or
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina (at your option) any later version.
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina This program is distributed in the hope that it will be useful,
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina GNU General Public License for more details.
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina You should have received a copy of the GNU General Public License
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina#define DEFAULT_PAM_VERBOSITY PAM_VERBOSITY_IMPORTANT
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březinastatic void pam_reply(struct pam_auth_req *preq);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březinastatic int extract_authtok_v2(TALLOC_CTX *mem_ctx, struct sss_auth_token *tok,
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina if (data_size < sizeof(uint32_t) || *c+data_size > blen ||
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina SIZE_T_OVERFLOW(*c, data_size)) return EINVAL;
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina SAFEALIGN_COPY_UINT32_CHECK(&auth_token_type, &body[*c], blen, c);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina auth_token_length = data_size - sizeof(uint32_t);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březinastatic int extract_string(char **var, size_t size, uint8_t *body, size_t blen,
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina if (*c+size > blen || SIZE_T_OVERFLOW(*c, size)) return EINVAL;
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina /* If the string isn't valid UTF-8, fail */
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březinastatic int extract_uint32_t(uint32_t *var, size_t size, uint8_t *body,
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina if (size != sizeof(uint32_t) || *c+size > blen || SIZE_T_OVERFLOW(*c, size))
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina SAFEALIGN_COPY_UINT32_CHECK(var, &body[*c], blen, c);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březinastatic int pd_set_primary_name(const struct ldb_message *msg,struct pam_data *pd)
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina name = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, ("A user with no name?\n"));
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina DEBUG(SSSDBG_TRACE_FUNC, ("User's primary name is %s\n", name));
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březinastatic int pam_parse_in_data_v2(struct sss_domain_info *domains,
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina ((uint32_t *)body)[0] != SSS_START_OF_PAM_REQUEST ||
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina memcmp(&body[blen - sizeof(uint32_t)], &terminator, sizeof(uint32_t)) != 0) {
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina SAFEALIGN_COPY_UINT32_CHECK(&type, &body[c], blen, &c);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina SAFEALIGN_COPY_UINT32_CHECK(&size, &body[c], blen, &c);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina /* the uint32_t end maker SSS_END_OF_PAM_REQUEST does not count to
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina * the remaining buffer */
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina ret = extract_string(&pam_user, size, body, blen, &c);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina ret = extract_string(&pd->service, size, body, blen, &c);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina ret = extract_string(&pd->tty, size, body, blen, &c);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina ret = extract_string(&pd->ruser, size, body, blen, &c);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina ret = extract_string(&pd->rhost, size, body, blen, &c);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina DEBUG(1,("Ignoring unknown data type [%d].\n", type));
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina } while(c < blen);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina if (pd->user == NULL || *pd->user == '\0') return EINVAL;
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březinastatic int pam_parse_in_data_v3(struct sss_domain_info *domains,
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina ret = pam_parse_in_data_v2(domains, default_domain, pd, body, blen);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březinastatic int extract_authtok_v1(TALLOC_CTX *mem_ctx, struct sss_auth_token *tok,
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina SAFEALIGN_COPY_UINT32_CHECK(&auth_token_type, &body[*c], blen, c);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina SAFEALIGN_COPY_UINT32_CHECK(&auth_token_length, &body[*c], blen, c);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březinastatic int pam_parse_in_data(struct sss_domain_info *domains,
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina /* user name */
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina for (start = end; end < last; end++) if (body[end] == '\0') break;
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina ret = sss_parse_name_for_domains(pd, domains, default_domain,
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina (char *)&body[start], &pd->domain, &pd->user);
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina for (start = end; end < last; end++) if (body[end] == '\0') break;
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina for (start = end; end < last; end++) if (body[end] == '\0') break;
d3c82d0170d6d7407549afdadd08aa7e11aeb9a2Pavel Březina for (start = end; end < last; end++) if (body[end] == '\0') break;
if (ret) {
return ret;
if (ret) {
return ret;
return EOK;
if (!attrs) {
goto fail;
goto fail;
goto fail;
goto fail;
return EOK;
fail:
return ret;
int ret;
int pam_verbosity;
return EINVAL;
switch (user_info_type) {
return EINVAL;
sizeof(int64_t));
if ((expire_date == 0 &&
(expire_date > 0 &&
return EOK;
int ret;
case SSS_PAM_AUTHENTICATE:
goto done;
if (ret) {
goto done;
case SSS_PAM_CHAUTHTOK_PRELIM:
case SSS_PAM_CHAUTHTOK:
goto done;
case SSS_PAM_SETCRED:
case SSS_PAM_ACCT_MGMT:
case SSS_PAM_OPEN_SESSION:
case SSS_PAM_CLOSE_SESSION:
goto done;
goto done;
goto done;
goto done;
goto done;
resp_c = 0;
resp_size = 0;
resp_c++;
sizeof(int32_t) +
goto done;
p += sizeof(int32_t);
p += sizeof(int32_t);
p += sizeof(int32_t);
p += sizeof(int32_t);
done:
case PAM_SUCCESS:
case PAM_PERM_DENIED:
if (delayed_until >= 0) {
goto done;
done:
return ret;
int ret;
if (!preq) {
return ENOMEM;
return ENOMEM;
goto done;
goto done;
goto done;
dom;
if (!dom) {
goto done;
goto done;
done:
struct pam_auth_req);
goto done;
goto done;
goto done;
done:
int ret;
while (dom) {
if (!dom) break;
if (!name) {
return ENOMEM;
return EIO;
return EFAULT;
return EIO;
return ENOENT;
return ENOENT;
SYSDB_CACHE_EXPIRE, 0);
return ret;
return EOK;
if (!dom) {
if (!dpreq) {
return ENOMEM;
if(!cb_ctx) {
return ENOMEM;
return EAGAIN;
return ENOENT;
char *err_msg;
&err_msg);
switch (ret) {
case EOK:
case EAGAIN:
case ENOENT:
return EOK;
int ret;
char *name;
if (err_maj) {
if (!name) {
goto done;
done:
if (ret) {
int ret;
return pam_cli_protocol_version;
return sss_cmds;