home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 6.2.271 < prev    next >
Encoding:
Internet Message Format  |  2004-02-18  |  10.8 KB

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