~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201210021442

« back to all changes in this revision

Viewing changes to services/plugins/guestInfo/getlib/compareNicInfo.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) 2009 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
/**
 
20
 * @file compareNicInfo.c
 
21
 *
 
22
 * Comparison routines for NicInfo types.  Handy for caching, unit testing.
 
23
 *
 
24
 * @todo Each byte of a MAC address is assumed to be represented by two
 
25
 * characters.  So, as far as these routines are concerned, 0:1:2:3:4:5
 
26
 * != 00:01:02:03:04:05.  Is this a problem?
 
27
 */
 
28
 
 
29
#include <string.h>
 
30
 
 
31
#include "vmware.h"
 
32
#include "xdrutil.h"
 
33
 
 
34
#include "guestInfoLib.h"
 
35
 
 
36
 
 
37
/**
 
38
 * Common comparison prefix routine.
 
39
 */
 
40
#define RETURN_EARLY_CMP_PTRS(a, b)  do {                               \
 
41
   if (!(a) && !(b)) {                                                  \
 
42
      return TRUE;                                                      \
 
43
   } else if ((!(a) && (b)) || ((a) && !(b))) {                         \
 
44
      return FALSE;                                                     \
 
45
   }                                                                    \
 
46
} while (0)
 
47
 
 
48
 
 
49
/*
 
50
 ******************************************************************************
 
51
 * GuestInfo_IsEqual_DhcpConfigInfo --                                   */ /**
 
52
 *
 
53
 * Compares a pair of DhcpConfigInfos.
 
54
 *
 
55
 * @param[in] a DhcpConfigInfo number 1.  May be NULL.
 
56
 * @param[in] b DhcpConfigInfo number 2.  May be NULL.
 
57
 *
 
58
 * @retval TRUE  DhcpConfigInfos are equivalent.
 
59
 * @retval FALSE DhcpConfigInfos differ.
 
60
 *
 
61
 ******************************************************************************
 
62
 */
 
63
 
 
64
Bool
 
65
GuestInfo_IsEqual_DhcpConfigInfo(const DhcpConfigInfo *a,
 
66
                                 const DhcpConfigInfo *b)
 
67
{
 
68
   RETURN_EARLY_CMP_PTRS(a, b);
 
69
 
 
70
   return a->enabled == b->enabled &&
 
71
          strcmp(a->dhcpSettings, b->dhcpSettings) == 0;
 
72
}
 
73
 
 
74
 
 
75
/*
 
76
 ******************************************************************************
 
77
 * GuestInfo_IsEqual_DnsConfigInfo --                                    */ /**
 
78
 *
 
79
 * Compares a pair of DnsConfigInfos.
 
80
 *
 
81
 * @param[in] a DnsConfigInfo number 1.  May be NULL.
 
82
 * @param[in] b DnsConfigInfo number 2.  May be NULL.
 
83
 *
 
84
 * @retval TRUE  DnsConfigInfos are equivalent.
 
85
 * @retval FALSE DnsConfigInfos differ.
 
86
 *
 
87
 ******************************************************************************
 
88
 */
 
89
 
 
90
Bool
 
91
GuestInfo_IsEqual_DnsConfigInfo(const DnsConfigInfo *a,
 
92
                                const DnsConfigInfo *b)
 
93
{
 
94
   u_int ai;
 
95
   u_int bi;
 
96
 
 
97
   RETURN_EARLY_CMP_PTRS(a, b);
 
98
 
 
99
   if (!GuestInfo_IsEqual_DnsHostname(a->hostName, b->hostName) ||
 
100
       !GuestInfo_IsEqual_DnsHostname(a->domainName, b->domainName) ||
 
101
       a->serverList.serverList_len != b->serverList.serverList_len ||
 
102
       a->searchSuffixes.searchSuffixes_len != b->searchSuffixes.searchSuffixes_len) {
 
103
      return FALSE;
 
104
   }
 
105
 
 
106
   /*
 
107
    * Since the lists' lengths match, search in b for each item in a.  We'll
 
108
    * assume that we don't have any duplicates in a s.t. unique(a) is a proper
 
109
    * subset of b.
 
110
    *
 
111
    * Bail if we can't find an entry.
 
112
    */
 
113
 
 
114
   XDRUTIL_FOREACH(ai, a, serverList) {
 
115
      TypedIpAddress *aServer = XDRUTIL_GETITEM(a, serverList, ai);
 
116
 
 
117
      XDRUTIL_FOREACH(bi, b, serverList) {
 
118
         TypedIpAddress *bServer = XDRUTIL_GETITEM(b, serverList, bi);
 
119
 
 
120
         if (GuestInfo_IsEqual_TypedIpAddress(aServer, bServer)) {
 
121
            break;
 
122
         }
 
123
      }
 
124
 
 
125
      if (bi == b->serverList.serverList_len) {
 
126
         /* Exhausted b's list, didn't find aServer. */
 
127
         return FALSE;
 
128
      }
 
129
   }
 
130
 
 
131
   XDRUTIL_FOREACH(ai, a, searchSuffixes) {
 
132
      DnsHostname *aSuffix = XDRUTIL_GETITEM(a, searchSuffixes, ai);
 
133
 
 
134
      XDRUTIL_FOREACH(bi, b, searchSuffixes) {
 
135
         DnsHostname *bSuffix = XDRUTIL_GETITEM(b, searchSuffixes, bi);
 
136
 
 
137
         if (GuestInfo_IsEqual_DnsHostname(aSuffix, bSuffix)) {
 
138
            break;
 
139
         }
 
140
      }
 
141
 
 
142
      if (bi == b->searchSuffixes.searchSuffixes_len) {
 
143
         /* Exhausted b's list, didn't find aSuffix. */
 
144
         return FALSE;
 
145
      }
 
146
   }
 
147
 
 
148
   return TRUE;
 
149
}
 
150
 
 
151
 
 
152
/*
 
153
 ******************************************************************************
 
154
 * GuestInfo_IsEqual_DnsHostname --                                      */ /**
 
155
 *
 
156
 * Compares a pair of DnsHostnames.
 
157
 *
 
158
 * @param[in] a DnsHostname number 1.  May be NULL.
 
159
 * @param[in] b DnsHostname number 2.  May be NULL.
 
160
 *
 
161
 * @retval TRUE  DnsHostnames are equivalent.
 
162
 * @retval FALSE DnsHostnames differ.
 
163
 *
 
164
 ******************************************************************************
 
165
 */
 
166
 
 
167
Bool
 
168
GuestInfo_IsEqual_DnsHostname(const DnsHostname *a,
 
169
                              const DnsHostname *b)
 
170
{
 
171
   RETURN_EARLY_CMP_PTRS(a, b);
 
172
   return strcasecmp(*a, *b) == 0 ? TRUE : FALSE;
 
173
}
 
174
 
 
175
 
 
176
/*
 
177
 ******************************************************************************
 
178
 * GuestInfo_IsEqual_GuestNicV3 --                                       */ /**
 
179
 *
 
180
 * Compares two GuestNicV3s.
 
181
 *
 
182
 * @param[in] a GuestNicV3 number 1.  May be NULL.
 
183
 * @param[in] b GuestNicV3 number 2.  May be NULL.
 
184
 *
 
185
 * @retval TRUE  GuestNicV3s are equivalent.
 
186
 * @retval FALSE GuestNicV3s differ.
 
187
 *
 
188
 ******************************************************************************
 
189
 */
 
190
 
 
191
Bool
 
192
GuestInfo_IsEqual_GuestNicV3(const GuestNicV3 *a,
 
193
                             const GuestNicV3 *b)
 
