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

« back to all changes in this revision

Viewing changes to services/plugins/vix/vixToolsEnvVars.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) 2010 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
 * vixToolsEnvVars.c --
 
21
 *
 
22
 *      Routines that encapsulate the complexity of dealing with
 
23
 *      environment variables when the process may be impersonating
 
24
 *      a user.
 
25
 */
 
26
 
 
27
#include <stdlib.h>
 
28
#ifdef __APPLE__
 
29
#include <crt_externs.h>
 
30
#endif
 
31
 
 
32
#include "util.h"
 
33
#include "unicode.h"
 
34
#include "dynbuf.h"
 
35
#include "str.h"
 
36
#include "posix.h"
 
37
#include "vixToolsInt.h"
 
38
 
 
39
 
 
40
#ifndef _WIN32
 
41
extern char **environ;
 
42
#endif
 
43
 
 
44
struct VixToolsEnvIterator {
 
45
#ifdef _WIN32
 
46
   enum {
 
47
      VIX_TOOLS_ENV_TYPE_ENV_BLOCK = 1,
 
48
      VIX_TOOLS_ENV_TYPE_ENVIRON,
 
49
   } envType;
 
50
   union {
 
51
      /* Used when envType is VIX_TOOLS_ENV_TYPE_ENV_BLOCK. */
 
52
      struct {
 
53
         wchar_t *envBlock;     // Keep the original around to free.
 
54
         wchar_t *currEnvVar;
 
55
      } eb;
 
56
      /* Used when envType is VIX_TOOLS_ENV_TYPE_ENVIRON. */
 
57
      wchar_t **environ;
 
58
   } data;
 
59
#else
 
60
   char **environ;
 
61
#endif
 
62
};
 
63
 
 
64
 
 
65
struct VixToolsUserEnvironment {
 
66
#ifdef _WIN32
 
67
   Bool impersonated;
 
68
   wchar_t *envBlock;      // Only used when impersonated == TRUE.
 
69
#else
 
70
   // The POSIX versions don't need any state currently.
 
71
#endif
 
72
};
 
73
 
 
74
 
 
75
 
 
76
/*
 
77
 *-----------------------------------------------------------------------------
 
78
 *
 
79
 * VixToolsNewEnvIterator --
 
80
 *
 
81
 *      Create a new environment variable iterator for the user
 
82
 *      represented by 'userToken'.
 
83
 *      The resulting VixToolsEnvIterator must be freed using
 
84
 *      VixToolsDestroyEnvIterator.
 
85
 *
 
86
 * Results:
 
87
 *      VixError
 
88
 *
 
89
 * Side effects:
 
90
 *      None
 
91
 *
 
92
 *-----------------------------------------------------------------------------
 
93
 */
 
94
 
 
95
VixError
 
96
VixToolsNewEnvIterator(void *userToken,                  // IN
 
97
                       VixToolsEnvIterator **envItr)     // OUT
 
98
{
 
99
   VixError err = VIX_OK;
 
100
   VixToolsEnvIterator *it = Util_SafeMalloc(sizeof *it);
 
101
 
 
102
   if (NULL == envItr) {
 
103
      err = VIX_E_FAIL;
 
104
      goto abort;
 
105
   }
 
106
 
 
107
   *envItr = NULL;
 
108
 
 
109
#ifdef _WIN32
 
110
   if (PROCESS_CREATOR_USER_TOKEN != userToken) {
 
111
      /*
 
112
       * The process is impersonating a user, so retrieve the user's
 
113
       * environment block instead of using the process's environment.
 
114
       */
 
115
      it->envType = VIX_TOOLS_ENV_TYPE_ENV_BLOCK;
 
116
      err = VixToolsGetEnvBlock(userToken, &it->data.eb.envBlock);
 
117
      if (VIX_FAILED(err)) {
 
118
         goto abort;
 
119
      }
 
120
      it->data.eb.currEnvVar = it->data.eb.envBlock;
 
121
   } else {
 
122
      /*
 
123
       * The action is being performed as the user running the process
 
124
       * so the process's environment is fine.
 
125
       * TODO: Is this totally equivilent to the behavior when impersonated?
 
126
       * Would fetching the environment block include changes to the user's
 
127
       * or system's environment made after the process is running?
 
128
       */
 
129
      it->envType = VIX_TOOLS_ENV_TYPE_ENVIRON;
 
130
      it->data.environ = _wenviron;
 
131
   }
 
132
#elif defined(__APPLE__)
 
133
   it->environ = *_NSGetEnviron();
 
134
#elif defined(__FreeBSD__)
 
135
   /*
 
136
    * Looking at /build/toolchain/bsd32/freebsd-6.3/usr/include/stand.h,
 
137
    * environ is a pointer to a doubly linked list of structs. I guess they
 
138
    * just want to be different. Anyway, this is something that needs
 
139
    * work if we want to support FreeBSD.
 
140
    */
 
141
   err = VIX_E_NOT_SUPPORTED;
 
142
   goto abort;
 
143
#else
 
144
   it->environ = environ;
 
145
#endif
 
146
   *envItr = it;
 
147
abort:
 
148
   if (VIX_FAILED(err)) {
 
149
      free(it);
 
150
   }
 
151
 
 
152
   return err;
 
153
}
 
