Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.56 KB | None | 0 0
  1. static int password_pipe(request_rec *r)
  2.     {
  3.     apr_table_t *e = r->subprocess_env;
  4.     int fd, wfd;
  5.     apr_size_t  nbytes;
  6.     apr_file_t *readp = NULL;
  7.     apr_file_t *writep = NULL;
  8.     const char *user, *pass, *auth, *userDN, *siepwd;
  9.     char *ans;
  10.     apr_status_t rv;
  11.  
  12.     user = r->user;
  13.     pass = apr_table_get(r->notes, RQ_NOTES_USERPW);
  14.     userDN = apr_table_get(r->notes, RQ_NOTES_USERDN);
  15.     auth = apr_table_get(r->headers_in, "authorization");
  16.     siepwd = ADM_NO_VALUE_STRING;
  17.  
  18.     if (!user) user = ADM_NO_VALUE_STRING;
  19.     if (!pass) pass = ADM_NO_VALUE_STRING;
  20.     if (!auth) auth = ADM_NO_VALUE_STRING;
  21.     if (!userDN) userDN = ADM_NO_VALUE_STRING;
  22.  
  23.     ans = (char*)apr_palloc(r->pool, strlen(user) + strlen(ADM_USER_STRING) +
  24.                         strlen(pass) + strlen(ADM_PASS_STRING) +
  25.                         strlen(auth) + strlen(ADM_AUTH_STRING) +
  26.                         strlen(userDN) + strlen(ADM_USERDN_STRING) +
  27.                         strlen(ADM_SIEPWD_STRING) +
  28.                         strlen(siepwd) + 16);
  29.  
  30.     sprintf(ans, "%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n", ADM_USER_STRING, user,
  31.             ADM_PASS_STRING, pass,
  32.             ADM_AUTH_STRING, auth,
  33.             ADM_USERDN_STRING, userDN,
  34.             ADM_SIEPWD_STRING,
  35.             siepwd);
  36.  
  37.     rv = apr_file_pipe_create(&readp, &writep, r->pool);
  38.  
  39.     if (rv != APR_SUCCESS) {
  40.         ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
  41.                       "mod_admserv: Unable to create pipe");
  42.         return HTTP_INTERNAL_SERVER_ERROR;
  43.     }
  44.  
  45.     /* Get the low-level file descriptor */
  46.     apr_os_file_get(&fd, readp);
  47.     apr_os_file_get(&wfd, writep);
  48.  
  49.     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
  50.                  "password_pipe(): created pipe read %d write %d", fd, wfd);
  51.  
  52.     /* Register a cleanup callback so this gets closed at the end of the
  53.        request. */
  54.     apr_pool_cleanup_register(r->pool, (void *)((intptr_t)fd), close_pipe,
  55.                                       apr_pool_cleanup_null);
  56.  
  57.     /* Send this to the client so they know what fd to read from */
  58.     apr_table_setn(e, "PASSWORD_PIPE",  apr_itoa(r->pool, fd));
  59.  
  60.     nbytes = strlen(ans);
  61.     apr_file_write(writep, ans, &nbytes);
  62.  
  63.     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
  64.                  "password_pipe(): wrote %d bytes", (int)nbytes);
  65.  
  66.     /* Close the writing side, we don't need this any more */
  67.     apr_file_close(writep);
  68.  
  69.     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, NULL,
  70.                  "password_pipe(): closed write descriptor");
  71.  
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement