Browse code

Renamed all calls to create_temp_filename()

All places where create_temp_filename() was called are now calling
create_temp_file(). Extra checks on the result of create_temp_file()
is added in addition.

Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
Acked-by: Gert Doering <gert@greenie.muc.de>

David Sommerseth authored on 2010/04/17 05:09:48
Showing 4 changed files
... ...
@@ -615,7 +615,7 @@ init_static (void)
615 615
 #ifdef STATUS_PRINTF_TEST
616 616
   {
617 617
     struct gc_arena gc = gc_new ();
618
-    const char *tmp_file = create_temp_filename ("/tmp", "foo", &gc);
618
+    const char *tmp_file = create_temp_file ("/tmp", "foo", &gc);
619 619
     struct status_output *so = status_open (tmp_file, 0, -1, NULL, STATUS_OUTPUT_WRITE);
620 620
     status_printf (so, "%s", "foo");
621 621
     status_printf (so, "%s", "bar");
... ...
@@ -1530,7 +1530,13 @@ multi_connection_established (struct multi_context *m, struct multi_instance *mi
1530 1530
       if (plugin_defined (mi->context.plugins, OPENVPN_PLUGIN_CLIENT_CONNECT))
1531 1531
 	{
1532 1532
 	  struct argv argv = argv_new ();
1533
-	  const char *dc_file = create_temp_filename (mi->context.options.tmp_dir, "cc", &gc);
1533
+	  const char *dc_file = create_temp_file (mi->context.options.tmp_dir, "cc", &gc);
1534
+
1535
+          if( !dc_file ) {
1536
+            cc_succeeded = false;
1537
+            goto script_depr_failed;
1538
+          }
1539
+
1534 1540
 	  argv_printf (&argv, "%s", dc_file);
1535 1541
 	  delete_file (dc_file);
1536 1542
 	  if (plugin_call (mi->context.plugins, OPENVPN_PLUGIN_CLIENT_CONNECT, &argv, NULL, mi->context.c2.es) != OPENVPN_PLUGIN_FUNC_SUCCESS)
... ...
@@ -1543,6 +1549,7 @@ multi_connection_established (struct multi_context *m, struct multi_instance *mi
1543 1543
 	      multi_client_connect_post (m, mi, dc_file, option_permissions_mask, &option_types_found);
1544 1544
 	      ++cc_succeeded_count;
1545 1545
 	    }
1546
+        script_depr_failed:
1546 1547
 	  argv_reset (&argv);
1547 1548
 	}
1548 1549
 
... ...
@@ -1578,9 +1585,11 @@ multi_connection_established (struct multi_context *m, struct multi_instance *mi
1578 1578
 
1579 1579
 	  setenv_str (mi->context.c2.es, "script_type", "client-connect");
1580 1580
 
1581
-	  dc_file = create_temp_filename (mi->context.options.tmp_dir, "cc", &gc);
1582
-
1583
-	  delete_file (dc_file);
1581
+	  dc_file = create_temp_file (mi->context.options.tmp_dir, "cc", &gc);
1582
+          if( !dc_file ) {
1583
+            cc_succeeded = false;
1584
+            goto script_failed;
1585
+          }
1584 1586
 
1585 1587
 	  argv_printf (&argv, "%sc %s",
1586 1588
 		       mi->context.options.client_connect_script,
... ...
@@ -1593,7 +1602,7 @@ multi_connection_established (struct multi_context *m, struct multi_instance *mi
1593 1593
 	    }
1594 1594
 	  else
1595 1595
 	    cc_succeeded = false;
1596
-
1596
+        script_failed:
1597 1597
 	  argv_reset (&argv);
1598 1598
 	}
1599 1599
 
... ...
@@ -554,24 +554,25 @@ pf_init_context (struct context *c)
554 554
 #ifdef PLUGIN_PF
555 555
   if (plugin_defined (c->plugins, OPENVPN_PLUGIN_ENABLE_PF))
556 556
     {
557
-      const char *pf_file = create_temp_filename (c->options.tmp_dir, "pf", &gc);
558
-      delete_file (pf_file);
559
-      setenv_str (c->c2.es, "pf_file", pf_file);
560
-
561
-      if (plugin_call (c->plugins, OPENVPN_PLUGIN_ENABLE_PF, NULL, NULL, c->c2.es) == OPENVPN_PLUGIN_FUNC_SUCCESS)
562
-	{
563
-	  event_timeout_init (&c->c2.pf.reload, 1, now);
564
-	  c->c2.pf.filename = string_alloc (pf_file, NULL);
565
-	  c->c2.pf.enabled = true;
557
+      const char *pf_file = create_temp_file (c->options.tmp_dir, "pf", &gc);
558
+      if( pf_file ) {
559
+        setenv_str (c->c2.es, "pf_file", pf_file);
560
+
561
+        if (plugin_call (c->plugins, OPENVPN_PLUGIN_ENABLE_PF, NULL, NULL, c->c2.es) == OPENVPN_PLUGIN_FUNC_SUCCESS)
562
+          {
563
+            event_timeout_init (&c->c2.pf.reload, 1, now);
564
+            c->c2.pf.filename = string_alloc (pf_file, NULL);
565
+            c->c2.pf.enabled = true;
566 566
 #ifdef ENABLE_DEBUG
567
-	  if (check_debug_level (D_PF_DEBUG))
568
-	    pf_context_print (&c->c2.pf, "pf_init_context#1", D_PF_DEBUG);
567
+            if (check_debug_level (D_PF_DEBUG))
568
+              pf_context_print (&c->c2.pf, "pf_init_context#1", D_PF_DEBUG);
569 569
 #endif
570
-	}
571
-      else
572
-	{
573
-	  msg (M_WARN, "WARNING: OPENVPN_PLUGIN_ENABLE_PF disabled");
574
-	}
570
+          }
571
+        else
572
+          {
573
+            msg (M_WARN, "WARNING: OPENVPN_PLUGIN_ENABLE_PF disabled");
574
+          }
575
+      }
575 576
     }
576 577
 #endif
577 578
 #ifdef MANAGEMENT_PF
... ...
@@ -1094,10 +1094,11 @@ key_state_gen_auth_control_file (struct key_state *ks, const struct tls_options
1094 1094
   const char *acf;
1095 1095
 
1096 1096
   key_state_rm_auth_control_file (ks);
1097
-  acf = create_temp_filename (opt->tmp_dir, "acf", &gc);
1098
-  ks->auth_control_file = string_alloc (acf, NULL);
1099
-  setenv_str (opt->es, "auth_control_file", ks->auth_control_file);
1100
-
1097
+  acf = create_temp_file (opt->tmp_dir, "acf", &gc);
1098
+  if( acf ) {
1099
+    ks->auth_control_file = string_alloc (acf, NULL);
1100
+    setenv_str (opt->es, "auth_control_file", ks->auth_control_file);
1101
+  } /* FIXME: Should have better error handling? */
1101 1102
   gc_free (&gc);					  
1102 1103
 }
1103 1104
 
... ...
@@ -3215,17 +3216,22 @@ verify_user_pass_script (struct tls_session *session, const struct user_pass *up
3215 3215
 	{
3216 3216
 	  struct status_output *so;
3217 3217
 
3218
-	  tmp_file = create_temp_filename (session->opt->tmp_dir, "up", &gc);
3219
-	  so = status_open (tmp_file, 0, -1, NULL, STATUS_OUTPUT_WRITE);
3220
-	  status_printf (so, "%s", up->username);
3221
-	  status_printf (so, "%s", up->password);
3222
-	  if (!status_close (so))
3223
-	    {
3224
-	      msg (D_TLS_ERRORS, "TLS Auth Error: could not write username/password to file: %s",
3225
-		   tmp_file);
3226
-	      goto done;
3227
-	    }
3228
-	}
3218
+	  tmp_file = create_temp_file (session->opt->tmp_dir, "up", &gc);
3219
+          if( tmp_file ) {
3220
+            so = status_open (tmp_file, 0, -1, NULL, STATUS_OUTPUT_WRITE);
3221
+            status_printf (so, "%s", up->username);
3222
+            status_printf (so, "%s", up->password);
3223
+            if (!status_close (so))
3224
+              {
3225
+                msg (D_TLS_ERRORS, "TLS Auth Error: could not write username/password to file: %s",
3226
+                     tmp_file);
3227
+                goto done;
3228
+              }
3229
+          } else {
3230
+            msg (D_TLS_ERRORS, "TLS Auth Error: could not create write "
3231
+                 "username/password to temp file");
3232
+          }
3233
+        }
3229 3234
       else
3230 3235
 	{
3231 3236
 	  setenv_str (session->opt->es, "username", up->username);