154
 
 
155
 
 
156
/*
 
157
 *-----------------------------------------------------------------------------
 
158
 *
 
159
 * VixToolsGetNextEnvVar --
 
160
 *
 
161
 *      Get the next envariable variable pair in the form NAME=VALUE.
 
162
 *
 
163
 * Results:
 
164
 *      A heap-allocated UTF-8 string, or NULL when the iterator has
 
165
 *      reached the end.
 
166
 *
 
167
 * Side effects:
 
168
 *      Advances the iterator.
 
169
 *
 
170
 *-----------------------------------------------------------------------------
 
171
 */
 
172
 
 
173
char *
 
174
VixToolsGetNextEnvVar(VixToolsEnvIterator *envItr)    // IN
 
175
{
 
176
   char *envVar;
 
177
 
 
178
   if (NULL == envItr) {
 
179
      return NULL;
 
180
   }
 
181
 
 
182
#ifdef _WIN32
 
183
   if (VIX_TOOLS_ENV_TYPE_ENV_BLOCK == envItr->envType) {
 
184
      if (L'\0' == envItr->data.eb.currEnvVar[0]) {
 
185
         envVar = NULL;
 
186
      } else {
 
187
         envVar = Unicode_AllocWithUTF16(envItr->data.eb.currEnvVar);
 
188
         while(*envItr->data.eb.currEnvVar++);
 
189
      }
 
190
   } else if (VIX_TOOLS_ENV_TYPE_ENVIRON == envItr->envType) {
 
191
      if (NULL == *envItr->data.environ) {
 
192
         envVar = NULL;
 
193
      } else {
 
194
         envVar = Unicode_AllocWithUTF16(*envItr->data.environ);
 
195
         envItr->data.environ++;
 
196
      }
 
197
   } else {
 
198
      /* Is someone using uninitialized memory? */
 
199
      NOT_IMPLEMENTED();
 
200
   }
 
201
#else
 
202
   if (NULL == *envItr->environ) {
 
203
      envVar = NULL;
 
204
   } else {
 
205
      envVar = Unicode_Alloc(*envItr->environ, STRING_ENCODING_DEFAULT);
 
206
      envItr->environ++;
 
207
   }
 
208
#endif
 
209
   return envVar;
 
210
}
 
211
 
 
212
 
 
213
/*
 
214
 *-----------------------------------------------------------------------------
 
215
 *
 
216
 * VixToolsDestroyEnvIterator --
 
217
 *
 
218
 *      Free()s any memory associated with the VixToolsEnvIterator.
 
219
 *
 
220
 * Results:
 
221
 *      None
 
222
 *
 
223
 * Side effects:
 
224
 *      None
 
225
 *
 
226
 *-----------------------------------------------------------------------------
 
227
 */
 
228
 
 
229
void
 
230
VixToolsDestroyEnvIterator(VixToolsEnvIterator *envItr)   // IN
 
231
{
 
232
   if (NULL != envItr) {
 
233
#ifdef _WIN32
 
234
      if (VIX_TOOLS_ENV_TYPE_ENV_BLOCK == envItr->envType) {
 
235
         if (NULL != envItr->data.eb.envBlock) {
 
236
            VixToolsDestroyEnvironmentBlock(envItr->data.eb.envBlock);
 
237
         }
 
238
      }
 
239
#endif
 
240
      free(envItr);
 
241
   }
 
242
}
 