194
{
 
195
   u_int ai;
 
196
   u_int bi;
 
197
 
 
198
   RETURN_EARLY_CMP_PTRS(a, b);
 
199
 
 
200
   /* Not optional fields. */
 
201
   ASSERT(a->macAddress);
 
202
   ASSERT(b->macAddress);
 
203
 
 
204
   if (strcasecmp(a->macAddress, b->macAddress) != 0) {
 
205
      return FALSE;
 
206
   }
 
207
 
 
208
   /*
 
209
    * Compare the IP lists.
 
210
    */
 
211
 
 
212
   if (a->ips.ips_len != b->ips.ips_len) {
 
213
      return FALSE;
 
214
   }
 
215
 
 
216
   XDRUTIL_FOREACH(ai, a, ips) {
 
217
      IpAddressEntry *aEntry = XDRUTIL_GETITEM(a, ips, ai);
 
218
 
 
219
      XDRUTIL_FOREACH(bi, b, ips) {
 
220
         IpAddressEntry *bEntry = XDRUTIL_GETITEM(b, ips, bi);
 
221
 
 
222
         if (GuestInfo_IsEqual_IpAddressEntry(aEntry, bEntry)) {
 
223
            break;
 
224
         }
 
225
      }
 
226
 
 
227
      if (bi == b->ips.ips_len) {
 
228
         /* Exhausted b's list, didn't find aEntry. */
 
229
         return FALSE;
 
230
      }
 
231
   }
 
232
 
 
233
   return
 
234
      GuestInfo_IsEqual_DnsConfigInfo(a->dnsConfigInfo, b->dnsConfigInfo) &&
 
235
      GuestInfo_IsEqual_WinsConfigInfo(a->winsConfigInfo, b->winsConfigInfo) &&
 
236
      GuestInfo_IsEqual_DhcpConfigInfo(a->dhcpConfigInfov4, b->dhcpConfigInfov4) &&
 
237
      GuestInfo_IsEqual_DhcpConfigInfo(a->dhcpConfigInfov6, b->dhcpConfigInfov6);
 
238
}
 
239
 
 
240
 
 
241
/*
 
242
 ******************************************************************************
 
243
 * GuestInfo_IsEqual_InetCidrRouteEntry --                               */ /**
 
244
 *
 
245
 * Compares two InetCidrRouteEntrys.
 
246
 *
 
247
 * @param[in] a     InetCidrRouteEntry number 1.  May be NULL.
 
248
 * @param[in] b     InetCidrRouteEntry number 2.  May be NULL.
 
249
 * @param[in] aInfo a's NicInfo container.  If a != NULL, may NOT be NULL.
 
250
 * @param[in] bInfo b's NicInfo container.  If b != NULL, may NOT be NULL.
 
251
 *
 
252
 * @retval TRUE  InetCidrRouteEntrys are equivalent.
 
253
 * @retval FALSE InetCidrRouteEntrys differ.
 
254
 *
 
255
 ******************************************************************************
 
256
 */
 
257
 
 
258
Bool
 
259
GuestInfo_IsEqual_InetCidrRouteEntry(const InetCidrRouteEntry *a,
 
260
                                     const InetCidrRouteEntry *b,
 
261
                                     const NicInfoV3 *aInfo,
 
262
                                     const NicInfoV3 *bInfo)
 
263
{
 
264
   RETURN_EARLY_CMP_PTRS(a, b);
 
265
 
 
266
   ASSERT(aInfo);
 
267
   ASSERT(bInfo);
 
268
 
 
269
   return
 
270
      GuestInfo_IsEqual_TypedIpAddress(&a->inetCidrRouteDest,
 
271
                                       &b->inetCidrRouteDest) &&
 
272
      a->inetCidrRoutePfxLen == b->inetCidrRoutePfxLen &&
 
273
      GuestInfo_IsEqual_TypedIpAddress(a->inetCidrRouteNextHop,
 
274
                                       b->inetCidrRouteNextHop) &&
 
275
      strcasecmp(aInfo->nics.nics_val[a->inetCidrRouteIfIndex].macAddress,
 
276
                 bInfo->nics.nics_val[b->inetCidrRouteIfIndex].macAddress) == 0 &&
 
277
      a->inetCidrRouteType == b->inetCidrRouteType &&
 
278
      a->inetCidrRouteMetric == b->inetCidrRouteMetric;
 
279
}
 
