Esempio n. 1
0
static void rugged_credential_extract_ssh_key_from_agent(git_cred **cred, VALUE rb_credential)
{
	VALUE rb_username = rb_iv_get(rb_credential, "@username");

	Check_Type(rb_username, T_STRING);

	rugged_exception_check(
		git_cred_ssh_key_from_agent(cred, StringValueCStr(rb_username))
	);
}
Esempio n. 2
0
/**
 * Callback if the remote host requires authentication in order to
 * connect to it
 *
 * @param cred The newly created credential object.
 * @param url The resource for which we are demanding a credential.
 * @param user_from_url The username that was embedded in a "user@host"
 * remote url, or NULL if not included.
 * @param allowed_types A bitmask stating which cred types are OK to return.
 * @param payload The payload provided when specifying this callback.
 * @return 0 on success, else -1.
 */
int git2r_cred_acquire_cb(
    git_cred **cred,
    const char *url,
    const char *username_from_url,
    unsigned int allowed_types,
    void *payload)
{
    SEXP credentials, class_name;

    GIT_UNUSED(url);

    if (!payload)
        return -1;

    credentials = ((git2r_transfer_data*)payload)->credentials;
    if (credentials == R_NilValue) {
        if (GIT_CREDTYPE_SSH_KEY & allowed_types) {
            if (git_cred_ssh_key_from_agent(cred, username_from_url))
                return -1;
            return 0;
        }

        return -1;
    }

    class_name = getAttrib(credentials, R_ClassSymbol);
    if (strcmp(CHAR(STRING_ELT(class_name, 0)), "cred_ssh_key") == 0) {
        return git2r_cred_ssh_key(
            cred, username_from_url, allowed_types, credentials);
    } else if (strcmp(CHAR(STRING_ELT(class_name, 0)), "cred_env") == 0) {
        return git2r_cred_env(cred, allowed_types, credentials);
    } else if (strcmp(CHAR(STRING_ELT(class_name, 0)), "cred_token") == 0) {
        return git2r_cred_token(cred, allowed_types, credentials);
    } else if (strcmp(CHAR(STRING_ELT(class_name, 0)), "cred_user_pass") == 0) {
        return git2r_cred_user_pass(cred, allowed_types, credentials);
    }

    return -1;
}
Esempio n. 3
0
/**
 * Callback if the remote host requires authentication in order to
 * connect to it
 *
 * @param cred The newly created credential object.
 * @param url The resource for which we are demanding a credential.
 * @param user_from_url The username that was embedded in a "user@host"
 * remote url, or NULL if not included.
 * @param allowed_types A bitmask stating which cred types are OK to return.
 * @param payload The payload provided when specifying this callback.
 * @return 0 on success, else -1.
 */
int git2r_cred_acquire_cb(
    git_cred **cred,
    const char *url,
    const char *username_from_url,
    unsigned int allowed_types,
    void *payload)
{
    int err = -1;
    SEXP credentials = (SEXP)payload;

    GIT_UNUSED(url);

    if (R_NilValue != credentials) {
        SEXP class_name;

        class_name = getAttrib(credentials, R_ClassSymbol);
        if (0 == strcmp(CHAR(STRING_ELT(class_name, 0)), "cred_ssh_key")) {
            if (GIT_CREDTYPE_SSH_KEY & allowed_types) {
                SEXP slot;
                const char *publickey;
                const char *privatekey = NULL;
                const char *passphrase = NULL;

                publickey = CHAR(STRING_ELT(
                                     GET_SLOT(credentials,
                                              Rf_install("publickey")), 0));
                privatekey = CHAR(STRING_ELT(
                                      GET_SLOT(credentials,
                                               Rf_install("privatekey")), 0));

                slot = GET_SLOT(credentials, Rf_install("passphrase"));
                if (length(slot)) {
                    if (NA_STRING != STRING_ELT(slot, 0))
                        passphrase = CHAR(STRING_ELT(slot, 0));
                }

                err = git_cred_ssh_key_new(
                    cred,
                    username_from_url,
                    publickey,
                    privatekey,
                    passphrase);
            }
        } else if (0 == strcmp(CHAR(STRING_ELT(class_name, 0)), "cred_plaintext")) {
            if (GIT_CREDTYPE_USERPASS_PLAINTEXT & allowed_types) {
                const char *username;
                const char *password;

                username = CHAR(STRING_ELT(
                                    GET_SLOT(credentials,
                                             Rf_install("username")), 0));
                password = CHAR(STRING_ELT(
                                    GET_SLOT(credentials,
                                             Rf_install("password")), 0));

                err = git_cred_userpass_plaintext_new(cred, username, password);
            }
        }
    } else if (GIT_CREDTYPE_SSH_KEY & allowed_types) {
        err = git_cred_ssh_key_from_agent(cred, username_from_url);
    }

    return err;
}