243
 
 
244
 
 
245
/*
 
246
 *-----------------------------------------------------------------------------
 
247
 *
 
248
 * VixToolsNewUserEnvironment --
 
249
 *
 
250
 *      Create a new UserEnvironment that can be used to query for
 
251
 *      environment variables.
 
252
 *
 
253
 * Results:
 
254
 *      VixError
 
255
 *
 
256
 * Side effects:
 
257
 *      None
 
258
 *
 
259
 *-----------------------------------------------------------------------------
 
260
 */
 
261
 
 
262
VixError
 
263
VixToolsNewUserEnvironment(void *userToken,                   // IN
 
264
                           VixToolsUserEnvironment **env)     // OUT
 
265
{
 
266
   VixError err = VIX_OK;
 
267
   VixToolsUserEnvironment *myEnv = Util_SafeMalloc(sizeof *myEnv);
 
268
 
 
269
   if (NULL == env) {
 
270
      err = VIX_E_FAIL;
 
271
      goto abort;
 
272
   }
 
273
 
 
274
   *env = NULL;
 
275
 
 
276
#ifdef _WIN32
 
277
   if (PROCESS_CREATOR_USER_TOKEN != userToken) {
 
278
      myEnv->impersonated = TRUE;
 
279
      err = VixToolsGetEnvBlock(userToken, &myEnv->envBlock);
 
280
      if (VIX_FAILED(err)) {
 
281
         goto abort;
 
282
      }
 
283
   } else {
 
284
      myEnv->impersonated = FALSE;
 
285
      /* We will just read from the process's environment. */
 
286
   }
 
287
#endif
 
288
 
 
289
   *env = myEnv;
 
290
 
 
291
abort:
 
292
   if (VIX_FAILED(err)) {
 
293
      free(myEnv);
 
294
   }
 
295
 
 
296
   return err;
 
297
}
 
298
 
 
299
 
 
300
/*
 
301
 *-----------------------------------------------------------------------------
 
302
 *
 
303
 * VixToolsGetEnvFromUserEnvironment --
 
304
 *
 
305
 *      Looks up the environment variable given by 'name' in the provided
 
306
 *      user environment.
 
307
 *
 
308
 * Results:
 
309
 *      A heap-allocated UTF-8 string, or NULL if the environment variable
 
310
 *      is not found.
 
311
 *
 
312
 * Side effects:
 
313
 *      None
 
314
 *
 
315
 *-----------------------------------------------------------------------------
 
316
 */
 
317
 
 
318
char *
 
319
VixToolsGetEnvFromUserEnvironment(const VixToolsUserEnvironment *env,  // IN
 
320
                                  const char *name)                    // IN
 
321
{
 
322
   char *envVar;
 
323
 
 
324
   if (NULL == env) {
 
325
      return NULL;
 
326
   }
 
327
 
 
328
#ifdef _WIN32
 
329
   if (env->impersonated) {
 
330
      envVar = VixToolsGetEnvVarFromEnvBlock(env->envBlock, name);
 
331
   } else {
 
332
      envVar = Util_SafeStrdup(Posix_Getenv(name));
 
333
   }
 
334
#else
 
335
   envVar = Util_SafeStrdup(Posix_Getenv(name));
 
336
#endif
 
337
 
 
338
   return envVar;
 
339
}
 
340
 
 
341
 
 
342
/*
 
343
 *-----------------------------------------------------------------------------
 
344
 *
 
345
 * VixToolsDestroyUserEnvironment --
 
346
 *
 
347
 *      Releases any resources used by the VixToolsUserEnvironment.
 
348
 *      The VixToolsUserEnvironment must not be used after calling
 
349
 *      this function.
 
350
 *
 
351
 * Results:
 
352
 *      None
 
353
 *
 
354
 * Side effects:
 
355
 *      None
 
356
 *
 
357
 *-----------------------------------------------------------------------------
 
358
 */
 
359
 
 
360
void
 
361
VixToolsDestroyUserEnvironment(VixToolsUserEnvironment *env)   // IN
 
362
{
 
363
   if (NULL != env) {
 
364
#ifdef _WIN32
 
365
      if (NULL != env->envBlock) {
 
366
         if (env->impersonated) {
 
367
            VixToolsDestroyEnvironmentBlock(env->envBlock);
 
368
         }
 
369
      }
 
370
#endif
 
371
      free(env);
 
372
   }
 
373
}
 