280
 
 
281
 
 
282
/*
 
283
 ******************************************************************************
 
284
 * GuestInfo_IsEqual_IpAddressEntry --                                   */ /**
 
285
 *
 
286
 * Compares two IpAddressEntrys.
 
287
 *
 
288
 * @param[in] a IpAddressEntry number 1.  May be NULL.
 
289
 * @param[in] b IpAddressEntry number 2.  May be NULL.
 
290
 *
 
291
 * @retval TRUE  IpAddressEntrys are equivalent.
 
292
 * @retval FALSE IpAddressEntrys differ.
 
293
 *
 
294
 ******************************************************************************
 
295
 */
 
296
 
 
297
Bool
 
298
GuestInfo_IsEqual_IpAddressEntry(const IpAddressEntry *a,
 
299
                                 const IpAddressEntry *b)
 
300
{
 
301
   RETURN_EARLY_CMP_PTRS(a, b);
 
302
 
 
303
   return
 
304
      GuestInfo_IsEqual_TypedIpAddress(&a->ipAddressAddr, &b->ipAddressAddr) &&
 
305
      a->ipAddressPrefixLength == b->ipAddressPrefixLength &&
 
306
      ((a->ipAddressOrigin == NULL && b->ipAddressOrigin == NULL) ||
 
307
       (a->ipAddressOrigin != NULL && b->ipAddressOrigin != NULL &&
 
308
        *a->ipAddressOrigin == *b->ipAddressOrigin)) &&
 
309
      ((a->ipAddressStatus == NULL && b->ipAddressStatus == NULL) ||
 
310
       (a->ipAddressStatus != NULL && b->ipAddressStatus != NULL &&
 
311
        *a->ipAddressStatus == *b->ipAddressStatus));
 
312
}
 
313
 
 
314
 
 
315
/*
 
316
 ******************************************************************************
 
317
 * GuestInfo_IsEqual_NicInfoV3 --                                        */ /**
 
318
 *
 
319
 * Compares two NicInfoV3s.
 
320
 *
 
321
 * @param[in] a NicInfoV3 number 1.  May be NULL.
 
322
 * @param[in] b NicInfoV3 number 2.  May be NULL.
 
323
 *
 
324
 * @retval TRUE  NicInfoV3s are equivalent.
 
325
 * @retval FALSE NicInfoV3s differ.
 
326
 *
 
327
 ******************************************************************************
 
328
 */
 
329
 
 
330
Bool
 
331
GuestInfo_IsEqual_NicInfoV3(const NicInfoV3 *a,
 
332
                            const NicInfoV3 *b)
 
