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

« back to all changes in this revision

Viewing changes to nslcd/ether.c

  • Committer: Package Import Robot
  • Author(s): Arthur de Jong
  • Date: 2014-06-08 14:00:00 UTC
  • mfrom: (16.1.8) (14.1.12 experimental)
  • Revision ID: package-import@ubuntu.com-20140608140000-rt6fspljmk9252zd
Tags: 0.9.4-1
* upload to unstable
* new upstream release:
  - also handle password policy information on BIND failure (this makes it
    possible to distinguish between a wrong password and an expired
    password)
  - fix mapping the member attribute to an empty string
  - any buffers that may have held passwords are cleared before the memory
    is released
  - increase buffer size for passwords to support extremely long passwords
    (thanks ushi)
  - increase buffer size for DN to support very long names or names with
    non-ASCII characters
  - log an error in almost all places where a defined buffer is not large
    enough to hold the provided data instead of just (sometimes silently)
    failing
  - logging improvements (start-up problems, login failures)
* add signature checking option to watch file
* add a debian/upstream/metadata file

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
   Copyright (C) 1997-2005 Luke Howard
7
7
   Copyright (C) 2006 West Consulting
8
 
   Copyright (C) 2006, 2007, 2009, 2010, 2011 Arthur de Jong
 
8
   Copyright (C) 2006-2014 Arthur de Jong
9
9
 
10
10
   This library is free software; you can redistribute it and/or
11
11
   modify it under the terms of the GNU Lesser General Public
55
55
const char *ether_filter = "(objectClass=ieee802Device)";
56
56
 
57
57
/* the attributes to request with searches */
58
 
const char *attmap_ether_cn          = "cn";
59
 
const char *attmap_ether_macAddress  = "macAddress";
 
58
const char *attmap_ether_cn         = "cn";
 
59
const char *attmap_ether_macAddress = "macAddress";
60
60
 
61
61
/* the attribute list to request with searches */
62
62
static const char *ether_attrs[3];
64
64
/* create a search filter for searching an ethernet address
65
65
   by name, return -1 on errors */
66
66
static int mkfilter_ether_byname(const char *name,
67
 
                                 char *buffer,size_t buflen)
 
67
                                 char *buffer, size_t buflen)
68
68
{
69
 
  char safename[300];
 
69
  char safename[BUFLEN_HOSTNAME];
70
70
  /* escape attribute */
71
 
  if(myldap_escape(name,safename,sizeof(safename)))
 
71
  if (myldap_escape(name, safename, sizeof(safename)))
 
72
  {
 
73
    log_log(LOG_ERR, "mkfilter_ether_byname(): safename buffer too small");
72
74
    return -1;
 
75
  }
73
76
  /* build filter */
74
 
  return mysnprintf(buffer,buflen,
75
 
                   "(&%s(%s=%s))",
76
 
                   ether_filter,
77
 
                   attmap_ether_cn,safename);
 
77
  return mysnprintf(buffer, buflen, "(&%s(%s=%s))",
 
78
                    ether_filter, attmap_ether_cn, safename);
78
79
}
79
80
 
80
81
static int mkfilter_ether_byether(const char *addrstr,
81
 
                                  char *buffer,size_t buflen)
 
82
                                  char *buffer, size_t buflen)
82
83
{
83
 
  /* FIXME: this has a bug when the directory has 01:00:0e:...
84
 
            and we're looking for 1:0:e:... (leading zeros) */
 
84
  /* Note: this only works if the address in LDAP has the preferred minimal
 
85
     representation (e.g. 1:0:e:...) and not with extra leading zeros
 
86
     (e.g. 01:00:0e:...) */
85
87
  /* there should be no characters that need escaping */
86
 
  /* build filter */
87
 
  return mysnprintf(buffer,buflen,
88
 
                   "(&%s(%s=%s))",
89
 
                   ether_filter,
90
 
                   attmap_ether_macAddress,addrstr);
 
88
  return mysnprintf(buffer, buflen, "(&%s(%s=%s))",
 
89
                    ether_filter, attmap_ether_macAddress, addrstr);
91
90
}
92
91
 
