static Npfcall* openssl_auth(Npfid *afid, Npstr *uname, Npstr *aname) {
    struct openssl_session_auth_context* ctx;
    Npqid aqid;

    ctx = new_session_context(afid);
    if ( ctx == NULL )
        return np_create_rerror("No mem",ENOMEM,1);


    ctx->uname = malloc(uname->len);
    if ( !ctx->uname )
        return np_create_rerror("No mem",ENOMEM,1);

    memcpy(ctx->uname, uname->str, uname->len);

    afid->aux = ctx;

    np_fid_incref(afid);

    pthread_create(&ctx->auth_thread, NULL, run_auth, ctx);

    aqid.type = Qtauth;

    return np_create_rauth(&aqid);
    //return execute_openssl_auth_protocol(ctx);
}
Esempio n. 2
0
Npfcall *
np_auth(Npreq *req, Npfcall *tc)
{
	Npconn *conn = req->conn;
	Npsrv *srv = conn->srv;
	Npfid *afid = req->fid;
	Npfcall *rc = NULL;
	Npqid aqid;
	char a[128];
	int auth_required = _authrequired(srv, &tc->u.tauth.uname,
					       tc->u.tauth.n_uname,
					       &tc->u.tauth.aname);

	if (tc->u.tauth.n_uname != P9_NONUNAME) {
		snprintf (a, sizeof(a), "auth(%d@%s:%.*s)",
			  tc->u.tauth.n_uname,
			  np_conn_get_client_id (conn), 
			  tc->u.tauth.aname.len, tc->u.tauth.aname.str);
	} else {
		snprintf (a, sizeof(a), "auth(%.*s@%s:%.*s)",
			  tc->u.tauth.uname.len, tc->u.tauth.uname.str,
			  np_conn_get_client_id (conn),
			  tc->u.tauth.aname.len, tc->u.tauth.aname.str);
	}
	if (!auth_required) {
		if (!(rc = np_create_rlerror(0))) {
			np_uerror(ENOMEM);
			np_logerr (srv, "%s: creating response", a);
		}
		goto error;
	}
	if (!afid) {
		np_uerror (EIO);
		np_logerr (srv, "%s: invalid afid (%d)", a, tc->u.tauth.afid);
		goto error;
	}
	np_fid_incref(afid);
	if (!(afid->user = np_attach2user (srv, &tc->u.tauth.uname,
				     		 tc->u.tauth.n_uname))) {
		np_logerr (srv, "%s: user lookup", a);
		goto error;
	}
	afid->type = P9_QTAUTH;
	if (!srv->auth->startauth(afid, afid->aname, &aqid)) {
		np_logerr (srv, "%s: startauth", a);
		goto error;
	}
	assert((aqid.type & P9_QTAUTH));
	if (!(rc = np_create_rauth(&aqid))) {
		np_uerror(ENOMEM);
		np_logerr (srv, "%s: creating response", a);
		goto error;
	}
error:
	return rc;
}
Esempio n. 3
0
static void
test_rauth (void)
{
    Npfcall *fc, *fc2;
    struct p9_qid qid = { 1, 2, 3 };

    if (!(fc = np_create_rauth (&qid)))
        msg_exit ("out of memory in %s", __FUNCTION__); 
    fc2 = _rcv_buf (fc, P9_RAUTH, __FUNCTION__);

    assert (fc->u.rauth.qid.type == fc2->u.rauth.qid.type);
    assert (fc->u.rauth.qid.version == fc2->u.rauth.qid.version);
    assert (fc->u.rauth.qid.path == fc2->u.rauth.qid.path);

    free (fc);
    free (fc2);
}