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

« back to all changes in this revision

Viewing changes to vmware-user-suid-wrapper/locationsdb.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) 2007 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
 
/*
21
 
 * locationsdb.c --
22
 
 *
23
 
 *    Provides the QueryLocationsDB routine for finding keys in the locations
24
 
 *    database.  Because our application is a setuid binary and we want to
25
 
 *    minimize risk, we retain the duplicated functionality here rather than
26
 
 *    link against lib/unixinstall.
27
 
 */
28
 
 
29
 
#if !defined(sun) && !defined(__FreeBSD__) && !defined(linux)
30
 
# error This program is not supported on your platform.
31
 
#endif
32
 
 
33
 
#include <sys/param.h>
34
 
 
35
 
#include <fcntl.h>
36
 
#include <string.h>
37
 
#include <strings.h>
38
 
 
39
 
#include "vm_basic_types.h"
40
 
#include "wrapper.h"
41
 
 
42
 
 
43
 
 
44
 
/*
45
 
 * Local data
46
 
 */
47
 
 
48
 
/*
49
 
 * Mappings between queries and search strings
50
 
 */
51
 
 
52
 
typedef struct Mapping {
53
 
   const char *answer;          /* string to match for "answer FOO" */
54
 
   const char *remove;          /* string to match for "remove_answer FOO" */
55
 
   size_t answerSize;           /* size of answer buffer */
56
 
   size_t removeSize;           /* size of remove buffer */
57
 
} Mapping;
58
 
 
59
 
/*
60
 
 * queryMappings between Selector => search strings.  Used by QueryLocationsDB.
61
 
 */
62
 
 
63
 
#define ANSWER_LIBDIR   "answer LIBDIR"
64
 
#define REMOVE_LIBDIR   "remove_answer LIBDIR"
65
 
#define ANSWER_BINDIR   "answer BINDIR"
66
 
#define REMOVE_BINDIR   "remove_answer BINDIR"
67
 
 
68
 
static Mapping queryMappings[] = {
69
 
   { ANSWER_LIBDIR, REMOVE_LIBDIR, sizeof ANSWER_LIBDIR, sizeof REMOVE_LIBDIR },
70
 
   { ANSWER_BINDIR, REMOVE_BINDIR, sizeof ANSWER_BINDIR, sizeof REMOVE_BINDIR },
71
 
   { 0, 0, 0, 0 }
72
 
};
73
 
 
74
 
 
75
 
/*
76
 
 * Global functions (definitions)
77
 
 */
78
 
 
79
 
 
80
 
/*
81
 
 *----------------------------------------------------------------------------
82
 
 *
83
 
 * QueryLocationsDB --
84
 
 *
85
 
 *    Based on the caller's Selector, determines the directory selected as
86
 
 *    "LIBDIR", "BINDIR", etc. when the Tools were last configured.
87
 
 *
88
 
 * Results:
89
 
 *    TRUE on success, FALSE on failure.  queryDir is filled in on success.
90
 
 *
91
 
 * Side effects:
92
 
 *    None.
93
 
 *
94
 
 *----------------------------------------------------------------------------
95
 
 */
96
 
 
97
 
Bool
98
 
QueryLocationsDB(const char *locations, // IN : path of locations database
99
 
                 Selector selector,     // IN : DB query to search for
100
 
                 char *queryDir,        // OUT: address to write dirname to
101
 
                 size_t queryDirSize)   // IN : size of queryDir buffer
102
 
{
103
 
   FILE *file = NULL;
104
 
   char buf[MAXPATHLEN];
105
 
   Bool found = FALSE;
106
 
   Mapping *map;
107
 
 
108
 
   if (selector < 0 || selector >= QUERY_MAX) {
109
 
      Error("Internal logic error.  This is a bug.");
110
 
      return FALSE;
111
 
   }
112
 
 
113
 
   file = fopen(locations, "r");
114
 
   if (!file) {
115
 
      return FALSE;
116
 
   }
117
 
 
118
 
   map = &queryMappings[selector];
119
 
 
120
 
   /*
121
 
    * We need to inspect the entire locations database since there are both
122
 
    * "answer"s and "remove_answer"s.  We want to provide the last answer that
123
 
    * has not been removed.
124
 
    */
125
 
   while (fgets(buf, sizeof buf, file)) {
126
 
      if (strncmp(buf, map->answer, map->answerSize - 1) == 0) {
127
 
         char *newline;
128
 
 
129
 
         strncpy(queryDir, buf + map->answerSize, queryDirSize);
130
 
         if (queryDir[queryDirSize - 1] != '\0') {
131
 
            found = FALSE;
132
 
            continue;
133
 
         }
134
 
 
135
 
         /* Truncate the string at the newline character, if it's present. */
136
 
         newline = strchr(queryDir, '\n');
137
 
         if (newline && newline - queryDir < queryDirSize) {
138
 
            *newline = '\0';
139
 
         }
140
 
 
141
 
         found = TRUE;
142
 
      } else if (strncmp(buf, map->remove, map->removeSize - 1) == 0) {
143
 
         found = FALSE;
144
 
      }
145
 
   }
146
 
 
147
 
   fclose(file);
148
 
   return found;
149
 
}