~ubuntu-branches/ubuntu/utopic/nss-pam-ldapd/utopic-proposed

« back to all changes in this revision

Viewing changes to nslcd/common.h

  • Committer: Bazaar Package Importer
  • Author(s): Arthur de Jong
  • Date: 2009-09-01 17:00:00 UTC
  • Revision ID: james.westby@ubuntu.com-20090901170000-54hqcpmbxk32rzer
Tags: 0.7.0
* rename software to nss-pam-ldapd to indicate that PAM module is now a
  standard part of the software
* split into the binary packages libnss-ldapd, libpam-ldapd and nslcd
  (libpam-ldapd packaging used a patch for libpam-ldap by Steve Langasek)
  (closes: #535505)
* the configuration file name has been changed to /etc/nslcd.conf (package
  upgrade should migrate the configuration)
* updated Galician debconf translation by Marce Villarino (closes: #537424)
* patch by Petter Reinholdtsen to fix init script to start before autofs
  (closes: #544093)
* the default values for bind_timelimit and reconnect_maxsleeptime were
  lowered from 30 to 10 seconds (closes: #532874)
* upgrade to standards-version 3.8.3 (no changes needed)
* password hashes are no longer returned to non-root users (based on a patch
  by Alexander V. Chernikov)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   common.h - common server code routines
 
3
   This file is part of the nss-pam-ldapd library.
 
4
 
 
5
   Copyright (C) 2006 West Consulting
 
6
   Copyright (C) 2006, 2007, 2008, 2009 Arthur de Jong
 
7
 
 
8
   This library is free software; you can redistribute it and/or
 
9
   modify it under the terms of the GNU Lesser General Public
 
10
   License as published by the Free Software Foundation; either
 
11
   version 2.1 of the License, or (at your option) any later version.
 
12
 
 
13
   This library is distributed in the hope that it will be useful,
 
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
   Lesser General Public License for more details.
 
17
 
 
18
   You should have received a copy of the GNU Lesser General Public
 
19
   License along with this library; if not, write to the Free Software
 
20
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
21
   02110-1301 USA
 
22
*/
 
23
 
 
24
#ifndef _SERVER_COMMON_H
 
25
#define _SERVER_COMMON_H 1
 
26
 
 
27
#include "nslcd.h"
 
28
#include "common/nslcd-prot.h"
 
29
#include "common/tio.h"
 
30
#include "compat/attrs.h"
 
31
#include "myldap.h"
 
32
 
 
33
/* macros for basic read and write operations, the following
 
34
   ERROR_OUT* marcos define the action taken on errors
 
35
   the stream is not closed because the caller closes the
 
36
   stream */
 
37
 
 
38
#define ERROR_OUT_WRITEERROR(fp) \
 
39
  log_log(LOG_WARNING,"error writing to client"); \
 
40
  return -1;
 
41
 
 
42
#define ERROR_OUT_READERROR(fp) \
 
43
  log_log(LOG_WARNING,"error reading from client"); \
 
44
  return -1;
 
45
 
 
46
#define ERROR_OUT_BUFERROR(fp) \
 
47
  log_log(LOG_WARNING,"client supplied argument too large"); \
 
48
  return -1;
 
49
 
 
50
/* a simple wrapper around snprintf,
 
51
   returns 0 if ok, -1 on error */
 
52
int mysnprintf(char *buffer,size_t buflen,const char *format, ...)
 
53
  LIKE_PRINTF(3,4);
 
54
 
 
55
/* This tries to get the user password attribute from the entry.
 
56
   It will try to return an encrypted password as it is used in /etc/passwd,
 
57
   /etc/group or /etc/shadow depending upon what is in the directory.
 
58
   This function will return NULL if no passwd is found and will return the
 
59
   literal value in the directory if conversion is not possible. */
 
60
const char *get_userpassword(MYLDAP_ENTRY *entry,const char *attr);
 
61
 
 
62
/* write out an address, parsing the addr value */
 
63
int write_address(TFILE *fp,const char *addr);
 
64
 
 
65
/* a helper macro to write out addresses and bail out on errors */
 
66
#define WRITE_ADDRESS(fp,addr) \
 
67
  if (write_address(fp,addr)) \
 
68
    return -1;
 
69
 
 
70
/* read an address from the stream */
 
71
int read_address(TFILE *fp,char *addr,int *addrlen,int *af);
 
72
 
 
73
/* helper macro to read an address from the stream */
 
74
#define READ_ADDRESS(fp,addr,len,af) \
 
75
  len=(int)sizeof(addr); \
 
76
  if (read_address(fp,addr,&(len),&(af))) \
 
77
    return -1;
 
78
 
 
79
/* checks to see if the specified string is a valid user or group name */
 
80
MUST_USE int isvalidname(const char *name);
 
81
 
 
82
/* Perform an LDAP lookup to translate the DN into a uid.
 
83
   This function either returns NULL or a strdup()ed string. */
 
84
MUST_USE char *lookup_dn2uid(MYLDAP_SESSION *session,const char *dn,int *rcp);
 
85
 
 
86
/* transforms the DN info a uid doing an LDAP lookup if needed */
 
87
MUST_USE char *dn2uid(MYLDAP_SESSION *session,const char *dn,char *buf,size_t buflen);
 
88
 
 
89
/* use the user id to lookup an LDAP entry */
 
90
MYLDAP_ENTRY *uid2entry(MYLDAP_SESSION *session,const char *uid);
 
91
 
 
92
/* transforms the uid into a DN by doing an LDAP lookup */
 
93
MUST_USE char *uid2dn(MYLDAP_SESSION *session,const char *uid,char *buf,size_t buflen);
 
94
 
 
95
/* these are the functions for initialising the database specific
 
96
   modules */
 
97
void alias_init(void);
 
98
void ether_init(void);
 
99
void group_init(void);
 
100
void host_init(void);
 
101
void netgroup_init(void);
 
102
void network_init(void);
 
103
void passwd_init(void);
 
104
void protocol_init(void);
 
105
void rpc_init(void);
 
106
void service_init(void);
 
107
void shadow_init(void);
 
108
 
 
109
/* these are the different functions that handle the database
 
110
   specific actions, see nslcd.h for the action descriptions */
 
111
int nslcd_alias_byname(TFILE *fp,MYLDAP_SESSION *session);
 
112
int nslcd_alias_all(TFILE *fp,MYLDAP_SESSION *session);
 
113
int nslcd_ether_byname(TFILE *fp,MYLDAP_SESSION *session);
 
114
int nslcd_ether_byether(TFILE *fp,MYLDAP_SESSION *session);
 
115
int nslcd_ether_all(TFILE *fp,MYLDAP_SESSION *session);
 
116
int nslcd_group_byname(TFILE *fp,MYLDAP_SESSION *session);
 
117
int nslcd_group_bygid(TFILE *fp,MYLDAP_SESSION *session);
 
118
int nslcd_group_bymember(TFILE *fp,MYLDAP_SESSION *session);
 
119
int nslcd_group_all(TFILE *fp,MYLDAP_SESSION *session);
 
120
int nslcd_host_byname(TFILE *fp,MYLDAP_SESSION *session);
 
121
int nslcd_host_byaddr(TFILE *fp,MYLDAP_SESSION *session);
 
122
int nslcd_host_all(TFILE *fp,MYLDAP_SESSION *session);
 
123
int nslcd_netgroup_byname(TFILE *fp,MYLDAP_SESSION *session);
 
124
int nslcd_network_byname(TFILE *fp,MYLDAP_SESSION *session);
 
125
int nslcd_network_byaddr(TFILE *fp,MYLDAP_SESSION *session);
 
126
int nslcd_network_all(TFILE *fp,MYLDAP_SESSION *session);
 
127
int nslcd_passwd_byname(TFILE *fp,MYLDAP_SESSION *session,uid_t calleruid);
 
128
int nslcd_passwd_byuid(TFILE *fp,MYLDAP_SESSION *session,uid_t calleruid);
 
129
int nslcd_passwd_all(TFILE *fp,MYLDAP_SESSION *session,uid_t calleruid);
 
130
int nslcd_protocol_byname(TFILE *fp,MYLDAP_SESSION *session);
 
131
int nslcd_protocol_bynumber(TFILE *fp,MYLDAP_SESSION *session);
 
132
int nslcd_protocol_all(TFILE *fp,MYLDAP_SESSION *session);
 
133
int nslcd_rpc_byname(TFILE *fp,MYLDAP_SESSION *session);
 
134
int nslcd_rpc_bynumber(TFILE *fp,MYLDAP_SESSION *session);
 
135
int nslcd_rpc_all(TFILE *fp,MYLDAP_SESSION *session);
 
136
int nslcd_service_byname(TFILE *fp,MYLDAP_SESSION *session);
 
137
int nslcd_service_bynumber(TFILE *fp,MYLDAP_SESSION *session);
 
138
int nslcd_service_all(TFILE *fp,MYLDAP_SESSION *session);
 
139
int nslcd_shadow_byname(TFILE *fp,MYLDAP_SESSION *session);
 
140
int nslcd_shadow_all(TFILE *fp,MYLDAP_SESSION *session);
 
141
int nslcd_pam_authc(TFILE *fp,MYLDAP_SESSION *session);
 
142
int nslcd_pam_authz(TFILE *fp,MYLDAP_SESSION *session);
 
143
int nslcd_pam_sess_o(TFILE *fp,MYLDAP_SESSION *session);
 
144
int nslcd_pam_sess_c(TFILE *fp,MYLDAP_SESSION *session);
 
145
int nslcd_pam_pwmod(TFILE *fp,MYLDAP_SESSION *session);
 
146
 
 
147
/* macros for generating service handling code */
 
148
#define NSLCD_HANDLE(db,fn,readfn,logcall,action,mkfilter,writefn) \
 
149
  NSLCD_HANDLE_PARAMS(db,fn,,readfn,logcall,action,mkfilter,writefn)
 
150
#define COMMA ,
 
151
#define NSLCD_HANDLE_UID(db,fn,readfn,logcall,action,mkfilter,writefn) \
 
152
  NSLCD_HANDLE_PARAMS(db,fn,COMMA uid_t calleruid,readfn,logcall,action,mkfilter,writefn)
 
153
#define NSLCD_HANDLE_PARAMS(db,fn,params,readfn,logcall,action,mkfilter,writefn) \
 
154
  int nslcd_##db##_##fn(TFILE *fp,MYLDAP_SESSION *session params ) \
 
155
  { \
 
156
    /* define common variables */ \
 
157
    int32_t tmpint32; \
 
158
    MYLDAP_SEARCH *search; \
 
159
    MYLDAP_ENTRY *entry; \
 
160
    const char *base; \
 
161
    int rc,i; \
 
162
    /* read request parameters */ \
 
163
    readfn; \
 
164
    /* log call */ \
 
165
    logcall; \
 
166
    /* write the response header */ \
 
167
    WRITE_INT32(fp,NSLCD_VERSION); \
 
168
    WRITE_INT32(fp,action); \
 
169
    /* prepare the search filter */ \
 
170
    if (mkfilter) \
 
171
    { \
 
172
      log_log(LOG_WARNING,"nslcd_" __STRING(db) "_" __STRING(fn) "(): filter buffer too small"); \
 
173
      return -1; \
 
174
    } \
 
175
    /* perform a search for each search base */ \
 
176
    for (i=0; (base=db##_bases[i])!=NULL; i++) \
 
177
    { \
 
178
      /* do the LDAP search */ \
 
179
      if ((search=myldap_search(session,base,db##_scope,filter,db##_attrs))==NULL) \
 
180
        return -1; \
 
181
      /* go over results */ \
 
182
      while ((entry=myldap_get_entry(search,&rc))!=NULL) \
 
183
      { \
 
184
        if (writefn) \
 
185
          return -1; \
 
186
      } \
 
187
    } \
 
188
    /* write the final result code */ \
 
189
    if (rc==LDAP_SUCCESS) \
 
190
    { \
 
191
      WRITE_INT32(fp,NSLCD_RESULT_END); \
 
192
    } \
 
193
    return 0; \
 
194
  }
 
195
 
 
196
#endif /* not _SERVER_COMMON_H */