]>
Commit | Line | Data |
---|---|---|
34eabb99 AG |
1 | To: vim-dev@vim.org |
2 | Subject: Patch 6.2.271 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=ISO-8859-1 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 6.2.271 | |
11 | Problem: NetBeans: Can't do "tail -f" on the log. Passing socket info with | |
12 | an argument or environment variable is not secure. | |
13 | Solution: Wait after initializing the log. Allow passing the socket info | |
14 | through a file. (Gordon Prieur) | |
15 | Files: runtime/doc/netbeans.txt, src/main.c, src/netbeans.c | |
16 | ||
17 | ||
18 | *** ../vim-6.2.270/runtime/doc/netbeans.txt Fri Jan 30 21:03:16 2004 | |
19 | --- runtime/doc/netbeans.txt Sun Feb 15 16:45:37 2004 | |
20 | *************** | |
21 | *** 1,4 **** | |
22 | ! *netbeans.txt* For Vim version 6.2. Last change: 2004 Jan 17 | |
23 | ||
24 | ||
25 | VIM REFERENCE MANUAL by Gordon Prieur | |
26 | --- 1,4 ---- | |
27 | ! *netbeans.txt* For Vim version 6.2. Last change: 2004 Feb 15 | |
28 | ||
29 | ||
30 | VIM REFERENCE MANUAL by Gordon Prieur | |
31 | *************** | |
32 | *** 200,207 **** | |
33 | ============================================================================== | |
34 | 9. Running Vim from NetBeans *netbeans-run* | |
35 | ||
36 | ! NetBeans starts Vim with the |-nb| argument. The full form is: > | |
37 | ! -nb:{hostname}:{addr}:{password} | |
38 | ||
39 | {hostname} is the name of the machine where NetBeans is running. When omitted | |
40 | the environment variable "__NETBEANS_HOST" is used or the default "localhost". | |
41 | --- 200,225 ---- | |
42 | ============================================================================== | |
43 | 9. Running Vim from NetBeans *netbeans-run* | |
44 | ||
45 | ! NetBeans starts Vim with the |-nb| argument. Three forms can be used, that | |
46 | ! differ in the way the information for the connection is specified: | |
47 | ! | |
48 | ! -nb={fname} from a file | |
49 | ! -nb:{hostname}:{addr}:{password} directly | |
50 | ! -nb from a file or environment | |
51 | ! | |
52 | ! *E660* | |
53 | ! For security reasons, the best method is to write the information in a file | |
54 | ! readable only by the user. The name of the file can be passed with the | |
55 | ! "-nb={fname}" argument or, when "-nb" is used without a parameter, the | |
56 | ! environment variable "__NETBEANS_CONINFO". The file must contain these three | |
57 | ! lines, in any order: | |
58 | ! | |
59 | ! host={hostname} | |
60 | ! port={addr} | |
61 | ! auth={password} | |
62 | ! | |
63 | ! Other lines are ignored. The caller of Vim is responsible for deleting the | |
64 | ! file afterwards. | |
65 | ||
66 | {hostname} is the name of the machine where NetBeans is running. When omitted | |
67 | the environment variable "__NETBEANS_HOST" is used or the default "localhost". | |
68 | *** ../vim-6.2.270/src/main.c Sun Feb 15 13:37:22 2004 | |
69 | --- src/main.c Sun Feb 15 15:58:56 2004 | |
70 | *************** | |
71 | *** 148,155 **** | |
72 | #endif | |
73 | ||
74 | # ifdef NBDEBUG | |
75 | - nbdebug_wait(WT_ENV | WT_WAIT | WT_STOP, "SPRO_GVIM_WAIT", 20); | |
76 | nbdebug_log_init("SPRO_GVIM_DEBUG", "SPRO_GVIM_DLEVEL"); | |
77 | # endif | |
78 | ||
79 | /* | |
80 | --- 148,155 ---- | |
81 | #endif | |
82 | ||
83 | # ifdef NBDEBUG | |
84 | nbdebug_log_init("SPRO_GVIM_DEBUG", "SPRO_GVIM_DLEVEL"); | |
85 | + nbdebug_wait(WT_ENV | WT_WAIT | WT_STOP, "SPRO_GVIM_WAIT", 20); | |
86 | # endif | |
87 | ||
88 | /* | |
89 | *** ../vim-6.2.270/src/netbeans.c Thu Feb 5 12:09:25 2004 | |
90 | --- src/netbeans.c Sun Feb 15 21:25:26 2004 | |
91 | *************** | |
92 | *** 70,75 **** | |
93 | --- 70,76 ---- | |
94 | static long get_buf_size __ARGS((buf_T *)); | |
95 | ||
96 | static void netbeans_connect __ARGS((void)); | |
97 | + static void getConnInfo __ARGS((char *file, char **host, char **port, char **password)); | |
98 | ||
99 | static void nb_init_graphics __ARGS((void)); | |
100 | static void coloncmd __ARGS((char *cmd, ...)); | |
101 | *************** | |
102 | *** 220,225 **** | |
103 | --- 221,230 ---- | |
104 | } | |
105 | #endif /* FEAT_GUI_W32 */ | |
106 | ||
107 | + #define NB_DEF_HOST "localhost" | |
108 | + #define NB_DEF_ADDR "3219" | |
109 | + #define NB_DEF_PASS "changeme" | |
110 | + | |
111 | static void | |
112 | netbeans_connect(void) | |
113 | { | |
114 | *************** | |
115 | *** 235,271 **** | |
116 | struct sockaddr_un server; | |
117 | #endif | |
118 | char buf[32]; | |
119 | ! char * hostname; | |
120 | ! char * address; | |
121 | ! char * password; | |
122 | ! | |
123 | ! /* netbeansArg is -nb or -nb:<host>:<addr>:<password> */ | |
124 | ! if (netbeansArg[3] == ':') | |
125 | ! netbeansArg += 4; | |
126 | else | |
127 | ! netbeansArg = NULL; | |
128 | ||
129 | ! hostname = netbeansArg; | |
130 | ! if (hostname == NULL || *hostname == '\0') | |
131 | ! hostname = getenv("__NETBEANS_HOST"); | |
132 | ! if (hostname == NULL || *hostname == '\0') | |
133 | ! hostname = "localhost"; /* default */ | |
134 | ||
135 | ! address = strchr(hostname, ':'); | |
136 | ! if (address != NULL) | |
137 | ! *address++ = '\0'; | |
138 | ! else | |
139 | ! address = getenv("__NETBEANS_SOCKET"); | |
140 | if (address == NULL || *address == '\0') | |
141 | ! address = "3219"; /* default */ | |
142 | ! | |
143 | ! password = strchr(address, ':'); | |
144 | ! if (password != NULL) | |
145 | ! *password++ = '\0'; | |
146 | ! else | |
147 | ! password = getenv("__NETBEANS_VIM_PASSWORD"); | |
148 | if (password == NULL || *password == '\0') | |
149 | ! password = "changeme"; /* default */ | |
150 | ||
151 | #ifdef INET_SOCKETS | |
152 | port = atoi(address); | |
153 | --- 240,314 ---- | |
154 | struct sockaddr_un server; | |
155 | #endif | |
156 | char buf[32]; | |
157 | ! char *hostname = NULL; | |
158 | ! char *address = NULL; | |
159 | ! char *password = NULL; | |
160 | ! char *fname; | |
161 | ! char *arg = NULL; | |
162 | ! | |
163 | ! if (netbeansArg[3] == '=') | |
164 | ! /* "-nb=fname": Read info from specified file. */ | |
165 | ! getConnInfo(netbeansArg + 4, &hostname, &address, &password); | |
166 | else | |
167 | ! { | |
168 | ! if (netbeansArg[3] == ':') | |
169 | ! /* "-nb:<host>:<addr>:<password>": get info from argument */ | |
170 | ! arg = netbeansArg + 4; | |
171 | ! if (arg == NULL && (fname = getenv("__NETBEANS_CONINFO")) != NULL) | |
172 | ! /* "-nb": get info from file specified in environment */ | |
173 | ! getConnInfo(fname, &hostname, &address, &password); | |
174 | ! else | |
175 | ! { | |
176 | ! if (arg != NULL) | |
177 | ! { | |
178 | ! /* "-nb:<host>:<addr>:<password>": get info from argument */ | |
179 | ! hostname = arg; | |
180 | ! address = strchr(hostname, ':'); | |
181 | ! if (address != NULL) | |
182 | ! { | |
183 | ! *address++ = '\0'; | |
184 | ! password = strchr(address, ':'); | |
185 | ! if (password != NULL) | |
186 | ! *password++ = '\0'; | |
187 | ! } | |
188 | ! } | |
189 | ||
190 | ! /* Get the missing values from the environment. */ | |
191 | ! if (hostname == NULL || *hostname == '\0') | |
192 | ! hostname = getenv("__NETBEANS_HOST"); | |
193 | ! if (address == NULL) | |
194 | ! address = getenv("__NETBEANS_SOCKET"); | |
195 | ! if (password == NULL) | |
196 | ! password = getenv("__NETBEANS_VIM_PASSWORD"); | |
197 | ! | |
198 | ! /* Move values to allocated memory. */ | |
199 | ! if (hostname != NULL) | |
200 | ! hostname = (char *)vim_strsave((char_u *)hostname); | |
201 | ! if (address != NULL) | |
202 | ! address = (char *)vim_strsave((char_u *)address); | |
203 | ! if (password != NULL) | |
204 | ! password = (char *)vim_strsave((char_u *)password); | |
205 | ! } | |
206 | ! } | |
207 | ||
208 | ! /* Use the default when a value is missing. */ | |
209 | ! if (hostname == NULL || *hostname == '\0') | |
210 | ! { | |
211 | ! vim_free(hostname); | |
212 | ! hostname = (char *)vim_strsave((char_u *)NB_DEF_HOST); | |
213 | ! } | |
214 | if (address == NULL || *address == '\0') | |
215 | ! { | |
216 | ! vim_free(address); | |
217 | ! address = (char *)vim_strsave((char_u *)NB_DEF_ADDR); | |
218 | ! } | |
219 | if (password == NULL || *password == '\0') | |
220 | ! { | |
221 | ! vim_free(password); | |
222 | ! password = (char *)vim_strsave((char_u *)NB_DEF_PASS); | |
223 | ! } | |
224 | ! if (hostname == NULL || address == NULL || password == NULL) | |
225 | ! goto theend; /* out of memory */ | |
226 | ||
227 | #ifdef INET_SOCKETS | |
228 | port = atoi(address); | |
229 | *************** | |
230 | *** 273,279 **** | |
231 | if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) | |
232 | { | |
233 | PERROR("socket() in netbeans_connect()"); | |
234 | ! return; | |
235 | } | |
236 | ||
237 | /* Get the server internet address and put into addr structure */ | |
238 | --- 316,322 ---- | |
239 | if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) | |
240 | { | |
241 | PERROR("socket() in netbeans_connect()"); | |
242 | ! goto theend; | |
243 | } | |
244 | ||
245 | /* Get the server internet address and put into addr structure */ | |
246 | *************** | |
247 | *** 287,304 **** | |
248 | { | |
249 | /* DEBUG: input file */ | |
250 | sd = open(hostname, O_RDONLY); | |
251 | ! return; | |
252 | } | |
253 | PERROR("gethostbyname() in netbeans_connect()"); | |
254 | sd = -1; | |
255 | ! return; | |
256 | } | |
257 | memcpy((char *)&server.sin_addr, host->h_addr, host->h_length); | |
258 | #else | |
259 | if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) | |
260 | { | |
261 | PERROR("socket()"); | |
262 | ! return; | |
263 | } | |
264 | ||
265 | server.sun_family = AF_UNIX; | |
266 | --- 330,347 ---- | |
267 | { | |
268 | /* DEBUG: input file */ | |
269 | sd = open(hostname, O_RDONLY); | |
270 | ! goto theend; | |
271 | } | |
272 | PERROR("gethostbyname() in netbeans_connect()"); | |
273 | sd = -1; | |
274 | ! goto theend; | |
275 | } | |
276 | memcpy((char *)&server.sin_addr, host->h_addr, host->h_length); | |
277 | #else | |
278 | if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) | |
279 | { | |
280 | PERROR("socket()"); | |
281 | ! goto theend; | |
282 | } | |
283 | ||
284 | server.sun_family = AF_UNIX; | |
285 | *************** | |
286 | *** 315,327 **** | |
287 | if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) | |
288 | { | |
289 | PERROR("socket()#2 in netbeans_connect()"); | |
290 | ! return; | |
291 | } | |
292 | #else | |
293 | if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) | |
294 | { | |
295 | PERROR("socket()#2 in netbeans_connect()"); | |
296 | ! return; | |
297 | } | |
298 | #endif | |
299 | if (connect(sd, (struct sockaddr *)&server, sizeof(server))) | |
300 | --- 358,370 ---- | |
301 | if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) | |
302 | { | |
303 | PERROR("socket()#2 in netbeans_connect()"); | |
304 | ! goto theend; | |
305 | } | |
306 | #else | |
307 | if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) | |
308 | { | |
309 | PERROR("socket()#2 in netbeans_connect()"); | |
310 | ! goto theend; | |
311 | } | |
312 | #endif | |
313 | if (connect(sd, (struct sockaddr *)&server, sizeof(server))) | |
314 | *************** | |
315 | *** 368,374 **** | |
316 | --- 411,463 ---- | |
317 | ||
318 | haveConnection = TRUE; | |
319 | ||
320 | + theend: | |
321 | + vim_free(hostname); | |
322 | + vim_free(address); | |
323 | + vim_free(password); | |
324 | return; | |
325 | + } | |
326 | + | |
327 | + /* | |
328 | + * Obtain the NetBeans hostname, port address and password from a file. | |
329 | + * Return the strings in allocated memory. | |
330 | + */ | |
331 | + static void | |
332 | + getConnInfo(char *file, char **host, char **port, char **auth) | |
333 | + { | |
334 | + FILE *fp = mch_fopen(file, "r"); | |
335 | + char_u buf[BUFSIZ]; | |
336 | + char_u *lp; | |
337 | + char_u *nl; | |
338 | + | |
339 | + if (fp == NULL) | |
340 | + PERROR("E660: Cannot open NetBeans connection info file"); | |
341 | + else | |
342 | + { | |
343 | + /* Read the file. There should be one of each parameter */ | |
344 | + while ((lp = (char_u *)fgets((char *)buf, BUFSIZ, fp)) != NULL) | |
345 | + { | |
346 | + if ((nl = vim_strchr(lp, '\n')) != NULL) | |
347 | + *nl = 0; /* strip off the trailing newline */ | |
348 | + | |
349 | + if (STRNCMP(lp, "host=", 5) == 0) | |
350 | + { | |
351 | + vim_free(*host); | |
352 | + *host = (char *)vim_strsave(&buf[5]); | |
353 | + } | |
354 | + else if (STRNCMP(lp, "port=", 5) == 0) | |
355 | + { | |
356 | + vim_free(*port); | |
357 | + *port = (char *)vim_strsave(&buf[5]); | |
358 | + } | |
359 | + else if (STRNCMP(lp, "auth=", 5) == 0) | |
360 | + { | |
361 | + vim_free(*auth); | |
362 | + *auth = (char *)vim_strsave(&buf[5]); | |
363 | + } | |
364 | + } | |
365 | + fclose(fp); | |
366 | + } | |
367 | } | |
368 | ||
369 | ||
370 | *** ../vim-6.2.270/src/version.c Tue Feb 17 21:46:46 2004 | |
371 | --- src/version.c Thu Feb 19 14:39:28 2004 | |
372 | *************** | |
373 | *** 639,640 **** | |
374 | --- 639,642 ---- | |
375 | { /* Add new patch number below this line */ | |
376 | + /**/ | |
377 | + 271, | |
378 | /**/ | |
379 | ||
380 | -- | |
381 | hundred-and-one symptoms of being an internet addict: | |
382 | 184. You no longer ask prospective dates what their sign is, instead | |
383 | your line is "Hi, what's your URL?" | |
384 | ||
385 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
386 | /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
387 | \\\ Project leader for A-A-P -- http://www.A-A-P.org /// | |
388 | \\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html /// |