_PUBLIC_ void cli_credentials_parse_string(struct cli_credentials *credentials, const char *data, enum credentials_obtained obtained) { char *uname, *p; if (strcmp("%",data) == 0) { cli_credentials_set_anonymous(credentials); return; } uname = talloc_strdup(credentials, data); if ((p = strchr_m(uname,'%'))) { *p = 0; cli_credentials_set_password(credentials, p+1, obtained); } if ((p = strchr_m(uname,'@'))) { cli_credentials_set_principal(credentials, uname, obtained); *p = 0; cli_credentials_set_realm(credentials, p+1, obtained); return; } else if ((p = strchr_m(uname,'\\')) || (p = strchr_m(uname, '/'))) { *p = 0; cli_credentials_set_domain(credentials, uname, obtained); uname = p+1; } cli_credentials_set_username(credentials, uname, obtained); }
static PyObject *py_creds_set_principal(PyObject *self, PyObject *args) { char *newval; enum credentials_obtained obt = CRED_SPECIFIED; int _obt = obt; if (!PyArg_ParseTuple(args, "s|i", &newval, &_obt)) { return NULL; } obt = _obt; return PyBool_FromLong(cli_credentials_set_principal(PyCredentials_AsCliCredentials(self), newval, obt)); }
int cli_credentials_set_from_ccache(struct cli_credentials *cred, enum credentials_obtained obtained) { krb5_principal princ; krb5_error_code ret; char *name; char **realm; if (cred->ccache_obtained > obtained) { return 0; } ret = krb5_cc_get_principal(cred->ccache->smb_krb5_context->krb5_context, cred->ccache->ccache, &princ); if (ret) { char *err_mess = smb_get_krb5_error_message(cred->ccache->smb_krb5_context->krb5_context, ret, cred); DEBUG(1,("failed to get principal from ccache: %s\n", err_mess)); talloc_free(err_mess); return ret; } ret = krb5_unparse_name(cred->ccache->smb_krb5_context->krb5_context, princ, &name); if (ret) { char *err_mess = smb_get_krb5_error_message(cred->ccache->smb_krb5_context->krb5_context, ret, cred); DEBUG(1,("failed to unparse principal from ccache: %s\n", err_mess)); talloc_free(err_mess); return ret; } realm = krb5_princ_realm(cred->ccache->smb_krb5_context->krb5_context, princ); cli_credentials_set_principal(cred, name, obtained); free(name); krb5_free_principal(cred->ccache->smb_krb5_context->krb5_context, princ); cred->ccache_obtained = obtained; return 0; }
static int cli_credentials_set_from_ccache(struct cli_credentials *cred, struct ccache_container *ccache, enum credentials_obtained obtained, const char **error_string) { krb5_principal princ; krb5_error_code ret; char *name; if (cred->ccache_obtained > obtained) { return 0; } ret = krb5_cc_get_principal(ccache->smb_krb5_context->krb5_context, ccache->ccache, &princ); if (ret) { (*error_string) = talloc_asprintf(cred, "failed to get principal from ccache: %s\n", smb_get_krb5_error_message(ccache->smb_krb5_context->krb5_context, ret, cred)); return ret; } ret = krb5_unparse_name(ccache->smb_krb5_context->krb5_context, princ, &name); if (ret) { (*error_string) = talloc_asprintf(cred, "failed to unparse principal from ccache: %s\n", smb_get_krb5_error_message(ccache->smb_krb5_context->krb5_context, ret, cred)); return ret; } cli_credentials_set_principal(cred, name, obtained); free(name); krb5_free_principal(ccache->smb_krb5_context->krb5_context, princ); /* set the ccache_obtained here, as it just got set to UNINITIALISED by the calls above */ cred->ccache_obtained = obtained; return 0; }