Ejemplo n.º 1
0
static int plain_auth_init(void **ctx, void *pool, const char *username, const char *ip, const char *our_ip, unsigned pid)
{
	struct plain_ctx_st *pctx;
	int ret;

	if (username == NULL || username[0] == 0) {
		syslog(LOG_AUTH,
		       "plain-auth: no username present");
		return ERR_AUTH_FAIL;
	}

	pctx = talloc_zero(pool, struct plain_ctx_st);
	if (pctx == NULL)
		return ERR_AUTH_FAIL;

	strlcpy(pctx->username, username, sizeof(pctx->username));
	pctx->pass_msg = NULL; /* use default */

	ret = read_auth_pass(pctx);
	if (ret < 0) {
		talloc_free(pctx);
		return ERR_AUTH_FAIL;
	}

	*ctx = pctx;

	return ERR_AUTH_CONTINUE;
}
Ejemplo n.º 2
0
static int plain_auth_init(void **ctx, void *pool, const common_auth_init_st *info)
{
    struct plain_ctx_st *pctx;
    int ret;

    if (info->username == NULL || info->username[0] == 0) {
        syslog(LOG_AUTH,
               "plain-auth: no username present");
        return ERR_AUTH_FAIL;
    }

    pctx = talloc_zero(pool, struct plain_ctx_st);
    if (pctx == NULL)
        return ERR_AUTH_FAIL;

    strlcpy(pctx->username, info->username, sizeof(pctx->username));
    pctx->pass_msg = NULL; /* use default */

    /* this doesn't fail on password mismatch but sets p->failed */
    ret = read_auth_pass(pctx);
    if (ret < 0) {
        talloc_free(pctx);
        return ERR_AUTH_FAIL;
    }

    *ctx = pctx;

    if (pctx->cpass[0] == 0 && pctx->failed == 0) {
        /* if there is no password set, nor an OTP file; don't ask for password */
        if (otp_file == NULL)
            return 0;

        /* only OTP is present */
        pctx->pass_msg = pass_msg_otp;
    }

    return ERR_AUTH_CONTINUE;
}