static void client (Gsasl * ctx) { Gsasl_session *session; const char *mech = "PLAIN"; int rc; /* Create new authentication session. */ if ((rc = gsasl_client_start (ctx, mech, &session)) != GSASL_OK) { printf ("Cannot initialize client (%d): %s\n", rc, gsasl_strerror (rc)); return; } /* Set username and password in session handle. This info will be lost when this session is deallocated below. */ gsasl_property_set (session, GSASL_AUTHID, "jas"); gsasl_property_set (session, GSASL_PASSWORD, "secret"); /* Do it. */ client_authenticate (session); /* Cleanup. */ gsasl_finish (session); }
TH_HDL client_handler(void* client) { client_t* cli = (client_t*)client; char buff[BUFF_SIZE]; cli->running = true; if(cli->server->auth && !client_authenticate(cli)) cli->running = false; while(cli->running && cli->server->running) { //readline int r = read_line(cli->sock, buff, BUFF_SIZE, true); if(r <= 0) break; request_t req; _log(LVL_TRACE, "Request received : %s\n", buff); if(decode_request(cli, &req, buff, r) < 0) continue; // Process request process_request(&req); //Send response encode_reply(&req, buff, BUFF_SIZE); _log(LVL_TRACE, "Reply sent : %s\n", buff); send(cli->sock, buff, strlen(buff), 0); } _log(LVL_TRACE, "Exiting client thread\n", buff); cli->running = false; shutdown(cli->sock, SHUT_WR); close(cli->sock); server_unregister_client(cli->server, cli); free(client); _log(LVL_TRACE, "Client thread exited\n", buff); TH_RETURN; }
static void client (Gsasl * ctx) { Gsasl_session *session; const char *mech = "SECURID"; int rc; /* Create new authentication session. */ if ((rc = gsasl_client_start (ctx, mech, &session)) != GSASL_OK) { printf ("Cannot initialize client (%d): %s\n", rc, gsasl_strerror (rc)); return; } /* Do it. */ client_authenticate (session); /* Cleanup. */ gsasl_finish (session); }