93
92
void ether_init(void)
94
93
{
95
94
  int i;
96
95
  /* set up search bases */
97
 
  if (ether_bases[0]==NULL)
98
 
    for (i=0;i<NSS_LDAP_CONFIG_MAX_BASES;i++)
99
 
      ether_bases[i]=nslcd_cfg->ldc_bases[i];
 
96
  if (ether_bases[0] == NULL)
 
97
    for (i = 0; i < NSS_LDAP_CONFIG_MAX_BASES; i++)
 
98
      ether_bases[i] = nslcd_cfg->bases[i];
100
99
  /* set up scope */
101
 
  if (ether_scope==LDAP_SCOPE_DEFAULT)
102
 
    ether_scope=nslcd_cfg->ldc_scope;
 
100
  if (ether_scope == LDAP_SCOPE_DEFAULT)
 
101
    ether_scope = nslcd_cfg->scope;
103
102
  /* set up attribute list */
104
 
  ether_attrs[0]=attmap_ether_cn;
105
 
  ether_attrs[1]=attmap_ether_macAddress;
106
 
  ether_attrs[2]=NULL;
 
103
  ether_attrs[0] = attmap_ether_cn;
 
104
  ether_attrs[1] = attmap_ether_macAddress;
 
105
  ether_attrs[2] = NULL;
107
106
}
108
107
 
109
108
/* TODO: check for errors in aton() */
110
 
#define WRITE_ETHER(fp,addr) \
111
 
  ether_aton_r(addr,&tmpaddr); \
112
 
  WRITE_TYPE(fp,tmpaddr,uint8_t[6]);
 
109
#define WRITE_ETHER(fp, addr)                                               \
 
110
  ether_aton_r(addr, &tmpaddr);                                             \
 
111
  WRITE(fp, &tmpaddr, sizeof(uint8_t[6]));
113
112
 
114
 
static int write_ether(TFILE *fp,MYLDAP_ENTRY *entry,
115
 
                       const char *reqname,const char *reqether)
 
113
static int write_ether(TFILE *fp, MYLDAP_ENTRY *entry,
 
114
                       const char *reqname, const char *reqether)
116
115
{
117
116
  int32_t tmpint32;
118
117
  struct ether_addr tmpaddr;
119
118
  const char *tmparr[2];
120
 
  const char **names,**ethers;
121
 
  int i,j;
 
119
  const char **names, **ethers;
 
120
  int i, j;
122
121
  /* get the name of the ether entry */
123
 
  names=myldap_get_values(entry,attmap_ether_cn);
124
 
  if ((names==NULL)||(names[0]==NULL))
 
122
  names = myldap_get_values(entry, attmap_ether_cn);
 
123
  if ((names == NULL) || (names[0] == NULL))
125
124
  {
126
 
    log_log(LOG_WARNING,"%s: %s: missing",
127
 
                        myldap_get_dn(entry),attmap_ether_cn);
 
125
    log_log(LOG_WARNING, "%s: %s: missing",
 
126
            myldap_get_dn(entry), attmap_ether_cn);
128
127
    return 0;
129
128
  }
130
129
  /* get the addresses */
131
 
  if (reqether!=NULL)
 
130
  if (reqether != NULL)
132
131
  {
133
 
    ethers=tmparr;
134
 
    ethers[0]=reqether;
135
 
    ethers[1]=NULL;
 
132
    ethers = tmparr;
 
133
    ethers[0] = reqether;
 
134
    ethers[1] = NULL;
136
135
  }
137
136
  else
138
137
  {
139
 
    ethers=myldap_get_values(entry,attmap_ether_macAddress);
140
 
    if ((ethers==NULL)||(ethers[0]==NULL))
 
138
    ethers = myldap_get_values(entry, attmap_ether_macAddress);
 
139
    if ((ethers == NULL) || (ethers[0] == NULL))
141
140
    {
142
 
      log_log(LOG_WARNING,"%s: %s: missing",
143
 
                          myldap_get_dn(entry),attmap_ether_macAddress);
 
141
      log_log(LOG_WARNING, "%s: %s: missing",
 
142
              myldap_get_dn(entry), attmap_ether_macAddress);
144
143
      return 0;
145
144
    }
146
145
    /* TODO: move parsing of addresses up here */
147
146
  }
148
147
  /* write entries for all names and addresses */
149
 
  for (i=0;names[i]!=NULL;i++)
150
 
    if ((reqname==NULL)||(strcasecmp(reqname,names[i])==0))
151
 
      for (j=0;ethers[j]!=NULL;j++)
 
148
  for (i = 0; names[i] != NULL; i++)
 
149
    if ((reqname == NULL) || (strcasecmp(reqname, names[i]) == 0))
 
150
      for (j = 0; ethers[j] != NULL; j++)
152
151
      {
153
 
        WRITE_INT32(fp,NSLCD_RESULT_BEGIN);
154
 
        WRITE_STRING(fp,names[i]);
155
 
        WRITE_ETHER(fp,ethers[j]);
 
152
        WRITE_INT32(fp, NSLCD_RESULT_BEGIN);
 
153
        WRITE_STRING(fp, names[i]);
 
154
        WRITE_ETHER(fp, ethers[j]);
156
155
      }
157
156
  return 0;
158
157
}
159
158
 
