OpenVAS Manager  7.0.3~git
lsc_user.c
Go to the documentation of this file.
1 /* OpenVAS Manager
2  * $Id$
3  * Description: LSC user credentials package generation.
4  *
5  * Authors:
6  * Matthew Mundell <matthew.mundell@greenbone.net>
7  * Michael Wiegand <michael.wiegand@greenbone.net>
8  * Felix Wolfsteller <felix.wolfsteller@greenbone.net>
9  *
10  * Copyright:
11  * Copyright (C) 2009 Greenbone Networks GmbH
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26  */
27 
28 #include <glib.h>
29 #include <glib/gstdio.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <unistd.h>
34 #include <sys/stat.h>
35 #include <sys/types.h>
36 #include <sys/wait.h>
37 
38 #include <openvas/base/openvas_file.h>
39 
40 #undef G_LOG_DOMAIN
41 
44 #define G_LOG_DOMAIN "md manage"
45 
46 
47 /* Helpers. */
48 
66 static int
67 check_is_file (const char *name)
68 {
69  struct stat sb;
70 
71  if (stat (name, &sb))
72  {
73  return -1;
74  }
75  else
76  {
77  return (S_ISREG (sb.st_mode));
78  }
79 }
80 
81 
82 /* Key creation. */
83 
97 static int
98 create_ssh_key (const char *comment, const char *passphrase,
99  const char *privpath)
100 {
101  gchar *astdout = NULL;
102  gchar *astderr = NULL;
103  GError *err = NULL;
104  gint exit_status = 0;
105  gchar *dir;
106  char *command;
107 
108  /* Sanity-check essential parameters. */
109 
110  if (!comment || comment[0] == '\0')
111  {
112  g_debug ("%s: comment must be set", __FUNCTION__);
113  return -1;
114  }
115  if (!passphrase || strlen (passphrase) < 5)
116  {
117  g_debug ("%s: password must be longer than 4 characters", __FUNCTION__);
118  return -1;
119  }
120 
121  /* Sanity check files. */
122 
123  dir = g_path_get_dirname (privpath);
124  if (g_mkdir_with_parents (dir, 0755 /* "rwxr-xr-x" */ ))
125  {
126  g_debug ("%s: failed to access %s", __FUNCTION__, dir);
127  g_free (dir);
128  return -1;
129  }
130  g_free (dir);
131 
132  /* Spawn ssh-keygen. */
133  command = g_strconcat ("ssh-keygen -t rsa -f ", privpath, " -C \"", comment,
134  "\" -P \"", passphrase, "\"", NULL);
135  g_debug ("command: ssh-keygen -t rsa -f %s -C \"%s\" -P \"********\"",
136  privpath, comment);
137 
138  if ((g_spawn_command_line_sync (command, &astdout, &astderr, &exit_status,
139  &err)
140  == FALSE)
141  || (WIFEXITED (exit_status) == 0)
142  || WEXITSTATUS (exit_status))
143  {
144  if (err)
145  {
146  g_debug ("%s: failed to create private key: %s\n",
147  __FUNCTION__, err->message);
148  g_error_free (err);
149  }
150  else
151  g_debug ("%s: failed to create private key\n", __FUNCTION__);
152  g_debug ("%s: key-gen failed with %d (WIF %i, WEX %i).\n",
153  __FUNCTION__, exit_status, WIFEXITED (exit_status),
154  WEXITSTATUS (exit_status));
155  g_debug ("%s: stdout: %s", __FUNCTION__, astdout);
156  g_debug ("%s: stderr: %s", __FUNCTION__, astderr);
157  g_free (command);
158  g_free (astdout);
159  g_free (astderr);
160  return -1;
161  }
162  g_free (command);
163  g_free (astdout);
164  g_free (astderr);
165  return 0;
166 }
167 
176 int
177 lsc_user_keys_create (const gchar *password,
178  gchar **private_key)
179 {
180  GError *error;
181  gsize length;
182  char key_dir[] = "/tmp/openvas_key_XXXXXX";
183  gchar *key_path = NULL;
184  int ret = -1;
185 
186  /* Make a directory for the keys. */
187 
188  if (mkdtemp (key_dir) == NULL)
189  return -1;
190 
191  /* Create private key. */
192  key_path = g_build_filename (key_dir, "key", NULL);
193  if (create_ssh_key ("Key generated by OpenVAS Manager", password, key_path))
194  goto free_exit;
195 
196  error = NULL;
197  g_file_get_contents (key_path, private_key, &length, &error);
198  if (error)
199  {
200  g_error_free (error);
201  goto free_exit;
202  }
203  ret = 0;
204  free_exit:
205 
206  g_free (key_path);
207  openvas_file_remove_recurse (key_dir);
208  return ret;
209 }
210 
211 
212 /* RPM package generation. */
213 
222 static const gchar *
223 get_rpm_generator_path ()
224 {
225  static gchar *rpm_generator_path = NULL;
226 
227  if (rpm_generator_path == NULL)
228  {
229  gchar *path_exec = g_build_filename (OPENVAS_DATA_DIR,
230  "openvas-lsc-rpm-creator.sh",
231  NULL);
232  if (check_is_file (path_exec) == 0)
233  {
234  g_free (path_exec);
235  return NULL;
236  }
237  g_free (path_exec);
238  rpm_generator_path = g_strdup (OPENVAS_DATA_DIR);
239  }
240 
241  return rpm_generator_path;
242 }
243 
254 static gboolean
255 lsc_user_rpm_create (const gchar *username,
256  const gchar *public_key_path,
257  const gchar *to_filename)
258 {
259  const gchar *generator_path;
260  gchar *rpm_path = NULL;
261  gint exit_status;
262  gchar *new_pubkey_filename = NULL;
263  gchar *pubkey_basename = NULL;
264  gchar **cmd;
265  char tmpdir[] = "/tmp/lsc_user_rpm_create_XXXXXX";
266  gboolean success = TRUE;
267  gchar *standard_out = NULL;
268  gchar *standard_err = NULL;
269  gchar *rpmfile;
270 
271  generator_path = get_rpm_generator_path ();
272 
273  /* Create a temporary directory. */
274 
275  g_debug ("%s: create temporary directory", __FUNCTION__);
276  if (mkdtemp (tmpdir) == NULL)
277  return FALSE;
278  g_debug ("%s: temporary directory: %s\n", __FUNCTION__, tmpdir);
279 
280  /* Copy the public key into the temporary directory. */
281 
282  g_debug ("%s: copy key to temporary directory\n", __FUNCTION__);
283  pubkey_basename = g_strdup_printf ("%s.pub", username);
284  new_pubkey_filename = g_build_filename (tmpdir, pubkey_basename, NULL);
285  if (openvas_file_copy (public_key_path, new_pubkey_filename)
286  == FALSE)
287  {
288  g_debug ("%s: failed to copy key file %s to %s",
289  __FUNCTION__, public_key_path, new_pubkey_filename);
290  g_free (pubkey_basename);
291  g_free (new_pubkey_filename);
292  return FALSE;
293  }
294 
295  /* Execute create-rpm script with the temporary directory as the
296  * target and the public key in the temporary directory as the key. */
297 
298  g_debug ("%s: Attempting RPM build\n", __FUNCTION__);
299  cmd = (gchar **) g_malloc (5 * sizeof (gchar *));
300  cmd[0] = g_strdup ("./openvas-lsc-rpm-creator.sh");
301  cmd[1] = g_strdup ("--target");
302  cmd[2] = g_strdup (tmpdir);
303  cmd[3] = g_build_filename (tmpdir, pubkey_basename, NULL);
304  cmd[4] = NULL;
305  g_debug ("%s: Spawning in %s: %s %s %s %s\n",
306  __FUNCTION__, generator_path, cmd[0], cmd[1], cmd[2], cmd[3]);
307  if ((g_spawn_sync (generator_path,
308  cmd,
309  NULL, /* Environment. */
310  G_SPAWN_SEARCH_PATH,
311  NULL, /* Setup function. */
312  NULL,
313  &standard_out,
314  &standard_err,
315  &exit_status,
316  NULL)
317  == FALSE)
318  || (WIFEXITED (exit_status) == 0)
319  || WEXITSTATUS (exit_status))
320  {
321  g_debug ("%s: failed to create the rpm: %d (WIF %i, WEX %i)",
322  __FUNCTION__,
323  exit_status,
324  WIFEXITED (exit_status),
325  WEXITSTATUS (exit_status));
326  g_debug ("%s: stdout: %s\n", __FUNCTION__, standard_out);
327  g_debug ("%s: stderr: %s\n", __FUNCTION__, standard_err);
328  success = FALSE;
329  }
330 
331  g_free (cmd[0]);
332  g_free (cmd[1]);
333  g_free (cmd[2]);
334  g_free (cmd[3]);
335  g_free (cmd[4]);
336  g_free (cmd);
337  g_free (pubkey_basename);
338  g_free (new_pubkey_filename);
339  g_free (standard_out);
340  g_free (standard_err);
341 
342  /* Build the filename that the RPM in the temporary directory has,
343  * for example RPMS/noarch/openvas-lsc-target-example_user-0.5-1.noarch.rpm.
344  */
345 
346  rpmfile = g_strconcat ("openvas-lsc-target-",
347  username,
348  "-0.5-1.noarch.rpm",
349  NULL);
350  rpm_path = g_build_filename (tmpdir, rpmfile, NULL);
351  g_debug ("%s: new filename (rpm_path): %s\n", __FUNCTION__, rpm_path);
352 
353  /* Move the RPM from the temporary directory to the given destination. */
354 
355  if (openvas_file_move (rpm_path, to_filename) == FALSE && success == TRUE)
356  {
357  g_debug ("%s: failed to move RPM %s to %s",
358  __FUNCTION__, rpm_path, to_filename);
359  success = FALSE;
360  }
361 
362  /* Remove the copy of the public key and the temporary directory. */
363 
364  if (openvas_file_remove_recurse (tmpdir) != 0 && success == TRUE)
365  {
366  g_debug ("%s: failed to remove temporary directory %s",
367  __FUNCTION__, tmpdir);
368  success = FALSE;
369  }
370 
371  g_free (rpm_path);
372  g_free (rpmfile);
373 
374  return success;
375 }
376 
384 static gboolean
385 alien_found ()
386 {
387  static gboolean searched = FALSE;
388  static gboolean found = FALSE;
389 
390  if (searched == FALSE)
391  {
392  /* Check if alien is found in path. */
393  gchar *alien_path = g_find_program_in_path ("alien");
394  if (alien_path != NULL)
395  {
396  found = TRUE;
397  g_free (alien_path);
398  }
399  searched = TRUE;
400  }
401 
402  return found;
403 }
404 
415 int
416 lsc_user_rpm_recreate (const gchar *name, const char *public_key,
417  void **rpm, gsize *rpm_size)
418 {
419  GError *error;
420  char rpm_dir[] = "/tmp/rpm_XXXXXX";
421  char key_dir[] = "/tmp/key_XXXXXX";
422  gchar *rpm_path, *public_key_path;
423  int ret = -1;
424 
425  if (alien_found () == FALSE)
426  {
427  g_warning ("%s: Need \"alien\" to make RPMs\n", __FUNCTION__);
428  return -1;
429  }
430 
431  /* Make a directory for the key. */
432 
433  if (mkdtemp (key_dir) == NULL)
434  return -1;
435 
436  /* Write public key to file. */
437 
438  error = NULL;
439  public_key_path = g_build_filename (key_dir, "key.pub", NULL);
440  g_file_set_contents (public_key_path, public_key, strlen (public_key),
441  &error);
442  if (error)
443  goto free_exit;
444 
445  /* Create RPM package. */
446 
447  if (mkdtemp (rpm_dir) == NULL)
448  goto free_exit;
449  rpm_path = g_build_filename (rpm_dir, "p.rpm", NULL);
450  g_debug ("%s: rpm_path: %s", __FUNCTION__, rpm_path);
451  if (lsc_user_rpm_create (name, public_key_path, rpm_path) == FALSE)
452  {
453  g_free (rpm_path);
454  goto rm_exit;
455  }
456 
457  /* Read the package into memory. */
458 
459  error = NULL;
460  g_file_get_contents (rpm_path, (gchar **) rpm, rpm_size, &error);
461  g_free (rpm_path);
462  if (error)
463  {
464  g_error_free (error);
465  goto rm_exit;
466  }
467 
468  /* Return. */
469 
470  ret = 0;
471 
472  rm_exit:
473 
474  openvas_file_remove_recurse (rpm_dir);
475 
476  free_exit:
477 
478  g_free (public_key_path);
479 
480  openvas_file_remove_recurse (key_dir);
481 
482  return ret;
483 }
484 
485 
486 /* Deb generation. */
487 
496 static int
497 execute_alien (const gchar *rpmdir, const gchar *rpmfile)
498 {
499  gchar **cmd;
500  gint exit_status;
501  int ret = 0;
502  gchar *standard_out = NULL;
503  gchar *standard_err = NULL;
504 
505  cmd = (gchar **) g_malloc (7 * sizeof (gchar *));
506 
507  cmd[0] = g_strdup ("fakeroot");
508  cmd[1] = g_strdup ("--");
509  cmd[2] = g_strdup ("alien");
510  cmd[3] = g_strdup ("--scripts");
511  cmd[4] = g_strdup ("--keep-version");
512  cmd[5] = g_strdup (rpmfile);
513  cmd[6] = NULL;
514  g_debug ("--- executing alien.\n");
515  g_debug ("%s: Spawning in %s: %s %s %s %s %s %s\n",
516  __FUNCTION__,
517  rpmdir, cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5]);
518  if ((g_spawn_sync (rpmdir,
519  cmd,
520  NULL, /* Environment. */
521  G_SPAWN_SEARCH_PATH,
522  NULL, /* Setup func. */
523  NULL,
524  &standard_out,
525  &standard_err,
526  &exit_status,
527  NULL) == FALSE)
528  || (WIFEXITED (exit_status) == 0)
529  || WEXITSTATUS (exit_status))
530  {
531  g_debug ("%s: failed to create the deb: %d (WIF %i, WEX %i)",
532  __FUNCTION__,
533  exit_status,
534  WIFEXITED (exit_status),
535  WEXITSTATUS (exit_status));
536  g_debug ("%s: stdout: %s\n", __FUNCTION__, standard_out);
537  g_debug ("%s: stderr: %s\n", __FUNCTION__, standard_err);
538  ret = -1;
539  }
540 
541  g_free (cmd[0]);
542  g_free (cmd[1]);
543  g_free (cmd[2]);
544  g_free (cmd[3]);
545  g_free (cmd[4]);
546  g_free (cmd[5]);
547  g_free (cmd[6]);
548  g_free (cmd);
549  g_free (standard_out);
550  g_free (standard_err);
551 
552  return ret;
553 }
554 
563 gchar *
564 lsc_user_deb_create (const gchar *user, const gchar *rpm_file)
565 {
566  gchar *dirname = g_path_get_dirname (rpm_file);
567  gchar *dir = g_strconcat (dirname, "/", NULL);
568  gchar *basename = g_path_get_basename (rpm_file);
569  gchar *down_user = g_ascii_strdown (user ? user : "user", -1);
570  gchar *deb_name = g_strdup_printf ("%s/openvas-lsc-target-%s_0.5-1_all.deb",
571  dirname, down_user);
572 
573  g_free (dirname);
574  g_free (down_user);
575 
576  if (execute_alien (dir, basename))
577  {
578  g_free (dir);
579  g_free (basename);
580  g_free (deb_name);
581  return NULL;
582  }
583 
584  g_free (dir);
585  g_free (basename);
586 
587  return deb_name;
588 }
589 
601 int
602 lsc_user_deb_recreate (const gchar *name, const char *rpm, gsize rpm_size,
603  void **deb, gsize *deb_size)
604 {
605  GError *error;
606  char deb_dir[] = "/tmp/deb_XXXXXX";
607  char rpm_dir[] = "/tmp/rpm_XXXXXX";
608  gchar *deb_path, *rpm_path;
609  int ret = -1;
610 
611  if (alien_found () == FALSE)
612  {
613  g_warning ("%s: Need \"alien\" to make DEBs\n", __FUNCTION__);
614  return -1;
615  }
616 
617  /* Make a directory for the RPM. */
618 
619  if (mkdtemp (rpm_dir) == NULL)
620  return -1;
621 
622  /* Write RPM to disk. */
623 
624  error = NULL;
625  rpm_path = g_build_filename (rpm_dir, "p.rpm", NULL);
626  g_file_set_contents (rpm_path, rpm, rpm_size, &error);
627  if (error)
628  goto free_exit;
629 
630  /* Create Debian package. */
631 
632  if (mkdtemp (deb_dir) == NULL)
633  goto free_exit;
634  deb_path = lsc_user_deb_create (name, rpm_path);
635  if (deb_path == NULL)
636  goto rm_exit;
637 
638  /* Read the package into memory. */
639 
640  error = NULL;
641  g_file_get_contents (deb_path, (gchar **) deb, deb_size, &error);
642  g_free (deb_path);
643  if (error)
644  {
645  g_error_free (error);
646  goto rm_exit;
647  }
648 
649  /* Return. */
650 
651  ret = 0;
652 
653  rm_exit:
654 
655  openvas_file_remove_recurse (deb_dir);
656 
657  free_exit:
658 
659  g_free (rpm_path);
660 
661  openvas_file_remove_recurse (rpm_dir);
662 
663  return ret;
664 }
665 
666 
667 /* Exe generation. */
668 
679 static int
680 create_nsis_script (const gchar *script_name, const gchar *package_name,
681  const gchar *user_name, const gchar *password)
682 {
683  FILE* fd;
684 
685  fd = fopen (script_name, "w");
686  if (fd == NULL)
687  return -1;
688 
689  // Write part about default section
690  fprintf (fd, "#Installer filename\n");
691  fprintf (fd, "outfile ");
692  fprintf (fd, "%s", package_name);
693  fprintf (fd, "\n\n");
694 
695  fprintf (fd, "# Set desktop as install directory\n");
696  fprintf (fd, "installDir $DESKTOP\n\n");
697 
698  fprintf (fd, "# Put some text\n");
699  fprintf (fd, "BrandingText \"OpenVAS Local Security Checks User\"\n\n");
700 
701  // For ms vista installers we need the UAC plugin and use the following lines:
702  // This requires the user to have the UAC plugin installed and to provide the
703  // the path to it.
704  //fprintf (fd, "# Request application privileges for Windows Vista\n");
705  //fprintf (fd, "RequestExecutionLevel admin\n\n");
706 
707  fprintf (fd, "#\n# Default (installer) section.\n#\n");
708  fprintf (fd, "section\n\n");
709 
710  fprintf (fd, "# Define output path\n");
711  fprintf (fd, "setOutPath $INSTDIR\n\n");
712 
713  fprintf (fd, "# Uninstaller name\n");
714  fprintf (fd, "writeUninstaller $INSTDIR\\openvas_lsc_remove_%s.exe\n\n",
715  user_name);
716 
717  // Need to find localized Administrators group name, create a
718  // GetAdminGroupName - vb script (Thanks to Thomas Rotter)
719  fprintf (fd, "# Create Thomas Rotters GetAdminGroupName.vb script\n");
720  fprintf (fd, "ExecWait \"cmd /C Echo Set objWMIService = GetObject($\\\"winmgmts:\\\\.\\root\\cimv2$\\\") > $\\\"%%temp%%\\GetAdminGroupName.vbs$\\\" \"\n");
721  fprintf (fd, "ExecWait \"cmd /C Echo Set colAccounts = objWMIService.ExecQuery ($\\\"Select * From Win32_Group Where SID = 'S-1-5-32-544'$\\\") >> $\\\"%%temp%%\\GetAdminGroupName.vbs$\\\"\"\n");
722  fprintf (fd, "ExecWait \"cmd /C Echo For Each objAccount in colAccounts >> $\\\"%%temp%%\\GetAdminGroupName.vbs$\\\"\"\n");
723  fprintf (fd, "ExecWait \"cmd /C Echo Wscript.Echo objAccount.Name >> $\\\"%%temp%%\\GetAdminGroupName.vbs$\\\"\"\n");
724  fprintf (fd, "ExecWait \"cmd /C Echo Next >> $\\\"%%temp%%\\GetAdminGroupName.vbs$\\\"\"\n");
725  fprintf (fd, "ExecWait \"cmd /C cscript //nologo $\\\"%%temp%%\\GetAdminGroupName.vbs$\\\" > $\\\"%%temp%%\\AdminGroupName.txt$\\\"\"\n\n");
726 
728  fprintf (fd, "# Create batch script that installs the user\n");
729  fprintf (fd, "ExecWait \"cmd /C Echo Set /P AdminGroupName= ^<$\\\"%%temp%%\\AdminGroupName.txt$\\\" > $\\\"%%temp%%\\AddUser.bat$\\\"\" \n");
730  fprintf (fd, "ExecWait \"cmd /C Echo net user %s %s /add /active:yes >> $\\\"%%temp%%\\AddUser.bat$\\\"\"\n",
731  user_name,
732  password);
733  fprintf (fd, "ExecWait \"cmd /C Echo net localgroup %%AdminGroupName%% %%COMPUTERNAME%%\\%s /add >> $\\\"%%temp%%\\AddUser.bat$\\\"\"\n\n",
734  user_name);
735 
736  fprintf (fd, "# Execute AddUser script\n");
737  fprintf (fd, "ExecWait \"cmd /C $\\\"%%temp%%\\AddUser.bat$\\\"\"\n\n");
738 
739  // Remove up temporary files for localized Administrators group names
740  fprintf (fd, "# Remove temporary files for localized admin group names\n");
741  fprintf (fd, "ExecWait \"del $\\\"%%temp%%\\AdminGroupName.txt$\\\"\"\n");
742  fprintf (fd, "ExecWait \"del $\\\"%%temp%%\\GetAdminGroupName.vbs$\\\"\"\n\n");
743  fprintf (fd, "ExecWait \"del $\\\"%%temp%%\\AddUser.bat$\\\"\"\n\n");
744 
746  fprintf (fd, "# Display message that everything seems to be fine\n");
747  fprintf (fd, "messageBox MB_OK \"A user has been added. An uninstaller is placed on your Desktop.\"\n\n");
748 
749  fprintf (fd, "# Default (install) section end\n");
750  fprintf (fd, "sectionEnd\n\n");
751 
752  // Write part about uninstall section
753  fprintf (fd, "#\n# Uninstaller section.\n#\n");
754  fprintf (fd, "section \"Uninstall\"\n\n");
755 
756  fprintf (fd, "# Run cmd to remove user\n");
757  fprintf (fd, "ExecWait \"net user %s /delete\"\n\n",
758  user_name);
759 
761  fprintf (fd, "# Unistaller should remove itself (from desktop/installdir)\n\n");
762 
763  fprintf (fd, "# Display message that everything seems to be fine\n");
764  fprintf (fd, "messageBox MB_OK \"A user has been removed. You can now savely remmove the uninstaller from your Desktop.\"\n\n");
765 
766  fprintf (fd, "# Uninstaller section end\n");
767  fprintf (fd, "sectionEnd\n\n");
768 
769  if (fclose (fd))
770  return -1;
771 
772  return 0;
773 }
774 
784 static int
785 execute_makensis (const gchar *nsis_script)
786 {
787  gchar *dirname = g_path_get_dirname (nsis_script);
788  gchar **cmd;
789  gint exit_status;
790  int ret = 0;
791  gchar *standard_out = NULL;
792  gchar *standard_err = NULL;
793 
794  cmd = (gchar **) g_malloc (3 * sizeof (gchar *));
795 
796  cmd[0] = g_strdup ("makensis");
797  cmd[1] = g_strdup (nsis_script);
798  cmd[2] = NULL;
799  g_debug ("--- executing makensis.\n");
800  g_debug ("%s: Spawning in %s: %s %s\n",
801  __FUNCTION__,
802  dirname, cmd[0], cmd[1]);
803  if ((g_spawn_sync (dirname,
804  cmd,
805  NULL, /* Environment. */
806  G_SPAWN_SEARCH_PATH,
807  NULL, /* Setup func. */
808  NULL,
809  &standard_out,
810  &standard_err,
811  &exit_status,
812  NULL) == FALSE)
813  || (WIFEXITED (exit_status) == 0)
814  || WEXITSTATUS (exit_status))
815  {
816  g_debug ("%s: failed to create the exe: %d (WIF %i, WEX %i)",
817  __FUNCTION__,
818  exit_status,
819  WIFEXITED (exit_status),
820  WEXITSTATUS (exit_status));
821  g_debug ("%s: stdout: %s\n", __FUNCTION__, standard_out);
822  g_debug ("%s: stderr: %s\n", __FUNCTION__, standard_err);
823  ret = -1;
824  }
825 
826  g_free (cmd[0]);
827  g_free (cmd[1]);
828  g_free (cmd);
829  g_free (dirname);
830  g_free (standard_out);
831  g_free (standard_err);
832 
833  return ret;
834 }
835 
845 static int
846 lsc_user_exe_create (const gchar *user_name, const gchar *password,
847  const gchar *to_filename)
848 {
849  gchar *dirname = g_path_get_dirname (to_filename);
850  gchar *nsis_script = g_build_filename (dirname, "p.nsis", NULL);
851 
852  g_free (dirname);
853 
854  if (create_nsis_script (nsis_script, to_filename, user_name, password))
855  {
856  g_warning ("%s: Failed to create NSIS script\n", __FUNCTION__);
857  g_free (nsis_script);
858  return -1;
859  }
860 
861  if (execute_makensis (nsis_script))
862  {
863  g_warning ("%s: Failed to execute makensis\n", __FUNCTION__);
864  g_free (nsis_script);
865  return -1;
866  }
867 
868  g_free (nsis_script);
869  return 0;
870 }
871 
882 int
883 lsc_user_exe_recreate (const gchar *name, const gchar *password,
884  void **exe, gsize *exe_size)
885 {
886  GError *error;
887  char exe_dir[] = "/tmp/exe_XXXXXX";
888  gchar *exe_path;
889  int ret = -1;
890 
891  if (alien_found () == FALSE)
892  {
893  g_warning ("%s: Need \"alien\" to make EXEs\n", __FUNCTION__);
894  return -1;
895  }
896 
897  /* Create NSIS package. */
898 
899  if (mkdtemp (exe_dir) == NULL)
900  return -1;
901  exe_path = g_build_filename (exe_dir, "p.nsis", NULL);
902  if (lsc_user_exe_create (name, password, exe_path))
903  goto rm_exit;
904 
905  /* Read the package into memory. */
906 
907  error = NULL;
908  g_file_get_contents (exe_path, (gchar **) exe, exe_size, &error);
909  if (error)
910  {
911  g_error_free (error);
912  goto rm_exit;
913  }
914 
915  /* Return. */
916 
917  ret = 0;
918 
919  rm_exit:
920 
921  openvas_file_remove_recurse (exe_dir);
922 
923  g_free (exe_path);
924 
925  return ret;
926 }
int lsc_user_deb_recreate(const gchar *name, const char *rpm, gsize rpm_size, void **deb, gsize *deb_size)
Recreate Debian package.
Definition: lsc_user.c:602
gchar * user_name(const char *)
Return the name of a user.
Definition: manage_sql.c:66287
int lsc_user_rpm_recreate(const gchar *name, const char *public_key, void **rpm, gsize *rpm_size)
Recreate RPM package.
Definition: lsc_user.c:416
gchar * lsc_user_deb_create(const gchar *user, const gchar *rpm_file)
Create a Debian package from an LSC user RPM package.
Definition: lsc_user.c:564
int lsc_user_exe_recreate(const gchar *name, const gchar *password, void **exe, gsize *exe_size)
Recreate NSIS package.
Definition: lsc_user.c:883
int lsc_user_keys_create(const gchar *password, gchar **private_key)
Create local security check (LSC) keys.
Definition: lsc_user.c:177