374
 
 
375
 
 
376
#ifdef _WIN32
 
377
/*
 
378
 *-----------------------------------------------------------------------------
 
379
 *
 
380
 * VixToolsEnvironToEnvBlock --
 
381
 *
 
382
 *      Converts a NULL terminated array of UTF-8 environment variables in
 
383
 *      the form NAME=VALUE to an Win32 environment block, which is a single
 
384
 *      contiguous array containing UTF-16 environment variables in the same
 
385
 *      form, each separated by a UTF-16 null character, followed by two
 
386
 *      training null characters.
 
387
 *
 
388
 * Results:
 
389
 *      VixError
 
390
 *
 
391
 * Side effects:
 
392
 *      None
 
393
 *
 
394
 *-----------------------------------------------------------------------------
 
395
 */
 
396
 
 
397
VixError
 
398
VixToolsEnvironToEnvBlock(char const * const *environ,    // IN: UTF-8
 
399
                          wchar_t **envBlock)             // OUT
 
400
{
 
401
   VixError err;
 
402
   DynBuf buf;
 
403
   Bool res;
 
404
   static const wchar_t nullTerm[] = { L'\0', L'\0' };
 
405
 
 
406
   DynBuf_Init(&buf);
 
407
 
 
408
   if ((NULL == environ) || (NULL == envBlock)) {
 
409
      err = VIX_E_FAIL;
 
410
      goto abort;
 
411
   }
 
412
 
 
413
   *envBlock = NULL;
 
414
 
 
415
   while (NULL != *environ) {
 
416
      wchar_t *envVar = Unicode_GetAllocUTF16(*environ);
 
417
 
 
418
      res = DynBuf_Append(&buf, envVar,
 
419
                          (wcslen(envVar) + 1) * sizeof(*envVar));
 
420
      free(envVar);
 
421
      if (!res) {
 
422
         err = VIX_E_OUT_OF_MEMORY;
 
423
         goto abort;
 
424
      }
 
425
      environ++;
 
426
   }
 
427
 
 
428
   /*
 
429
    * Append two null characters at the end. This adds an extra (third) null
 
430
    * if there was at least one environment variable (since there already
 
431
    * is one after the last string) but we need both if there were no
 
432
    * environment variables in the input array. I'll waste two bytes to
 
433
    * keep the code a little simpler.
 
434
    */
 
435
   res = DynBuf_Append(&buf, nullTerm, sizeof nullTerm);
 
436
   if (!res) {
 
437
      err = VIX_E_OUT_OF_MEMORY;
 
438
      goto abort;
 
439
   }
 
440
 
 
441
   *envBlock = DynBuf_Detach(&buf);
 
442
   err = VIX_OK;
 
443
 
 
444
abort:
 
445
   DynBuf_Destroy(&buf);
 
446
 
 
447
   return err;
 
448
}
 
449
#endif
 
450
 
 
451
 
 
452
/*
 
453
 *-----------------------------------------------------------------------------
 
454
 *
 
455
 * VixToolsValidateEnviron --
 
456
 *
 
457
 *      Ensures that the NULL terminated array of strings contains
 
458
 *      properly formated environment variables.
 
459
 *
 
460
 * Results:
 
461
 *      VixError
 
462
 *
 
463
 * Side effects:
 
464
 *      None
 
465
 *
 
466
 *-----------------------------------------------------------------------------
 
467
 */
 
468
 
 
469
VixError
 
470
VixToolsValidateEnviron(char const * const *environ)   // IN
 
471
{
 
472
   if (NULL == environ) {
 
473
      return VIX_E_FAIL;
 
474
   }
 
475
 
 
476
   while (NULL != *environ) {
 
477
      /*
 
478
       * Each string should contain at least one '=', to delineate between
 
479
       * the name and the value.
 
480
       */
 
481
      if (NULL == Str_Strchr(*environ, '=')) {
 
482
         return VIX_E_INVALID_ARG;
 
483
      }
 
484
      environ++;
 
485
   }
 
486
 
 
487
   return VIX_OK;
 
488
}
 
489
 
 
490
 
 
491
#ifdef VMX86_DEVEL
 
492
#ifdef _WIN32
 
