taskrambler  0.1.9
Web server and task management solution.
ldap.c File Reference
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ldap.h>
#include "class.h"
#include "uuid.h"
#include "utils/memory.h"
#include "commons.h"
#include "auth/credential.h"
#include "auth/interface/auth.h"
+ Include dependency graph for ldap.c:

Go to the source code of this file.

Functions

static int authLdapCtor (void *_this, va_list *params)
 
static void authLdapDtor (void *_this)
 
static int authLdapAuthenticate (void *_this, Credential cred, Uuid user_index)
 
 INIT_IFACE (Class, authLdapCtor, authLdapDtor, NULL)
 
 INIT_IFACE (Auth, authLdapAuthenticate)
 
 CREATE_CLASS (AuthLdap, NULL, IFACE(Class), IFACE(Auth))
 

Detailed Description

Author
Georg Hopp

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file ldap.c.

Function Documentation

static int authLdapAuthenticate ( void *  _this,
Credential  cred,
Uuid  user_index 
)
static
Todo:
here we need to get and return the user id
Todo:
do error logging instead.

Definition at line 73 of file ldap.c.

References CRED_PASSWORD, CRED_PWD, FALSE, and TRUE.

74 {
75  AuthLdap this = _this;
76  char who[256];
77  char * who_ptr = who;
78  int ldap_err;
79 
80  struct berval ldap_cred;
81  struct berval * ldap_servcred;
82 
83  if (CRED_PASSWORD != cred->type) {
84  return FALSE;
85  }
86 
87  ldap_initialize(&(this->ldap), this->url);
88  ldap_set_option(this->ldap, LDAP_OPT_PROTOCOL_VERSION, &(this->version));
89 
90  memcpy(who_ptr, "cn=", sizeof("cn=") - 1);
91  who_ptr += sizeof("cn=") - 1;
92  memcpy(who_ptr, CRED_PWD(cred).user, CRED_PWD(cred).nuser);
93  who_ptr += CRED_PWD(cred).nuser;
94  *who_ptr++ = ',';
95  memcpy(who_ptr, this->base_dn, this->nbase_dn);
96  who_ptr[this->nbase_dn] = 0;
97 
98  ldap_cred.bv_val = CRED_PWD(cred).pass;
99  ldap_cred.bv_len = CRED_PWD(cred).npass;
100  ldap_err = ldap_sasl_bind_s(
101  this->ldap,
102  who,
103  LDAP_SASL_SIMPLE,
104  &ldap_cred,
105  NULL,
106  NULL,
107  &ldap_servcred);
108 
109  ldap_unbind_ext_s(this->ldap, NULL, NULL);
110 
111  if (0 == ldap_err) {
112  //! \todo here we need to get and return the user id
113  return TRUE;
114  }
115 
116  //fprintf(stderr, "%s\n", ldap_err2string(ldap_err));
117  /** \todo do error logging instead. */
118  return FALSE;
119 }
#define FALSE
Definition: commons.h:28
#define TRUE
Definition: commons.h:27
#define CRED_PWD(c)
Definition: credential.h:30
static int authLdapCtor ( void *  _this,
va_list *  params 
)
static

Definition at line 40 of file ldap.c.

References memMalloc().

41 {
42  AuthLdap this = _this;
43  char * url = va_arg(*params, char*);
44  char * base_dn;
45 
46  this->url = memMalloc(strlen(url) + 1);
47  strcpy(this->url, url);
48 
49  this->version = 3;
50 
51  base_dn = va_arg(* params, char *);
52  this->nbase_dn = va_arg(* params, size_t);
53 
54  this->base_dn = memMalloc(this->nbase_dn + 1);
55  this->base_dn[this->nbase_dn] = 0;
56  memcpy(this->base_dn, base_dn, this->nbase_dn);
57 
58  return 0;
59 }
void * memMalloc(size_t)
Definition: memory.c:783

+ Here is the call graph for this function:

static void authLdapDtor ( void *  _this)
static

Definition at line 63 of file ldap.c.

References MEM_FREE.

64 {
65  AuthLdap this = _this;
66 
67  MEM_FREE(this->base_dn);
68  MEM_FREE(this->url);
69 }
#define MEM_FREE(seg)
Definition: memory.h:28
CREATE_CLASS ( AuthLdap  ,
NULL  ,
IFACE(Class)  ,
IFACE(Auth)   
)
INIT_IFACE ( Class  ,
authLdapCtor  ,
authLdapDtor  ,
NULL   
)
INIT_IFACE ( Auth  ,
authLdapAuthenticate   
)