~n-muench/ubuntu/precise/open-vm-tools/open-vm-tools-precise.sid-merge1

« back to all changes in this revision

Viewing changes to lib/SLPv2Parser/SLPv2Match.c

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2011-03-31 14:20:05 UTC
  • mfrom: (1.4.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110331142005-3n9red91p7ogkweo
Tags: 2011.03.28-387002-0ubuntu1
* Merge latest upstream git tag.  This has the unlocked_ioctl change
  needed to fix dkms build failures (LP: #727342)
* Changes in debian/rules:
  - work around a bug in toolbox/Makefile, where install-exec-hook is
    not happening.  This needs to get fixed the right way.
  - don't install 'vmware-user' which seems to no longer exist
  - move /etc/xdg into open-vm-toolbox (which should be done using .install)
* debian/open-vm-tools.init: add 'modprobe [-r] vmblock'. (LP: #332323)
* debian/rules and debian/open-vm-toolbox.lintian-overrides:
  - Make vmware-user-suid-wrapper suid-root (LP: #332323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*********************************************************
2
 
 * Copyright (C) 2005 VMware, Inc. All rights reserved.
3
 
 *
4
 
 * This program is free software; you can redistribute it and/or modify it
5
 
 * under the terms of the GNU Lesser General Public License as published
6
 
 * by the Free Software Foundation version 2.1 and no later version.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful, but
9
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10
 
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
11
 
 * License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU Lesser General Public License
14
 
 * along with this program; if not, write to the Free Software Foundation, Inc.,
15
 
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
16
 
 *
17
 
 *********************************************************/
18
 
 
19
 
#include <string.h>
20
 
#include <stdlib.h>
21
 
#ifdef WIN32
22
 
#include <Winsock2.h>
23
 
#else
24
 
#include <sys/types.h>
25
 
#include <netinet/in.h>
26
 
#endif
27
 
 
28
 
#include "vmware.h"
29
 
#include "util.h"
30
 
#include "str.h"
31
 
#include "SLPv2.h"
32
 
#include "SLPv2Private.h"
33
 
 
34
 
 
35
 
/*
36
 
 *-----------------------------------------------------------------------------
37
 
 *
38
 
 * SLPv2MsgParserMatchStringInList -
39
 
 *
40
 
 *      Returns TRUE if attribute is contained in list, where list
41
 
 *      is a comma separated list of attributes.
42
 
 *
43
 
 * Results:
44
 
 *      Returns TRUE upon match.
45
 
 *
46
 
 * Side effects:
47
 
 *      None
48
 
 *
49
 
 *-----------------------------------------------------------------------------
50
 
 */
51
 
 
52
 
Bool
53
 
SLPv2MsgParserMatchStringInList(char *list,      // IN
54
 
                                char *attribute) // IN
55
 
{
56
 
   char *start;
57
 
   char *end;
58
 
   size_t length;
59
 
 
60
 
   /*
61
 
    * If there is no attribute to match against, it's a match.
62
 
    */
63
 
   if (NULL == list || NULL == attribute || 0 == strlen(attribute)) {
64
 
      return TRUE;
65
 
   }
66
 
 
67
 
   /*
68
 
    * Look at every attribute in the list that is followed by a comma.
69
 
    */
70
 
   start = list;
71
 
   end   = Str_Strchr(start, ',');
72
 
   length = (NULL != end) ? (end - start) : strlen(start);
73
 
 
74
 
   while (end != NULL) {
75
 
      if (0 == Str_Strncasecmp(start, attribute, length)) {
76
 
         return TRUE;
77
 
      }
78
 
 
79
 
      start = end + 1;
80
 
      end   = Str_Strchr(start, ',');
81
 
      length = (NULL != end) ? (end - start) : strlen(start);
82
 
   }
83
 
 
84
 
   /*
85
 
    * At this point we're at the last item in list.
86
 
    */
87
 
   if (0 == Str_Strncasecmp(start, attribute, length)) {
88
 
     return TRUE;
89
 
   }
90
 
 
91
 
   return FALSE;
92
 
}
93
 
 
94
 
 
95
 
/*
96
 
 *-----------------------------------------------------------------------------
97
 
 *
98
 
 * SLPv2MsgParser_ServiceRequestMatch -
99
 
 *
100
 
 *      Returns TRUE if the packet matches the SLPv2 request parameters
101
 
 *      passed to this function.
102
 
 *
103
 
 * Results:
104
 
 *      Returns TRUE upon match.
105
 
 *
106
 
 * Side effects:
107
 
 *      None
108
 
 *
109
 
 *-----------------------------------------------------------------------------
110
 
 */
111
 
 
112
 
Bool
113
 
SLPv2MsgParser_ServiceRequestMatch(struct SLPv2_Parse *parse, // IN
114
 
                                   char *myIpsList,           // UN
115
 
                                   char *myServiceType,       // IN
116
 
                                   char *myScope,             // IN
117
 
                                   char *myPredicate,         // IN
118
 
                                   uint16 *xid)               // OUT
119
 
{
120
 
   ASSERT(NULL != parse);
121
 
 
122
 
   if (SLPV2_SERVICEREQUEST != parse->header->functionId) {
123
 
      return FALSE;
124
 
   }
125
 
 
126
 
   /*
127
 
    * TODO: ip address matching.
128
 
    */
129
 
 
130
 
   if (! SLPv2MsgParserMatchStringInList(parse->serviceRequest.serviceType,
131
 
                                                              myServiceType)) {
132
 
      return FALSE;
133
 
   }
134
 
 
135
 
   if (! SLPv2MsgParserMatchStringInList(parse->serviceRequest.scope,
136
 
                                                                    myScope)) {
137
 
      return FALSE;
138
 
   }
139
 
 
140
 
   // TODO: implement LDAPv3 predicate match
141
 
 
142
 
   if (NULL != xid) {
143
 
      *xid = Portable_ntohs(parse->header->xid);
144
 
   }
145
 
 
146
 
   return TRUE;
147
 
}
148
 
 
149
 
 
150
 
/*
151
 
 *-----------------------------------------------------------------------------
152
 
 *
153
 
 * SLPv2MsgParser_ServiceReplyMatch -
154
 
 *
155
 
 *      Returns TRUE if the packet matches the SLPv2 parameters
156
 
 *      passed to this function.
157
 
 *
158
 
 * Results:
159
 
 *      Returns TRUE upon match.
160
 
 *
161
 
 * Side effects:
162
 
 *      None
163
 
 *
164
 
 *-----------------------------------------------------------------------------
165
 
 */
166
 
 
167
 
Bool
168
 
SLPv2MsgParser_ServiceReplyMatch(struct SLPv2_Parse *parse, // IN
169
 
                                 int *urlCount,             // OUT
170
 
                                 char ***urlArray,          // OUT
171
 
                                 uint16 *xid)               // OUT
172
 
{
173
 
   ASSERT(NULL != parse);
174
 
 
175
 
   if (SLPV2_SERVICEREPLY != parse->header->functionId) {
176
 
      return FALSE;
177
 
   }
178
 
 
179
 
   if (NULL != urlCount) {
180
 
      *urlCount = parse->serviceReply.urlCount;
181
 
   }
182
 
 
183
 
   if (NULL != urlArray) {
184
 
      int i;
185
 
      *urlArray = Util_SafeMalloc(sizeof(char *)*parse->serviceReply.urlCount);
186
 
 
187
 
      for (i = 0; i < parse->serviceReply.urlCount; i++) {
188
 
         *urlArray[i] = Util_SafeStrdup(parse->serviceReply.url[i]);
189
 
      }
190
 
   }
191
 
 
192
 
   if (NULL != xid) {
193
 
      *xid = Portable_ntohs(parse->header->xid);
194
 
   }
195
 
 
196
 
   return TRUE;
197
 
}
198
 
 
199
 
 
200
 
/*
201
 
 *-----------------------------------------------------------------------------
202
 
 *
203
 
 * SLPv2MsgParser_AttributeRequestMatch -
204
 
 *
205
 
 *      Returns TRUE if the packet matches the SLPv2 request parameters
206
 
 *      passed to this function.
207
 
 *
208
 
 * Results:
209
 
 *      Returns TRUE upon match.
210
 
 *
211
 
 * Side effects:
212
 
 *      None
213
 
 *
214
 
 *-----------------------------------------------------------------------------
215
 
 */
216
 
 
217
 
Bool
218
 
SLPv2MsgParser_AttributeRequestMatch(struct SLPv2_Parse *parse, // IN
219
 
                                     char *myIpsList,           // UN
220
 
                                     char *url,                 // IN
221
 
                                     char *myScope,             // IN
222
 
                                     char *tagList,             // IN
223
 
                                     uint16 *xid)               // OUT
224
 
{
225
 
   ASSERT(NULL != parse);
226
 
 
227
 
   if (SLPV2_ATTRIBUTEREQUEST != parse->header->functionId) {
228
 
      return FALSE;
229
 
   }
230
 
 
231
 
   /*
232
 
    * TODO: ip address matching.
233
 
    */
234
 
 
235
 
   if ((url != NULL) && (0 != strcmp(url, parse->attributeRequest.url))) {
236
 
      return FALSE;
237
 
   }
238
 
 
239
 
   if (! SLPv2MsgParserMatchStringInList(parse->serviceRequest.scope,
240
 
                                                                    myScope)) {
241
 
      return FALSE;
242
 
   }
243
 
 
244
 
   /*
245
 
    * TODO: tag list and LDAPv3 predicate matching.
246
 
    */
247
 
 
248
 
   if (NULL != xid) {
249
 
      *xid = Portable_ntohs(parse->header->xid);
250
 
   }
251
 
 
252
 
   return TRUE;
253
 
}
254
 
 
255
 
 
256
 
 
257
 
/*
258
 
 *-----------------------------------------------------------------------------
259
 
 *
260
 
 * SLPv2MsgParser_AttributeReplyMatch -
261
 
 *
262
 
 *      Returns TRUE if the packet matches the SLPv2 parameters
263
 
 *      passed to this function.
264
 
 *
265
 
 * Results:
266
 
 *      Returns TRUE upon match.
267
 
 *
268
 
 * Side effects:
269
 
 *      None
270
 
 *
271
 
 *-----------------------------------------------------------------------------
272
 
 */
273
 
 
274
 
Bool
275
 
SLPv2MsgParser_AttributeReplyMatch(struct SLPv2_Parse *parse, // IN
276
 
                                   char **attributeList,      // OUT
277
 
                                   uint16 *xid)               // OUT
278
 
{
279
 
   ASSERT(NULL != parse);
280
 
 
281
 
   if (SLPV2_ATTRIBUTEREPLY != parse->header->functionId) {
282
 
      return FALSE;
283
 
   }
284
 
 
285
 
   if (attributeList != NULL) {
286
 
      *attributeList = Util_SafeStrdup(parse->attributeReply.attributeList);
287
 
   }
288
 
 
289
 
   if (NULL != xid) {
290
 
      *xid = Portable_ntohs(parse->header->xid);
291
 
   }
292
 
 
293
 
   return TRUE;
294
 
}
295
 
 
296