summaryrefslogtreecommitdiff
path: root/libbb/safe_gethostname.c
diff options
context:
space:
mode:
authorDenis Vlasenko2008-06-30 13:30:21 +0000
committerDenis Vlasenko2008-06-30 13:30:21 +0000
commitc94d3564c2b0584804fd4bab0a03f9160aa39720 (patch)
treec77f63cc4f0d406ebd0faee44cd508fa09482a0a /libbb/safe_gethostname.c
parentbc2fd372272e4917909358473c07e19c1ce450cc (diff)
downloadbusybox-c94d3564c2b0584804fd4bab0a03f9160aa39720.zip
busybox-c94d3564c2b0584804fd4bab0a03f9160aa39720.tar.gz
sendmail: from Vladimir:
Here comes the third part of compatibility patch for sendmail. * Introduced new safe_getdomainname() -- will it be useful? * Fixed SEGV if sender address is missed. Should snoop for sender address in mail headers? * More compat: use HOSTNAME instead of HOST when no server is explicitly specified. * crond: fixed mail recipient address. function old new delta safe_getdomainname - 56 +56 sendgetmail_main 1937 1946 +9 grep_file 846 850 +4 crond_main 1423 1425 +2 xstrtoull_range_sfx 295 296 +1 utoa_to_buf 110 108 -2 passwd_main 1053 1049 -4 sv_main 1234 1228 -6 parse_expr 841 833 -8 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 4/4 up/down: 72/-20) Total: 52 bytes
Diffstat (limited to 'libbb/safe_gethostname.c')
-rw-r--r--libbb/safe_gethostname.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/libbb/safe_gethostname.c b/libbb/safe_gethostname.c
index 1f8b2a8..7407fb7 100644
--- a/libbb/safe_gethostname.c
+++ b/libbb/safe_gethostname.c
@@ -48,6 +48,19 @@ char* FAST_FUNC safe_gethostname(void)
/* Uname can fail only if you pass a bad pointer to it. */
uname(&uts);
+ return xstrndup(!uts.nodename[0] ? "?" : uts.nodename, sizeof(uts.nodename));
+}
- return xstrndup(!*(uts.nodename) ? "?" : uts.nodename, sizeof(uts.nodename));
+/*
+ * On success return the current malloced and NUL terminated domainname.
+ * On error return malloced and NUL terminated string "?".
+ * This is an illegal first character for a domainname.
+ * The returned malloced string must be freed by the caller.
+ */
+char* FAST_FUNC safe_getdomainname(void)
+{
+ struct utsname uts;
+
+ uname(&uts);
+ return xstrndup(!uts.domainname[0] ? "?" : uts.domainname, sizeof(uts.domainname));
}