~ubuntu-branches/ubuntu/utopic/curl/utopic-updates

« back to all changes in this revision

Viewing changes to lib/curl_gethostname.c

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-05-22 14:53:29 UTC
  • mfrom: (3.4.28 sid)
  • Revision ID: package-import@ubuntu.com-20120522145329-hbf1n3zr7qh08qab
Tags: 7.25.0-1ubuntu1
* Merge from Debian testing (LP: #1003049).  Remaining changes:
  - Drop dependencies not in main:
    + Build-Depends: Drop stunnel4 and libssh2-1-dev.
    + Drop libssh2-1-dev from libcurl4-openssl-dev's Depends.
  - Add new libcurl3-udeb package.
  - Add new curl-udeb package.
  - Also closes (LP: #855291)
* debian/patches/CVE-2012-0036.patch: Dropped. CVE resolved upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 * Curl_gethostname() is a wrapper around gethostname() which allows
33
33
 * overriding the host name that the function would normally return.
34
34
 * This capability is used by the test suite to verify exact matching
35
 
 * of NTLM authentication, which exercises libcurl's MD4 and DES code.
 
35
 * of NTLM authentication, which exercises libcurl's MD4 and DES code
 
36
 * as well as by the SMTP module when a hostname is not provided.
36
37
 *
37
38
 * For libcurl debug enabled builds host name overriding takes place
38
39
 * when environment variable CURL_GETHOSTNAME is set, using the value
39
40
 * held by the variable to override returned host name.
40
41
 *
 
42
 * Note: The function always returns the un-qualified hostname rather
 
43
 * than being provider dependent.
 
44
 *
41
45
 * For libcurl shared library release builds the test suite preloads
42
46
 * another shared library named libhostname using the LD_PRELOAD
43
47
 * mechanism which intercepts, and might override, the gethostname()
58
62
  return -1;
59
63
 
60
64
#else
 
65
  int err;
 
66
  char* dot;
61
67
 
62
68
#ifdef DEBUGBUILD
63
69
 
65
71
  const char *force_hostname = getenv("CURL_GETHOSTNAME");
66
72
  if(force_hostname) {
67
73
    strncpy(name, force_hostname, namelen);
68
 
    name[namelen-1] = '\0';
69
 
    return 0;
 
74
    err = 0;
 
75
  }
 
76
  else {
 
77
    name[0] = '\0';
 
78
    err = gethostname(name, namelen);
70
79
  }
71
80
 
72
 
#endif /* DEBUGBUILD */
 
81
#else /* DEBUGBUILD */
73
82
 
74
83
  /* The call to system's gethostname() might get intercepted by the
75
84
     libhostname library when libcurl is built as a non-debug shared
76
85
     library when running the test suite. */
77
 
  return gethostname(name, namelen);
78
 
 
 
86
  name[0] = '\0';
 
87
  err = gethostname(name, namelen);
 
88
 
 
89
#endif
 
90
 
 
91
  name[namelen - 1] = '\0';
 
92
 
 
93
  if(err)
 
94
    return err;
 
95
 
 
96
  /* Truncate domain, leave only machine name */
 
97
  dot = strchr(name, '.');
 
98
  if(dot)
 
99
    *dot = '\0';
 
100
 
 
101
  return 0;
79
102
#endif
80
103
 
81
104
}