summaryrefslogtreecommitdiff
path: root/daemon/basic.c
blob: 1d476cae77dd99b0c25bc6b4b4cb44974b81ad3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

#include "usuals.h"
#include "httpauthd.h"
#include "basic.h"

int basic_parse(const char* header, ha_buffer_t* buf, basic_header_t* rec)
{
  char* t;
  ASSERT(header && buf && rec);

  memset(rec, 0, sizeof(*rec));

  /* Trim the white space */
  while(*header && isspace(*header))
    header++;

  /*
   * Authorization header is in this format:
   *
   * "Basic " B64(user ":" password)
   */
  header = (const char*)ha_bufdec64(buf, header, NULL);

  if(!header)
    return ha_buferr(buf) ? HA_CRITERROR : HA_FALSE;


  /* We have a cache key at this point so hash it */
  md5_string(rec->key, header);


  /* Parse the user. We need it in any case */
  t = strchr(header, ':');
  if(t != NULL)
  {
    /* Break the string in half */
    *t = 0;

    rec->user = header;
    rec->password = t + 1;
  }

  return HA_OK;
}