333
{
 
334
   u_int ai;
 
335
   u_int bi;
 
336
 
 
337
   RETURN_EARLY_CMP_PTRS(a, b);
 
338
 
 
339
   /*
 
340
    * Compare the NIC lists.
 
341
    */
 
342
 
 
343
   if (a->nics.nics_len != b->nics.nics_len) {
 
344
      return FALSE;
 
345
   }
 
346
 
 
347
   XDRUTIL_FOREACH(ai, a, nics) {
 
348
      GuestNicV3 *eachNic = XDRUTIL_GETITEM(a, nics, ai);
 
349
      GuestNicV3 *cmpNic = GuestInfo_Util_FindNicByMac(b, eachNic->macAddress);
 
350
 
 
351
      if (cmpNic == NULL ||
 
352
          !GuestInfo_IsEqual_GuestNicV3(eachNic, cmpNic)) {
 
353
         return FALSE;
 
354
      }
 
355
   }
 
356
 
 
357
   /*
 
358
    * Compare routes.
 
359
    */
 
360
 
 
361
   if (a->routes.routes_len != b->routes.routes_len) {
 
362
      return FALSE;
 
363
   }
 
364
 
 
365
   XDRUTIL_FOREACH(ai, a, routes) {
 
366
      InetCidrRouteEntry *aRoute = XDRUTIL_GETITEM(a, routes, ai);
 
367
 
 
368
      XDRUTIL_FOREACH(bi, b, routes) {
 
369
         InetCidrRouteEntry *bRoute = XDRUTIL_GETITEM(b, routes, bi);
 
370
 
 
371
         if (GuestInfo_IsEqual_InetCidrRouteEntry(aRoute, bRoute, a, b)) {
 
372
            break;
 
373
         }
 
374
      }
 
375
 
 
376
      if (bi == b->routes.routes_len) {
 
377
         /* Exhausted b's list, didn't find aRoute. */
 
378
         return FALSE;
 
379
      }
 
380
   }
 
381
 
 
382
   /*
 
383
    * Compare the stack settings:
 
384
    *    . DnsConfigInfo
 
385
    *    . WinsConfigInfo
 
386
    *    . DhcpConfigInfov4
 
387
    *    . DhcpConfigInfov6
 
388
    */
 
389
 
 
390
   return
 
391
      GuestInfo_IsEqual_DnsConfigInfo(a->dnsConfigInfo, b->dnsConfigInfo) &&
 
392
      GuestInfo_IsEqual_WinsConfigInfo(a->winsConfigInfo, b->winsConfigInfo) &&
 
393
      GuestInfo_IsEqual_DhcpConfigInfo(a->dhcpConfigInfov4, b->dhcpConfigInfov4) &&
 
394
      GuestInfo_IsEqual_DhcpConfigInfo(a->dhcpConfigInfov6, b->dhcpConfigInfov6);
 
395
}
 
396
 
 
397
 
 
398
/*
 
399
 ******************************************************************************
 
400
 * GuestInfo_IsEqual_TypedIpAddress --                                   */ /**
 
401
 *
 
402
 * Compares two TypedIpAddresses.
 
403
 *
 
404
 * @param[in] a TypedIpAddress number 1.  May be NULL.
 
405
 * @param[in] b TypedIpAddress number 2.  May be NULL.
 
406
 *
 
407
 * @retval TRUE  TypedIpAddresses are equivalent.
 
408
 * @retval FALSE TypedIpAddresses differ.
 
409
 *
 
410
 ******************************************************************************
 
411
 */
 
412
 
 
413
Bool
 
414
GuestInfo_IsEqual_TypedIpAddress(const TypedIpAddress *a,
 
415
                                 const TypedIpAddress *b)
 
416
{
 
417
   RETURN_EARLY_CMP_PTRS(a, b);
 
418
 
 
419
   if (a->ipAddressAddrType != b->ipAddressAddrType ||
 
420
       memcmp(a->ipAddressAddr.InetAddress_val,
 
421
              b->ipAddressAddr.InetAddress_val,
 
422
              a->ipAddressAddr.InetAddress_len)) {
 
423
      return FALSE;
 
424
   }
 
425
 
 
426
   return TRUE;
 
427
}
 
428
 
 
429
 
 
430
/*
 
431
 ******************************************************************************
 
432
 * GuestInfo_IsEqual_WinsConfigInfo --                                   */ /**
 
433
 *
 
434
 * Compares a pair of WinsConfigInfos.
 
435
 *
 
436
 * @param[in] a WinsConfigInfo number 1.  May be NULL.
 
437
 * @param[in] b WinsConfigInfo number 2.  May be NULL.
 
438
 *
 
439
 * @retval TRUE  WinsConfigInfos are equivalent.
 
440
 * @retval FALSE WinsConfigInfos differ.
 
441
 *
 
442
 ******************************************************************************
 
443
 */
 
444
 
 
445
Bool
 
446
GuestInfo_IsEqual_WinsConfigInfo(const WinsConfigInfo *a,
 
447
                                 const WinsConfigInfo *b)
 
448
{
 
449
   RETURN_EARLY_CMP_PTRS(a, b);
 
450
 
 
451
   return GuestInfo_IsEqual_TypedIpAddress(&a->primary, &b->primary) &&
 
452
          GuestInfo_IsEqual_TypedIpAddress(&a->secondary, &b->secondary);
 
453
}