Guest User

Untitled

a guest
May 11th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1.  
  2. /*--------------------------------------------------------------------------------------------------
  3. *
  4. *------------------------------------------------------------------------------------------------*/
  5. static int authorize_user(PGconn *conn, apr_pool_t *pool, char *username, char *password, char *proc_name){
  6. PGresult *res;
  7. char *sql;
  8. char *result;
  9.  
  10.  
  11. if(username == NULL || password == NULL || proc_name == NULL) return 0;
  12.  
  13.  
  14.  
  15. sql = apr_psprintf(pool,"SELECT * FROM %s('%s','%s','%s');",AUTHORIZE_WEB_METHOD,
  16. username,
  17. password,
  18. proc_name);
  19.  
  20. res = PQexec(conn,sql);
  21.  
  22. if(!res){
  23. return 0;
  24. }
  25.  
  26. if(PQresultStatus(res) == PGRES_FATAL_ERROR){
  27. PQclear(res);
  28. return 0;
  29. }
  30.  
  31. if(PQntuples(res) == 0){
  32. PQclear(res);
  33. return 0;
  34. };
  35.  
  36. result = PQgetvalue(res,0,0);
  37.  
  38. if(strcmp(result,"t") == 0){
  39. PQclear(res);
  40. return 1;
  41. } else {
  42. PQclear(res);
  43. return 0;
  44. }
  45. }
Add Comment
Please, Sign In to add comment