From 9dd454af184826f9e296c00f4dd0c38e93ed9ec3 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Sun, 22 Jul 2007 15:36:12 +0000 Subject: [PATCH] Using uname() instead of gethostname() to supporting truncating --- src/conf.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/conf.c b/src/conf.c index 2457dad..89b979a 100644 --- a/src/conf.c +++ b/src/conf.c @@ -15,7 +15,7 @@ * Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include #include #include #include "conf.h" @@ -124,12 +124,18 @@ static int pusb_conf_parse_device(t_pusb_options *opts, xmlDoc *doc) int pusb_conf_init(t_pusb_options *opts) { + struct utsname u; + memset(opts, 0x00, sizeof(*opts)); - if (gethostname(opts->hostname, sizeof(opts->hostname)) == -1) + if (uname(&u) == -1) { - log_error("gethostname: %s\n", strerror(errno)); + log_error("uname: %s\n", strerror(errno)); return (0); } + strncpy(opts->hostname, u.nodename, sizeof(opts->hostname)); + if (strlen(u.nodename) > sizeof(opts->hostname)) + log_info("Hostname \"%s\" is too long, truncating to \"%s\".\n", + u.nodename, opts->hostname); strcpy(opts->system_pad_directory, ".pamusb"); strcpy(opts->device_pad_directory, ".pamusb"); opts->probe_timeout = 10;