[Openvas-commits] r3237 - in trunk/openvas-client: . src/util
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue May 5 13:01:20 CEST 2009
Author: felix
Date: 2009-05-05 13:01:20 +0200 (Tue, 05 May 2009)
New Revision: 3237
Modified:
trunk/openvas-client/ChangeLog
trunk/openvas-client/src/util/openvas_lsc_user_makensis.c
Log:
Can noe build executable with nsis that installs a user on win xp
machines if executed with admin rights.
* src/util/openvas_lsc_user_makensis.c (execute_makensis): Executes
makensis on a given (.nis) file.
* src/util/openvas_lsc_user_makensis.c (create_nsi_file): Adjusted
resulting nsi script, so that it calls 'net user ...' in install and
uninstall process, todos added.
Modified: trunk/openvas-client/ChangeLog
===================================================================
--- trunk/openvas-client/ChangeLog 2009-05-05 10:35:44 UTC (rev 3236)
+++ trunk/openvas-client/ChangeLog 2009-05-05 11:01:20 UTC (rev 3237)
@@ -1,5 +1,17 @@
-2009-05-04 Felix Wolfsteller <felix.wolfsteller at intevation.de>
+2009-05-05 Felix Wolfsteller <felix.wolfsteller at intevation.de>
+ Can now build executable with nsis that installs a user on win xp
+ machines if executed with admin rights.
+
+ * src/util/openvas_lsc_user_makensis.c (execute_makensis): Executes
+ makensis on a given (.nis) file.
+
+ * src/util/openvas_lsc_user_makensis.c (create_nsi_file): Adjusted
+ resulting nsi script, so that it calls 'net user ...' in install and
+ uninstall process, todos added.
+
+2009-05-05 Felix Wolfsteller <felix.wolfsteller at intevation.de>
+
Cosmetics.
* libnessus/addslashes.c: Reformatting and doc.
Modified: trunk/openvas-client/src/util/openvas_lsc_user_makensis.c
===================================================================
--- trunk/openvas-client/src/util/openvas_lsc_user_makensis.c 2009-05-05 10:35:44 UTC (rev 3236)
+++ trunk/openvas-client/src/util/openvas_lsc_user_makensis.c 2009-05-05 11:01:20 UTC (rev 3237)
@@ -44,9 +44,17 @@
* the 'account'.
*
* For ms windows systems an executable can be created that installs the user.
- * To arrive at a windows executable, the nsis (nulsoft scriptable installer
+ * To arrive at a windows executable, the nsis (Nullsoft scriptable installer
* system) is used.
* With nsis executables are created from .nsi files with the tool makensis.
+ *
+ * Users are managed on ms windos systems using 'net':
+ at verbatim
+ net user <username> <password> /add /active:yes
+ net user <username> <password> /delete
+ // Currently not done:
+ net localgroup <local group> <local account> /<ADD>
+ at endverbatim
*/
#include "openvas_ssh_login.h"
@@ -84,20 +92,21 @@
}
/**
- * @brief Writes a nsi file to be used with the 'nulsoft scriptable installer
+ * @brief Writes a nsi file to be used with the 'Nullsoft scriptable installer
* @brief system'.
*/
static gboolean
-create_nsi_file (gchar* nsifilename, openvas_ssh_login* loginfo,
+create_nsi_file (const gchar* nsifilename, const openvas_ssh_login* loginfo,
const gchar* outfilename)
{
FILE* fd;
+
fd = fopen (nsifilename, "w");
if (fd <= 0)
return FALSE;
// Write part about default section
- fprintf (fd, "#Installer name\n");
+ fprintf (fd, "#Installer filename\n");
fprintf (fd, "outfile ");
fprintf (fd, outfilename);
fprintf (fd, "\n\n");
@@ -107,15 +116,22 @@
fprintf (fd, "#\n# Default (installer) section.\n#\n");
fprintf (fd, "section\n\n");
+ /** TODO check if we have admin rights, fail with a message if not */
fprintf (fd, "# Define output path\n");
fprintf (fd, "setOutPath $INSTDIR\n\n");
fprintf (fd, "# Uninstaller name\n");
- fprintf (fd, "writeUninstaller $INSTDIR\\openvas_lsc_remove_account.exe\n");
+ fprintf (fd, "writeUninstaller $INSTDIR\\openvas_lsc_remove_%s.exe\n\n",
+ loginfo->username);
- // # Run cmd to add user
+ fprintf (fd, "# Run cmd to add user\n");
+ /** TODO pick up return value, fail with a message if bad */
+ fprintf (fd, "ExecWait \"net user %s %s /add /active:yes\"\n\n",
+ loginfo->username, loginfo->userpassword);
+ /** TODO Display message that everything seems to be fine */
+
fprintf (fd, "# Default (install) section end\n");
fprintf (fd, "sectionEnd\n\n");
@@ -123,8 +139,14 @@
fprintf (fd, "#\n# Uninstaller section.\n#\n");
fprintf (fd, "section \"Uninstall\"\n\n");
- // # Run cmd to remove user
+ fprintf (fd, "# Run cmd to remove user\n");
+ /** TODO pick up return value, fail with a message if bad */
+ fprintf (fd, "ExecWait \"net user %s /delete\"\n\n",
+ loginfo->username);
+ /** @TODO Uninstaller should remove itself */
+ fprintf (fd, "# Unistaller should remove itself (from desktop/installdir)\n\n");
+
fprintf (fd, "# Uninstaller section end\n");
fprintf (fd, "sectionEnd\n\n");
@@ -137,9 +159,41 @@
* @brief Execute makensis to create an executable installer from a .nsi file.
*/
static gboolean
-execute_makensis (gchar* filename)
+execute_makensis (const gchar* filename)
{
- return FALSE;
+ gchar** cmd;
+ gint exit_status;
+
+ cmd = (gchar **) g_malloc (3 * sizeof (gchar *));
+
+ cmd[0] = g_strdup ("makensis");
+ cmd[1] = g_strdup (filename);
+ cmd[2] = NULL;
+ printf ("--- executing makensis.\n");
+ if (g_spawn_sync (".",
+ cmd,
+ NULL, // env
+ G_SPAWN_SEARCH_PATH,
+ NULL, // setup func
+ NULL,
+ NULL,
+ NULL,
+ &exit_status,
+ NULL ) == FALSE
+ || exit_status != 0)
+ {
+ show_error(_("Error (%d) creating the rpm with.\n"
+ "For further information consult your shell."), exit_status, cmd);
+ exit_status = -1;
+ }
+
+ g_free (cmd[0]);
+ g_free (cmd[1]);
+ g_free (cmd[2]);
+ g_free (cmd);
+
+ printf ("--- makensis finished happily.\n");
+ return (exit_status == 0);
}
/**
@@ -152,10 +206,21 @@
gboolean
openvas_lsc_user_makensis (openvas_ssh_login* loginfo, const gchar* to_filename)
{
- gchar* tmpdir = create_tmp_dir ();
+ gboolean success = FALSE;
+ /*
+ // Check if makensis is found in path
+ gchar* makensis_path = g_find_program_in_path ("makensis");
+
+ if (makensis_path == NULL)
+ {
+ show_error ("makensis not found.");
+ return FALSE;
+ }
+ */
+ gchar* tmpdir = create_tmp_dir ();
gchar* nsifile = g_build_filename (tmpdir, "lsc_user_installer.nsi", NULL);
create_nsi_file (nsifile, loginfo, to_filename);
- execute_makensis (nsifile);
- //del tmp dir
- return FALSE;
+ success = execute_makensis (nsifile);
+ /** @TODO delete tmp dir and contents */
+ return success;
}
More information about the Openvas-commits
mailing list