Exemple #1
0
static int auth_check(Octstr *user, Octstr *pass, List *headers, int *has_auth_hdr)
{
     int i, res = -1;
     Octstr *v = http_header_value(headers, octstr_imm("Authorization"));
     Octstr *p = NULL, *q = NULL;

     *has_auth_hdr = (v != NULL);
     if (octstr_len(user) == 0) {
	  res = 0;
	  goto done;
     }

     if (!v ||
	 octstr_search(v, octstr_imm("Basic "), 0) != 0)
	  goto done;
     p = octstr_copy(v, sizeof "Basic", octstr_len(v));
     octstr_base64_to_binary(p);
     
     i = octstr_search_char(p, ':', 0);
     q = octstr_copy(p, i+1, octstr_len(p));
     octstr_delete(p, i, octstr_len(p));
     
     /* p = user, q = pass. */

     if (octstr_compare(user, p) != 0 ||
	 octstr_compare(pass, q) != 0)
	  res = -1;
     else 
	  res = 0;
done:
     octstr_destroy(v);
     octstr_destroy(p);     
     octstr_destroy(q);
     return res;
}
Exemple #2
0
int operate_single_mime(Octstr *p_psoHdrs, MIMEEntity *p_psoMIME, const char *p_pszWebDir)
{
  int iRetVal = 0;
  Octstr *psoHdrName = NULL, *psoHdrValue = NULL;
  Octstr *psoMIMEOStr = NULL, *psoFileName = NULL;
  List *psoHdrList = NULL;
  int iFile = -1;

  if(psoMIMEOStr) {
    octstr_destroy(psoMIMEOStr);
  }
  /* выбираем необходимые заголовки */
  psoHdrList = mime_entity_headers(p_psoMIME);
  /* Content-type */
  psoHdrName = octstr_create("Content-type");
  psoHdrValue = http_header_value(psoHdrList, psoHdrName);
  if(0 == strncasecmp("application/smil", octstr_get_cstr(psoHdrValue), 16)) {
    goto done;
  }
  octstr_format_append(p_psoHdrs, "\r\n");
  octstr_format_append(p_psoHdrs, "\r\n%S;%S", psoHdrName, psoHdrValue);
  octstr_truncate(psoHdrName, 0);
  /* Content-location */
  octstr_append_cstr(psoHdrName, "Content-location");
  psoHdrValue = http_header_value(psoHdrList, psoHdrName);
  octstr_format_append(p_psoHdrs, "\r\n%S;%S", psoHdrName, psoHdrValue);
  octstr_truncate(psoHdrName, 0);
  /**/

  /* формируем имя файла */
  psoFileName = octstr_create(p_pszWebDir);
  if('/' != octstr_get_char(psoFileName, octstr_len(psoFileName) - 1)) {
    octstr_append_char(psoFileName, '/');
  }
  octstr_append(psoFileName, psoHdrValue);
  /* создаем файл */
  iFile = open(octstr_get_cstr(psoFileName), O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  if(0 > iFile) {
    if(errno != EEXIST) {
      iRetVal = 7;
      goto done;
    }
  }
  psoMIMEOStr = mime_entity_body(p_psoMIME);
  octstr_base64_to_binary(psoMIMEOStr);
  if(octstr_len(psoMIMEOStr) != write(iFile, octstr_get_cstr(psoMIMEOStr), octstr_len(psoMIMEOStr))) {
    iRetVal = 8;
    goto done;
  }

  done:
  if(psoHdrName) {
    octstr_destroy(psoHdrName);
  }
  if(psoFileName) {
    octstr_destroy(psoFileName);
  }
  if(0 < iFile) {
    close(iFile);
  }

  return iRetVal;
}