493
/*
 
494
 *-----------------------------------------------------------------------------
 
495
 *
 
496
 * TestVixToolsEnvironToEnvBlockEmptyEnviron --
 
497
 *
 
498
 *      Tests VixToolsEnvironToEnvBlock() with an empty environment: an
 
499
 *      char ** pointing to a single NULL pointer.
 
500
 *
 
501
 * Results:
 
502
 *      Passes or ASSERTs.
 
503
 *
 
504
 * Side effects:
 
505
 *      None
 
506
 *
 
507
 *-----------------------------------------------------------------------------
 
508
 */
 
509
 
 
510
static void
 
511
TestVixToolsEnvironToEnvBlockEmptyEnviron(void)
 
512
{
 
513
   const char *environ1[] = { NULL };
 
514
   wchar_t *envBlock;
 
515
   VixError err;
 
516
 
 
517
   err = VixToolsEnvironToEnvBlock(environ1, &envBlock);
 
518
   ASSERT(VIX_OK == err);
 
519
 
 
520
   ASSERT((L'\0' == envBlock[0]) && (L'\0' == envBlock[1]));
 
521
   free(envBlock);
 
522
}
 
523
 
 
524
 
 
525
/*
 
526
 *-----------------------------------------------------------------------------
 
527
 *
 
528
 * TestVixToolsEnvironToEnvBlockTwoGood --
 
529
 *
 
530
 *      Tests VixToolsEnvironToEnvBlock() with an environment containing
 
531
 *      two valid entries.
 
532
 *
 
533
 * Results:
 
534
 *      Passes or ASSERTs
 
535
 *
 
536
 * Side effects:
 
537
 *      None
 
538
 *
 
539
 *-----------------------------------------------------------------------------
 
540
 */
 
541
 
 
542
static void
 
543
TestVixToolsEnvironToEnvBlockTwoGood(void)
 
544
{
 
545
   const char *environ1[] = { "foo=bar", "env=block", NULL };
 
546
   wchar_t *envBlock, *currPos;
 
547
   VixError err;
 
548
 
 
549
   err = VixToolsEnvironToEnvBlock(environ1, &envBlock);
 
550
   ASSERT(VIX_OK == err);
 
551
 
 
552
   currPos = envBlock;
 
553
   ASSERT(wcscmp(currPos, L"foo=bar") == 0);
 
554
   currPos += wcslen(L"foo=bar") + 1;
 
555
   ASSERT(wcscmp(currPos, L"env=block") == 0);
 
556
   free(envBlock);
 
557
}
 
558
 
 
559
 
 
560
/*
 
561
 *-----------------------------------------------------------------------------
 
562
 *
 
563
 * TestVixToolsEnvironToEnvBlock --
 
564
 *
 
565
 *      Runs unit tests for VixToolsEnvironToEnvBlock().
 
566
 *
 
567
 * Results:
 
568
 *      Passes or ASSERTs.
 
569
 *
 
570
 * Side effects:
 
571
 *      None
 
572
 *
 
573
 *-----------------------------------------------------------------------------
 
574
 */
 
575
 
 
576
static void
 
577
TestVixToolsEnvironToEnvBlock(void)
 
578
{
 
579
   TestVixToolsEnvironToEnvBlockEmptyEnviron();
 
580
   TestVixToolsEnvironToEnvBlockTwoGood();
 
581
}
 
582
#endif // #ifdef _WIN32
 
583
 
 
584
 
 
585
/*
 
586
 *-----------------------------------------------------------------------------
 
587
 *
 
588
 * TestVixToolsValidateEnvironEmptyEnviron --
 
589
 *
 
590
 *      Tests VixToolsEnvironToEnvBlock() with an empty environment.
 
591
 *
 
592
 * Results:
 
593
 *      Passes or ASSERTs.
 
594
 *
 
595
 * Side effects:
 
596
 *      None
 
597
 *
 
598
 *-----------------------------------------------------------------------------
 
599
 */
 
600
 
 
601
static void
 
602
TestVixToolsValidateEnvironEmptyEnviron(void)
 
603
{
 
604
   const char *environ1[] = { NULL };
 
605
   VixError err;
 
606
 
 
607
   err = VixToolsValidateEnviron(environ1);
 
608
   ASSERT(VIX_OK == err);
 
609
}
 
610
 
 
611
 
 
612
/*
 
613
 *-----------------------------------------------------------------------------
 
614
 *
 
615
 * TestVixToolsValidateEnvironTwoGoodVars --
 
616
 *
 
617
 *      Tests VixToolsEnvironToEnvBlock() with an environment containing
 
618
 *      two valid environment variables.
 
619
 *
 
620
 * Results:
 
621
 *      Passes or ASSERTs.
 
622
 *
 
623
 * Side effects:
 
624
 *      None
 
625
 *
 
626
 *-----------------------------------------------------------------------------
 
627
 */
 