160
159
NSLCD_HANDLE(
161
 
  ether,byname,
162
 
  char name[256];
163
 
  char filter[4096];
164
 
  READ_STRING(fp,name);
165
 
  log_setrequest("ether=\"%s\"",name);,
166
 
  NSLCD_ACTION_ETHER_BYNAME,
167
 
  mkfilter_ether_byname(name,filter,sizeof(filter)),
168
 
  write_ether(fp,entry,name,NULL)
 
160
  ether, byname, NSLCD_ACTION_ETHER_BYNAME,
 
161
  char name[BUFLEN_HOSTNAME];
 
162
  char filter[BUFLEN_FILTER];
 
163
  READ_STRING(fp, name);
 
164
  log_setrequest("ether=\"%s\"", name);,
 
165
  mkfilter_ether_byname(name, filter, sizeof(filter)),
 
166
  write_ether(fp, entry, name, NULL)
169
167
)
170
168
 
171
169
NSLCD_HANDLE(
172
 
  ether,byether,
 
170
  ether, byether, NSLCD_ACTION_ETHER_BYETHER,
173
171
  struct ether_addr addr;
174
172
  char addrstr[20];
175
 
  char filter[4096];
176
 
  READ_TYPE(fp,addr,uint8_t[6]);
177
 
  if (ether_ntoa_r(&addr,addrstr)==NULL)
 
173
  char filter[BUFLEN_FILTER];
 
174
  READ(fp, &addr, sizeof(uint8_t[6]));
 
175
  if (ether_ntoa_r(&addr, addrstr) == NULL)
178
176
    return -1;
179
 
  log_setrequest("ether=%s",addrstr);,
180
 
  NSLCD_ACTION_ETHER_BYETHER,
181
 
  mkfilter_ether_byether(addrstr,filter,sizeof(filter)),
182
 
  write_ether(fp,entry,NULL,addrstr)
 
177
  log_setrequest("ether=%s", addrstr);,
 
178
  mkfilter_ether_byether(addrstr, filter, sizeof(filter)),
 
179
  write_ether(fp, entry, NULL, addrstr)
183
180
)
184
181
 
185
182
NSLCD_HANDLE(
186
 
  ether,all,
 
183
  ether, all, NSLCD_ACTION_ETHER_ALL,
187
184
  const char *filter;
188
185
  log_setrequest("ether(all)");,
189
 
  NSLCD_ACTION_ETHER_ALL,
190
 
  (filter=ether_filter,0),
191
 
  write_ether(fp,entry,NULL,NULL)
 
186
  (filter = ether_filter, 0),
 
187
  write_ether(fp, entry, NULL, NULL)
192
188
)