[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r1338 - in GNUnet/src: conf include util util/win
From: |
durner |
Subject: |
[GNUnet-SVN] r1338 - in GNUnet/src: conf include util util/win |
Date: |
Sat, 9 Jul 2005 05:21:15 -0700 (PDT) |
Author: durner
Date: 2005-07-09 05:21:04 -0700 (Sat, 09 Jul 2005)
New Revision: 1338
Added:
GNUnet/src/util/osconfig.c
Modified:
GNUnet/src/conf/gnunet-setup.c
GNUnet/src/conf/wizard.c
GNUnet/src/conf/wizard_callbacks.c
GNUnet/src/conf/wizard_curs.c
GNUnet/src/conf/wizard_util.c
GNUnet/src/conf/wizard_util.h
GNUnet/src/include/gnunet_util.h
GNUnet/src/util/Makefile.am
GNUnet/src/util/win/win.cc
Log:
API cleanup
Modified: GNUnet/src/conf/gnunet-setup.c
===================================================================
--- GNUnet/src/conf/gnunet-setup.c 2005-07-09 12:05:47 UTC (rev 1337)
+++ GNUnet/src/conf/gnunet-setup.c 2005-07-09 12:21:04 UTC (rev 1338)
@@ -32,7 +32,7 @@
static void help() {
puts(_("USAGE: gnunet-setup MODULE\n\n"
"MODULE\n"
- " recreate\t\trecreate configuration files\n"
+ " recreate\trecreate configuration files\n"
" config\t\ttext-based configuration\n"
" menuconfig\ttext-based menu\n"
" gconfig\tGTK configuration\n"
@@ -82,7 +82,7 @@
#if HAVE_GTK
wizard_main(argc - 1, &argv[1]);
#else
- puts("basic-gtk is not available\n");
+ puts("wizard-gtk is not available\n");
#endif
}
else if (strncmp(argv[1], "gconfig", 7) == 0) {
Modified: GNUnet/src/conf/wizard.c
===================================================================
--- GNUnet/src/conf/wizard.c 2005-07-09 12:05:47 UTC (rev 1337)
+++ GNUnet/src/conf/wizard.c 2005-07-09 12:21:04 UTC (rev 1338)
@@ -94,7 +94,7 @@
if (sym)
{
nic_item_count = 0;
- wiz_enum_nics(insert_nic);
+ enumNetworkIfs(insert_nic);
if (!nic_item_count)
{
@@ -215,8 +215,8 @@
if (group_name)
gtk_entry_set_text(GTK_ENTRY(entGroup), group_name);
- gtk_widget_set_sensitive(entUser, wiz_useradd_capable());
- gtk_widget_set_sensitive(entGroup, group =
wiz_groupadd_capable());
+ gtk_widget_set_sensitive(entUser, isOSUserAddCapable());
+ gtk_widget_set_sensitive(entGroup, group =
isOSGroupAddCapable());
}
void load_step5()
@@ -253,7 +253,7 @@
sym_get_tristate_value(sym) != no);
}
- if (wiz_useradd_capable())
+ if (isOSUserAddCapable())
gtk_widget_set_sensitive(chkStart, TRUE);
if (doAutoStart)
Modified: GNUnet/src/conf/wizard_callbacks.c
===================================================================
--- GNUnet/src/conf/wizard_callbacks.c 2005-07-09 12:05:47 UTC (rev 1337)
+++ GNUnet/src/conf/wizard_callbacks.c 2005-07-09 12:21:04 UTC (rev 1338)
@@ -231,14 +231,14 @@
on_finish_clicked (GtkButton * button, gpointer user_data)
{
if (doAutoStart && user_name)
- if (!wiz_addServiceAccount(group_name, user_name)) {
+ if (!wiz_createGroupUser(group_name, user_name)) {
#ifndef MINGW
showErr(_("Unable to create user account:"),
STRERROR(errno));
#endif
return;
}
- if (!wiz_autostart(doAutoStart, user_name, group_name)) {
+ if (!wiz_autostartService(doAutoStart, user_name, group_name)) {
#ifndef MINGW
showErr(_("Unable to change startup process:"),
STRERROR(errno));
#endif
Modified: GNUnet/src/conf/wizard_curs.c
===================================================================
--- GNUnet/src/conf/wizard_curs.c 2005-07-09 12:05:47 UTC (rev 1337)
+++ GNUnet/src/conf/wizard_curs.c 2005-07-09 12:21:04 UTC (rev 1338)
@@ -100,7 +100,7 @@
dialog_clear();
- wiz_enum_nics(insert_nic_curs);
+ enumNetworkIfs(insert_nic_curs);
/* Network interface */
if (nic_item_count) {
@@ -406,7 +406,7 @@
dialog_clear();
/* Autostart */
- if (wiz_autostart_capable()) {
+ if (isOSAutostartCapable()) {
while(true) {
ret = dialog_yesno(_("GNUnet configuration"), _("Do you
want to launch "
"GNUnet as a system service?"
@@ -428,7 +428,7 @@
}
/* User */
- if (wiz_useradd_capable()) {
+ if (isOSUserAddCapable()) {
while(true) {
ret = dialog_inputbox(_("GNUnet configuration"),
_("Define the user owning the GNUnet
service.\n\n"
@@ -456,7 +456,7 @@
dialog_clear();
/* Group */
- if (wiz_groupadd_capable()) {
+ if (isOSGroupAddCapable()) {
while(true) {
ret = dialog_inputbox(_("GNUnet configuration"),
_("Define the group owning the GNUnet
service.\n\n"
@@ -507,10 +507,10 @@
/* Save config */
if (user_name && strlen(user_name) > 0)
- if (!wiz_addServiceAccount(group_name, user_name))
+ if (!isOSUserAddCapable(group_name, user_name))
showCursErr(_("Unable to create user account:"),
STRERROR(errno));
- if (!wiz_autostart(autostart, user_name, group_name))
+ if (!isOSAutostartCapable(autostart, user_name, group_name))
showCursErr(_("Unable to change startup process:"),
STRERROR(errno));
init_dialog();
Modified: GNUnet/src/conf/wizard_util.c
===================================================================
--- GNUnet/src/conf/wizard_util.c 2005-07-09 12:05:47 UTC (rev 1337)
+++ GNUnet/src/conf/wizard_util.c 2005-07-09 12:21:04 UTC (rev 1338)
@@ -30,64 +30,7 @@
#define LKC_DIRECT_LINK
#include "lkc.h"
-/**
- * @brief Enumerate all network interfaces
- * @param callback the callback function
- */
-void wiz_enum_nics(void (*callback) (char *, int)) {
-#ifdef MINGW
- ListNICs(callback);
-#else
- char entry[11], *dst;
- FILE *f;
-
- if (system("ifconfig > /dev/null 2> /dev/null"))
- if (system("/sbin/ifconfig > /dev/null 2> /dev/null")
== 0)
- f = popen("/sbin/ifconfig 2> /dev/null", "r");
- else
- f = NULL;
- else
- f = popen("ifconfig 2> /dev/null", "r");
-
- if (!f)
- return;
-
- while(1)
- {
- int i = 0;
- int c = fgetc(f);
-
- if (c == EOF)
- break;
- dst = entry;
-
- /* Read interface name until the first space (or colon
under OS X) */
- while (c != EOF && c != '\n' &&
-#ifdef OSX
- c != ':'
-#else
- c != ' '
-#endif
- && i < 10)
- {
- *dst++ = c;
- i++;
- c = fgetc(f);
- }
- *dst = 0;
-
- if (entry[0])
- callback(entry, strcmp(entry, "eth0") == 0);
-
- while(c != '\n' && c != EOF)
- c = fgetc(f);
- }
-
- pclose(f);
-#endif
-}
-
/**
* @brief Determine whether a NIC makes a good default
*/
@@ -127,289 +70,78 @@
return suggestion;
}
-/**
- * @brief Checks if we can start GNUnet automatically
- * @return 1 if yes, 0 otherwise
- */
-int wiz_autostart_capable() {
-#ifdef WINDOWS
- return 1;
-#endif
-#ifdef LINUX
- if (ACCESS("/usr/sbin/update-rc.d", X_OK) == 0) {
- /* Debian */
- if (ACCESS("/etc/init.d/", W_OK) == 0)
- return 1;
- }
-
- return 0;
-#endif
-}
/**
* @brief Make GNUnet start automatically
* @param doAutoStart true to enable autostart, false to disable it
* @param username name of the user account to use
* @param groupname name of the group to use
+ * @return 1 on success, 0 on error
*/
-int wiz_autostart(int doAutoStart, char *username, char *groupname) {
-#ifdef WINDOWS
- if (doAutoStart)
- {
- if (IsWinNT())
- {
- char *err = NULL;
- DWORD dwErr = 0;
-
- if (username && !strlen(username))
- username = NULL;
-
- /* Install service */
- switch(InstallAsService(username))
- {
- case 0:
- case 1:
- break;
- case 2:
- err = winErrorStr(_("Can't open Service
Control Manager"),
- GetLastError());
- case 3:
- dwErr = GetLastError();
- if (dwErr != ERROR_SERVICE_EXISTS)
- {
- err = winErrorStr(_("Can't
create service"),
- GetLastError());
- }
- break;
- default:
- err = winErrorStr(_("Unknown error"),
- GetLastError());
- }
-
- /* Grant permissions to the GNUnet directory */
- if ((!err || dwErr == ERROR_SERVICE_EXISTS) && username)
- {
- char szHome[_MAX_PATH + 1];
-
- plibc_conv_to_win_path("/", szHome);
-
- if (!AddPathAccessRights(szHome, username,
GENERIC_ALL))
- {
- err = winErrorStr(_("Error changing the
permissions of the GNUnet directory"),
- GetLastError());
+int wiz_autostartService(int doAutoStart, char *username, char *groupname) {
+ char *err;
+ DWORD dwErr;
+ int ret = autostartService(doAutoStart, username, groupname);
+
+ if (ret ) {
+#ifdef MINGW
+ switch(ret) {
+ case 1:
+ err = winErrorStr(_("Can't open Service Control
Manager"),
+ GetLastError());
+ break;
+ case 2:
+ dwErr = GetLastError();
+ if (dwErr != ERROR_SERVICE_EXISTS) {
+ err = winErrorStr(_("Can't create
service"),
+ GetLastError());
}
- }
-
- if (err && dwErr != ERROR_SERVICE_EXISTS)
- {
- MessageBox(GetActiveWindow(), err, _("Error"),
MB_ICONSTOP | MB_OK);
- free(err);
- return 0;
- }
+ break;
+ case 3:
+ err = winErrorStr(_("Error changing the
permissions of the GNUnet directory"),
+ GetLastError());
+ break;
+ case 4:
+ err = _("Cannot write to the regisitry");
+ break;
+ case 5:
+ err = winErrorStr(_("Can't access the service"),
+ GetLastError());
+ case 6:
+ err = winErrorStr(_("Can't delete the service"),
+ GetLastError());
+ default:
+ err = winErrorStr(_("Unknown error"),
GetLastError());
}
- else
- {
- char szPath[_MAX_PATH + 1];
- plibc_conv_to_win_path("/bin/gnunetd.exe", szPath);
-
- if (RegSetValue(HKEY_LOCAL_MACHINE,
-
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", REG_SZ, szPath,
- strlen(szPath)) != ERROR_SUCCESS)
- {
- MessageBox(GetActiveWindow(), _("Cannot write to the
regisitry"),
- _("Error"), MB_ICONSTOP | MB_OK);
- }
- }
- }
- else
- {
- if (IsWinNT())
- {
- char *err = NULL;
-
- switch (UninstallService())
- {
- case 0:
- case 1:
- break;
- case 2:
- err = winErrorStr(_("Can't open Service
Control Manager"),
- GetLastError());
- return 0;
- case 3:
- err = winErrorStr(_("Can't access the
service"),
- GetLastError());
- return 0;
- case 4:
- err = winErrorStr(_("Can't delete the
service"),
- GetLastError());
- break;
- default:
- MessageBox(GetActiveWindow(),
_("Unknown error"), _("Error"),
- MB_ICONSTOP | MB_OK);
- }
-
- if (err)
- {
- MessageBox(GetActiveWindow(), err, _("Error"),
- MB_ICONSTOP | MB_OK);
- free(err);
- }
- }
- else
- {
- HKEY hKey;
-
- if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0,
KEY_SET_VALUE,
- &hKey) == ERROR_SUCCESS)
- {
- RegDeleteValue(hKey, "GNUnet");
- RegCloseKey(hKey);
- }
- }
- }
-#else
- /* Unix */
- if (ACCESS("/usr/sbin/update-rc.d", X_OK) == 0) {
- /* Debian */
- if (doAutoStart) {
- struct stat buf;
- if (STAT("/etc/init.d/gnunetd", &buf) == -1) {
- /* create init file */
- FILE *f = FOPEN("/etc/init.d/gnunetd", "w");
- if (! f)
- return 0;
-
- fputs("#! /bin/sh\n"
- "#\n"
- "#
Automatically created by gnunet-setup\n"
- "#\n"
- "\n"
-
"PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n"
-
"PIDFILE=/var/run/gnunetd/gnunetd.pid\n"
- "\n"
- "case
\"$1\" in\n"
- "
start)\n"
- "
echo -n \"Starting GNUnet: \"\n"
- "
gnunetd\n"
- "
echo \"gnunetd\"\n"
- "
;;\n"
- "
stop)\n"
- "
echo -n \"Stopping GNUnet: \"\n"
- "
kill `cat $PIDFILE`\n"
- "
echo \"gnunetd\"\n"
- "
;;\n"
- "
reload)\n"
- "
echo -n \"Reloading GNUnet: \"\n"
- "
kill -HUP `cat $PIDFILE`\n"
- "
echo \"gnunetd\"\n"
- "
;;\n"
- "
restart|force-reload)\n"
- "
echo \"Restarting GNUnet: gnunetd...\"\n"
- "
$0 stop\n"
- "
sleep 1\n"
- "
$0 start\n"
- "
;;\n"
- "
*)\n"
- "
echo \"Usage: /etc/init.d/gnunetd
{start|stop|reload|restart|force-reload}\" >&2\n"
- "
exit 1\n"
- "
;;\n"
- "\n"
- "esac\n"
- "exit 0\n", f);
- fclose(f);
- CHMOD("/etc/init.d/gnunetd", S_IRWXU |
S_IRGRP | S_IXGRP |
- S_IROTH | S_IXOTH);
- }
- errno = system("/usr/sbin/update-rc.d gnunetd
defaults");
- if (errno != 0)
- return 0;
- }
- else {
- if (UNLINK("/etc/init.d/gnunetd") != -1 || errno ==
ENOENT) {
- if (ACCESS("/usr/sbin/update-rc.d", X_OK) == 0)
{
- errno = system("/usr/sbin/update-rc.d
gnunetd remove");
- if (errno != 0) {
- errno = EPERM;
- return 0;
- }
- }
- else {
- errno = EPERM;
- return 0;
- }
- }
- else
- return 0;
- }
- }
- else
- return 0;
-
-#endif
- return 1;
-}
-/**
- * @brief Checks if we can add an user for the GNUnet service
- * @return 1 if yes, 0 otherwise
- * @todo support for useradd(8)
- */
-int wiz_useradd_capable(){
-#ifdef WINDOWS
- return IsWinNT();
+ MessageBox(GetActiveWindow(), err, _("Error"), MB_ICONSTOP |
MB_OK);
+ free(err);
#endif
-#ifdef LINUX
- if (ACCESS("/usr/sbin/adduser", X_OK) == 0)
- return 1;
- else
- /* TODO: useradd */
-#endif
- return 0;
-}
-/**
- * @brief Checks if we can add a group for the GNUnet service
- * @return 1 if yes, 0 otherwise
- * @todo support for groupadd(8)
- */
-int wiz_groupadd_capable() {
-#ifdef LINUX
- if (ACCESS("/usr/sbin/addgroup", X_OK) == 0) {
- return 1;
- }
- /* TODO: groupadd */
- else
-#endif
return 0;
+ }
+
+ return 1;
}
/**
* @brief Add a service account for GNUnet
* @param group the group of the new user
* @param name the name of the new user
- * @todo Check FreeBSD (adduser(8)), add support for useradd(8)
+ * @return 1 on success
*/
-int wiz_addServiceAccount(char *group_name, char *user_name) {
-
- if (!user_name || !strlen(user_name))
- return 1;
-
-#ifdef WINDOWS
- if (IsWinNT())
- {
- char *err = NULL;
+int wiz_createGroupUser(char *group_name, char *user_name) {
+ char *err;
+ int ret = createGroupUser(group_name, user_name);
- switch(CreateServiceAccount(user_name, "GNUnet service
account")) {
- case 0:
- ; /* OK */
- break;
+ if (ret) {
+#ifdef MINGW
+ switch(ret) {
case 1:
- MessageBox(0, _("This version of Windows does
not support "
- "multiple users."), _("Error"),
MB_ICONSTOP | MB_OK);
- return 0;
+ err = _("This version of Windows does not
support "
+ "multiple users.");
+ break;
case 2:
err = winErrorStr(_("Error creating user"),
GetLastError());
break;
@@ -421,47 +153,17 @@
break;
default:
err = winErrorStr(_("Unknown error while
creating a new user"), GetLastError());
- break;
}
-
- if (err)
- {
+
+ if (err) {
MessageBox(0, err, _("Error"), MB_ICONSTOP | MB_OK);
free(err);
-
- return 0;
}
- }
- else
- return 0;
-#else
- int haveGroup;
-
- if (ACCESS("/usr/sbin/adduser", X_OK) == 0) {
- /* Debian */
- /* TODO: FreeBSD?
http://www.freebsd.org/cgi/man.cgi?query=adduser&sektion=8 */
- char *cmd;
-
- haveGroup = group_name && strlen(group_name) > 0;
- cmd = MALLOC(haveGroup ? strlen(group_name) : 0 +
strlen(user_name) + 64);
-
- if (haveGroup) {
- sprintf(cmd, "/usr/sbin/addgroup --quiet --system %s",
group_name);
- system(cmd);
- }
-
- sprintf(cmd, "/usr/sbin/adduser --quiet --system %s %s "
- "--no-create-home %s", haveGroup ? "--ingroup" : "",
- haveGroup ? group_name : "", user_name);
- system(cmd);
-
- FREE(cmd);
- }
- /* TODO: useradd */
- else
- return 0;
#endif
+ return 0;
+ }
+
return 1;
}
Modified: GNUnet/src/conf/wizard_util.h
===================================================================
--- GNUnet/src/conf/wizard_util.h 2005-07-09 12:05:47 UTC (rev 1337)
+++ GNUnet/src/conf/wizard_util.h 2005-07-09 12:21:04 UTC (rev 1338)
@@ -29,13 +29,9 @@
#include "platform.h"
-int wiz_enum_nics(void (*callback) (char *, int));
int wiz_is_nic_default(const char *name, int suggestion);
-int wiz_autostart_capable();
-int wiz_autostart(int doAutoStart, char *username, char *groupname);
-int wiz_useradd_capable();
-int wiz_groupadd_capable();
-int wiz_addServiceAccount(char *group_name, char *user_name);
+int wiz_autostartService(int doAutoStart, char *username, char *groupname);
+int wiz_createGroupUser(char *group_name, char *user_name);
#endif //_WIZARD_UTIL_H_
Modified: GNUnet/src/include/gnunet_util.h
===================================================================
--- GNUnet/src/include/gnunet_util.h 2005-07-09 12:05:47 UTC (rev 1337)
+++ GNUnet/src/include/gnunet_util.h 2005-07-09 12:21:04 UTC (rev 1338)
@@ -2306,22 +2306,55 @@
/**
* Helper functions
*/
-#ifdef WINDOWS
-void EnumNICs(PMIB_IFTABLE *pIfTable, PMIB_IPADDRTABLE *pAddrTable);
-int ListNICs(void (*callback) (char *, int));
-char *winErrorStr(char *prefix, DWORD dwErr);
-int InstallAsService(char *username);
-int UninstallService(void);
-void _InitLsaString(PLSA_UNICODE_STRING LsaString, LPWSTR String);
-NTSTATUS _OpenPolicy(LPWSTR ServerName, DWORD DesiredAccess, PLSA_HANDLE
PolicyHandle);
-BOOL _GetAccountSid(LPTSTR SystemName, LPTSTR AccountName, PSID * Sid);
-NTSTATUS _SetPrivilegeOnAccount(LSA_HANDLE PolicyHandle, PSID AccountSid,
- LPWSTR PrivilegeName, BOOL bEnable);
-int CreateServiceAccount(char *pszName, char *pszDesc);
-#endif
+/**
+ * @brief Enumerate all network interfaces
+ * @param callback the callback function
+ */
+void enumNetworkIfs(void (*callback) (char *, int));
+/**
+ * @brief Checks if we can start GNUnet automatically
+ * @return 1 if yes, 0 otherwise
+ */
+int isOSAutostartCapable();
+/**
+ * @brief Make GNUnet start automatically
+ * @param doAutoStart true to enable autostart, false to disable it
+ * @param username name of the user account to use
+ * @param groupname name of the group to use
+ * @return 0 on success
+ */
+int autostartService(int doAutoStart, char *username, char *groupname);
+
+/**
+ * @brief Checks if we can add an user for the GNUnet service
+ * @return 1 if yes, 0 otherwise
+ * @todo support for useradd(8)
+ */
+int isOSUserAddCapable();
+
+/**
+ * @brief Checks if we can add a group for the GNUnet service
+ * @return 1 if yes, 0 otherwise
+ * @todo support for groupadd(8)
+ */
+int isOSGroupAddCapable();
+
+/**
+ * @brief Add a service account for GNUnet
+ * @param group the group of the new user
+ * @param name the name of the new user
+ * @return 0 on success
+ */
+int createGroupUser(char *group_name, char *user_name);
+
+/**
+ * @brief Format a Windows specific error code
+ */
+char *winErrorStr(char *prefix, int dwErr);
+
/**
* Checks if gnunetd is running
*
Modified: GNUnet/src/util/Makefile.am
===================================================================
--- GNUnet/src/util/Makefile.am 2005-07-09 12:05:47 UTC (rev 1337)
+++ GNUnet/src/util/Makefile.am 2005-07-09 12:21:04 UTC (rev 1338)
@@ -71,6 +71,7 @@
locking_gcrypt.c \
locking_gcrypt.h \
logging.c \
+ osconfig.c \
printhelp.c \
port.c \
random.c \
Added: GNUnet/src/util/osconfig.c
===================================================================
--- GNUnet/src/util/osconfig.c 2005-07-09 12:05:47 UTC (rev 1337)
+++ GNUnet/src/util/osconfig.c 2005-07-09 12:21:04 UTC (rev 1338)
@@ -0,0 +1,390 @@
+/*
+ This file is part of GNUnet.
+ (C) 2001, 2002, 2003, 2004, 2005 Christian Grothoff (and other
contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 2, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+/**
+ * @file util/osconfig.c
+ * @brief functions to read or change the OS configuration
+ * @author Nils Durner
+ */
+#include "platform.h"
+#include "gnunet_util.h"
+
+/**
+ * @brief Enumerate all network interfaces
+ * @param callback the callback function
+ */
+void enumNetworkIfs(void (*callback) (char *, int)) {
+#ifdef MINGW
+ ListNICs(callback);
+#else
+ char entry[11], *dst;
+ FILE *f;
+
+ if (system("ifconfig > /dev/null 2> /dev/null"))
+ if (system("/sbin/ifconfig > /dev/null 2> /dev/null")
== 0)
+ f = popen("/sbin/ifconfig 2> /dev/null", "r");
+ else
+ f = NULL;
+ else
+ f = popen("ifconfig 2> /dev/null", "r");
+
+ if (!f)
+ return;
+
+ while(1)
+ {
+ int i = 0;
+ int c = fgetc(f);
+
+ if (c == EOF)
+ break;
+
+ dst = entry;
+
+ /* Read interface name until the first space (or colon
under OS X) */
+ while (c != EOF && c != '\n' &&
+#ifdef OSX
+ c != ':'
+#else
+ c != ' '
+#endif
+ && i < 10)
+ {
+ *dst++ = c;
+ i++;
+ c = fgetc(f);
+ }
+ *dst = 0;
+
+ if (entry[0])
+ callback(entry, strcmp(entry, "eth0") == 0);
+
+ while(c != '\n' && c != EOF)
+ c = fgetc(f);
+ }
+
+ pclose(f);
+#endif
+}
+
+/**
+ * @brief Checks if we can start GNUnet automatically
+ * @return 1 if yes, 0 otherwise
+ */
+int isOSAutostartCapable() {
+#ifdef WINDOWS
+ return 1;
+#endif
+#ifdef LINUX
+ if (ACCESS("/usr/sbin/update-rc.d", X_OK) == 0) {
+ /* Debian */
+ if (ACCESS("/etc/init.d/", W_OK) == 0)
+ return 1;
+ }
+
+ return 0;
+#endif
+}
+
+/**
+ * @brief Make GNUnet start automatically
+ * @param doAutoStart true to enable autostart, false to disable it
+ * @param username name of the user account to use
+ * @param groupname name of the group to use
+ * @return 0 on success
+ */
+int autostartService(int doAutoStart, char *username, char *groupname) {
+#ifdef WINDOWS
+ if (doAutoStart)
+ {
+ if (IsWinNT())
+ {
+ char *err = NULL;
+ DWORD dwErr = 0;
+
+ if (username && !strlen(username))
+ username = NULL;
+
+ /* Install service */
+ switch(InstallAsService(username))
+ {
+ case 0:
+ case 1:
+ break;
+ case 2:
+ if (GetLastError() !=
ERROR_SERVICE_EXISTS)
+ return 1;
+ case 3:
+ return 2;
+ default:
+ return -1;
+ }
+
+ /* Grant permissions to the GNUnet directory */
+ if ((!err || dwErr == ERROR_SERVICE_EXISTS) && username)
+ {
+ char szHome[_MAX_PATH + 1];
+
+ plibc_conv_to_win_path("/", szHome);
+
+ if (!AddPathAccessRights(szHome, username,
GENERIC_ALL))
+ return 3;
+ }
+ }
+ else
+ {
+ char szPath[_MAX_PATH + 1];
+ plibc_conv_to_win_path("/bin/gnunetd.exe", szPath);
+
+ if (RegSetValue(HKEY_LOCAL_MACHINE,
+
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", REG_SZ, szPath,
+ strlen(szPath)) != ERROR_SUCCESS)
+ {
+ return 4;
+ }
+ }
+ }
+ else
+ {
+ if (IsWinNT())
+ {
+ char *err = NULL;
+
+ switch (UninstallService())
+ {
+ case 0:
+ case 1:
+ break;
+ case 2:
+ return 1;
+ case 3:
+ return 5;
+ case 4:
+ return 6;
+ default:
+ return -1;
+ }
+ }
+ else
+ {
+ HKEY hKey;
+
+ if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0,
KEY_SET_VALUE,
+ &hKey) == ERROR_SUCCESS)
+ {
+ RegDeleteValue(hKey, "GNUnet");
+
+ RegCloseKey(hKey);
+ }
+ }
+ }
+#else
+ /* Unix */
+ if (ACCESS("/usr/sbin/update-rc.d", X_OK) == 0) {
+ /* Debian */
+ if (doAutoStart) {
+ struct stat buf;
+ if (STAT("/etc/init.d/gnunetd", &buf) == -1) {
+ /* create init file */
+ FILE *f = FOPEN("/etc/init.d/gnunetd", "w");
+ if (! f)
+ return 1;
+
+ fputs("#! /bin/sh\n"
+ "#\n"
+ "#
Automatically created by gnunet-setup\n"
+ "#\n"
+ "\n"
+
"PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n"
+
"PIDFILE=/var/run/gnunetd/gnunetd.pid\n"
+ "\n"
+ "case
\"$1\" in\n"
+ "
start)\n"
+ "
echo -n \"Starting GNUnet: \"\n"
+ "
gnunetd\n"
+ "
echo \"gnunetd\"\n"
+ "
;;\n"
+ "
stop)\n"
+ "
echo -n \"Stopping GNUnet: \"\n"
+ "
kill `cat $PIDFILE`\n"
+ "
echo \"gnunetd\"\n"
+ "
;;\n"
+ "
reload)\n"
+ "
echo -n \"Reloading GNUnet: \"\n"
+ "
kill -HUP `cat $PIDFILE`\n"
+ "
echo \"gnunetd\"\n"
+ "
;;\n"
+ "
restart|force-reload)\n"
+ "
echo \"Restarting GNUnet: gnunetd...\"\n"
+ "
$0 stop\n"
+ "
sleep 1\n"
+ "
$0 start\n"
+ "
;;\n"
+ "
*)\n"
+ "
echo \"Usage: /etc/init.d/gnunetd
{start|stop|reload|restart|force-reload}\" >&2\n"
+ "
exit 1\n"
+ "
;;\n"
+ "\n"
+ "esac\n"
+ "exit 0\n", f);
+ fclose(f);
+ CHMOD("/etc/init.d/gnunetd", S_IRWXU |
S_IRGRP | S_IXGRP |
+ S_IROTH | S_IXOTH);
+ }
+ errno = system("/usr/sbin/update-rc.d gnunetd
defaults");
+ if (errno != 0)
+ return 1;
+ }
+ else {
+ if (UNLINK("/etc/init.d/gnunetd") != -1 || errno ==
ENOENT) {
+ if (ACCESS("/usr/sbin/update-rc.d", X_OK) == 0)
{
+ errno = system("/usr/sbin/update-rc.d
gnunetd remove");
+ if (errno != 0) {
+ errno = EPERM;
+ return 1;
+ }
+ }
+ else {
+ errno = EPERM;
+ return 1;
+ }
+ }
+ else
+ return 1;
+ }
+ }
+ else
+ return 1;
+
+#endif
+ return 0;
+}
+
+/**
+ * @brief Checks if we can add an user for the GNUnet service
+ * @return 1 if yes, 0 otherwise
+ * @todo support for useradd(8)
+ */
+int isOSUserAddCapable(){
+#ifdef WINDOWS
+ return IsWinNT();
+#endif
+#ifdef LINUX
+ if (ACCESS("/usr/sbin/adduser", X_OK) == 0)
+ return 1;
+ else
+ /* TODO: useradd */
+#endif
+ return 0;
+}
+
+/**
+ * @brief Checks if we can add a group for the GNUnet service
+ * @return 1 if yes, 0 otherwise
+ * @todo support for groupadd(8)
+ */
+int isOSGroupAddCapable() {
+#ifdef LINUX
+ if (ACCESS("/usr/sbin/addgroup", X_OK) == 0) {
+ return 1;
+ }
+ /* TODO: groupadd */
+ else
+#endif
+ return 0;
+}
+
+/**
+ * @brief Add a service account for GNUnet
+ * @param group the group of the new user
+ * @param name the name of the new user
+ * @return 0 on success
+ */
+int createGroupUser(char *group_name, char *user_name) {
+
+ if (!user_name || !strlen(user_name))
+ return 0;
+
+#ifdef WINDOWS
+ if (IsWinNT())
+ {
+ return CreateServiceAccount(user_name, "GNUnet service
account");
+ }
+#else
+ int haveGroup;
+
+ if (ACCESS("/usr/sbin/adduser", X_OK) == 0) {
+ /* Debian */
+ /* TODO: FreeBSD?
http://www.freebsd.org/cgi/man.cgi?query=adduser&sektion=8 */
+ char *cmd;
+
+ haveGroup = group_name && strlen(group_name) > 0;
+ cmd = MALLOC(haveGroup ? strlen(group_name) : 0 +
strlen(user_name) + 64);
+
+ if (haveGroup) {
+ sprintf(cmd, "/usr/sbin/addgroup --quiet --system %s",
group_name);
+ system(cmd);
+ }
+
+ sprintf(cmd, "/usr/sbin/adduser --quiet --system %s %s "
+ "--no-create-home %s", haveGroup ? "--ingroup" : "",
+ haveGroup ? group_name : "", user_name);
+ system(cmd);
+
+ FREE(cmd);
+ }
+ /* TODO: useradd */
+ else
+ return 1;
+#endif
+
+ return 0;
+}
+
+char *winErrorStr(char *prefix, int dwErr)
+{
+#ifdef WINDOWS
+ char *err, *ret;
+ int mem;
+
+ if (! FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
+ NULL, (DWORD) dwErr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &err,
+ 0, NULL ))
+ {
+ err = "";
+ }
+
+ mem = strlen(err) + strlen(prefix) + 20;
+ ret = (char *) malloc(mem);
+
+ snprintf(ret, mem, "%s: %s (#%u)", prefix, err, dwErr);
+
+ LocalFree(err);
+
+ return ret;
+#else
+ return NULL;
+#endif
+}
+
+
+/* end of osconfig.c */
Modified: GNUnet/src/util/win/win.cc
===================================================================
--- GNUnet/src/util/win/win.cc 2005-07-09 12:05:47 UTC (rev 1337)
+++ GNUnet/src/util/win/win.cc 2005-07-09 12:21:04 UTC (rev 1338)
@@ -777,28 +777,6 @@
return fResult;
}
-char *winErrorStr(char *prefix, DWORD dwErr)
-{
- char *err, *ret;
- int mem;
-
- if (! FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
- NULL, dwErr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &err,
- 0, NULL ))
- {
- err = "";
- }
-
- mem = strlen(err) + strlen(prefix) + 20;
- ret = (char *) malloc(mem);
-
- snprintf(ret, mem, "%s: %s (#%u)", prefix, err, dwErr);
-
- LocalFree(err);
-
- return ret;
-}
-
} /* extern "C" */
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r1338 - in GNUnet/src: conf include util util/win,
durner <=