628
 
 
629
static void
 
630
TestVixToolsValidateEnvironTwoGoodVars(void)
 
631
{
 
632
   const char *environ1[] = { "foo=bar", "vix=api", NULL };
 
633
   VixError err;
 
634
 
 
635
   err = VixToolsValidateEnviron(environ1);
 
636
   ASSERT(VIX_OK == err);
 
637
}
 
638
 
 
639
 
 
640
/*
 
641
 *-----------------------------------------------------------------------------
 
642
 *
 
643
 * TestVixToolsValidateEnvironOneBad --
 
644
 *
 
645
 *      Tests VixToolsEnvironToEnvBlock() with an environment containing
 
646
 *      one invalid environment variable.
 
647
 *
 
648
 * Results:
 
649
 *      Passes or ASSERTs.
 
650
 *
 
651
 * Side effects:
 
652
 *      None
 
653
 *
 
654
 *-----------------------------------------------------------------------------
 
655
 */
 
656
 
 
657
static void
 
658
TestVixToolsValidateEnvironOneBad(void)
 
659
{
 
660
   const char *environ1[] = { "noequals", NULL };
 
661
   VixError err;
 
662
 
 
663
   err = VixToolsValidateEnviron(environ1);
 
664
   ASSERT(VIX_E_INVALID_ARG == err);
 
665
}
 
666
 
 
667
 
 
668
/*
 
669
 *-----------------------------------------------------------------------------
 
670
 *
 
671
 * TestVixToolsValidateEnvironSecondBad --
 
672
 *
 
673
 *      Tests VixToolsEnvironToEnvBlock() with an environment containing
 
674
 *      one valid environment variable followed by one invalid environment
 
675
 *      variable.
 
676
 *
 
677
 * Results:
 
678
 *      Passes or ASSERTs.
 
679
 *
 
680
 * Side effects:
 
681
 *      None
 
682
 *
 
683
 *-----------------------------------------------------------------------------
 
684
 */
 
685
 
 
686
static void
 
687
TestVixToolsValidateEnvironSecondBad(void)
 
688
{
 
689
   const char *environ1[] = { "foo=bar", "noequals", NULL };
 
690
   VixError err;
 
691
 
 
692
   err = VixToolsValidateEnviron(environ1);
 
693
   ASSERT(VIX_E_INVALID_ARG == err);
 
694
}
 
695
 
 
696
 
 
697
/*
 
698
 *-----------------------------------------------------------------------------
 
699
 *
 
700
 * TestVixToolsValidateEnviron --
 
701
 *
 
702
 *      Run unit tests for VixToolsValidateEnviron().
 
703
 *
 
704
 * Results:
 
705
 *      Passes or ASSERTs.
 
706
 *
 
707
 * Side effects:
 
708
 *      None
 
709
 *
 
710
 *-----------------------------------------------------------------------------
 
711
 */
 
712
 
 
713
static void
 
714
TestVixToolsValidateEnviron(void)
 
715
{
 
716
   TestVixToolsValidateEnvironEmptyEnviron();
 
717
   TestVixToolsValidateEnvironTwoGoodVars();
 
718
   TestVixToolsValidateEnvironOneBad();
 
719
   TestVixToolsValidateEnvironSecondBad();
 
720
}
 
721
 
 
722
 
 
723
/*
 
724
 *-----------------------------------------------------------------------------
 
725
 *
 
726
 * TextVixToolsEnvVars --
 
727
 *
 
728
 *      Run unit tests for functions in this file.
 
729
 *
 
730
 * Results:
 
731
 *      Passes or ASSERTs.
 
732
 *
 
733
 * Side effects:
 
734
 *      None
 
735
 *
 
736
 *-----------------------------------------------------------------------------
 
737
 */
 
738
 
 
739
void
 
740
TestVixToolsEnvVars(void)
 
741
{
 
742
#ifdef _WIN32
 
743
   TestVixToolsEnvironToEnvBlock();
 
744
#endif
 
745
   TestVixToolsValidateEnviron();
 
746
}
 
747
#endif // #ifdef VMX86_DEVEL