File: sasl_init.c

package info (click to toggle)
cvm 0.97-0.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,036 kB
  • sloc: ansic: 4,065; sh: 2,758; makefile: 235; sql: 15
file content (47 lines) | stat: -rw-r--r-- 1,355 bytes parent folder | download
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
46
47
#include <stdlib.h>
#include <string.h>
#include <bglibs/ucspi.h>
#include "sasl.h"
#include "sasl_internal.h"

static struct sasl_mechanism mechanisms[4] = {
  { "LOGIN",    "CVM_SASL_PLAIN",    0, sasl_login_start,    0 },
  { "PLAIN",    "CVM_SASL_PLAIN",    0, sasl_plain_start,    0 },
  { "CRAM-MD5", "CVM_SASL_CRAM_MD5", 0, sasl_cram_md5_start, 0 },
  { 0,           0,                  0, 0,                   0 },
};

const struct sasl_mechanism* sasl_mechanisms;

static void set_mech(struct sasl_mechanism* mech, const char* cvm,
		     struct sasl_mechanism** prev,
		     struct sasl_mechanism** first)
{
  mech->cvm = cvm;
  if (*prev != 0)
    (*prev)->next = mech;
  else if (*first == 0)
    *prev = *first = mech;
}

int sasl_init(struct sasl_state* ss)
{
  struct sasl_mechanism* prev;
  struct sasl_mechanism* first;
  struct sasl_mechanism* mech;
  const char* tmp;
  for (mech = mechanisms, first = 0, prev = 0; mech->name != 0; ++mech) {
    if ((tmp = getenv(mech->var)) != 0)
      set_mech(mech, tmp, &prev, &first);
  }
  /* backwards compatibility for $CVM_SASL_LOGIN */
  if (!mechanisms[0].cvm && (tmp = getenv("CVM_SASL_LOGIN")) != 0) {
    prev = 0;
    first = 0;
    set_mech(&mechanisms[0], tmp, &prev, &first);
  }
  sasl_mechanisms = first;
  memset(ss, 0, sizeof *ss);
  ss->domain = ucspi_localhost();
  return 1;
}