/** * Collect user information. */ static void entropy_collect_user(SHA1Context *ctx) { const char *str[3]; str[0] = gethomedir(); #if GLIB_CHECK_VERSION(2,6,0) /* * These functions cannot be used with an unpatched GLib 1.2 on some * systems as they trigger a bug in GLib causing a crash. On Darwin * there's still a problem before GLib 2.6 due to a bug in Darwin though. */ str[1] = g_get_user_name(); str[2] = g_get_real_name(); entropy_array_string_collect(ctx, str, G_N_ELEMENTS(str)); #else { char user[UINT32_DEC_BUFLEN]; char real[UINT32_DEC_BUFLEN]; uint32_to_string_buf(entropy_rand31(), user, sizeof user); uint32_to_string_buf(entropy_rand31(), real, sizeof real); str[1] = user; str[2] = real; entropy_array_string_collect(ctx, str, G_N_ELEMENTS(str)); } #endif /* GLib >= 2.0 */ }
/** * Prints the ``port'' followed by host address ``ha'' to ``dst''. The string * written to ``dst'' is always NUL-terminated unless ``size'' is zero. If * ``size'' is too small, the string will be truncated. * * @param dst the destination buffer; may be NULL iff ``size'' is zero. * @param port the port number. * @param ha the host address. * @param size the size of ``dst'' in bytes. * * @return The length of the resulting string assuming ``size'' is sufficient. */ size_t host_port_addr_to_string_buf(uint16 port, const host_addr_t ha, char *dst, size_t size) { char port_buf[UINT32_DEC_BUFLEN]; char host_buf[HOST_ADDR_BUFLEN]; size_t n; uint32_to_string_buf(port, port_buf, sizeof port_buf); host_addr_to_string_buf(ha, host_buf, sizeof host_buf); switch (host_addr_net(ha)) { case NET_TYPE_IPV6: n = concat_strings(dst, size, port_buf, ":[", host_buf, "]", (void *) 0); break; case NET_TYPE_IPV4: n = concat_strings(dst, size, port_buf, ":", host_buf, (void *) 0); break; default: n = g_strlcpy(dst, host_buf, size); } return n; }
const char * host_port_to_string(const char *hostname, host_addr_t addr, uint16 port) { static char buf[MAX_HOSTLEN + 32]; if (hostname) { char port_buf[UINT32_DEC_BUFLEN]; uint32_to_string_buf(port, port_buf, sizeof port_buf); concat_strings(buf, sizeof buf, hostname, ":", port_buf, (void *) 0); } else { host_addr_port_to_string_buf(addr, port, buf, sizeof buf); } return buf; }
const char * host_port_to_string(const char *hostname, host_addr_t addr, uint16 port) { buf_t *b = buf_private(G_STRFUNC, MAX_HOSTLEN + HOST_ADDR_PORT_BUFLEN); char *p = buf_data(b); if (hostname != NULL) { char port_buf[UINT32_DEC_BUFLEN]; uint32_to_string_buf(port, port_buf, sizeof port_buf); concat_strings(p, buf_size(b), hostname, ":", port_buf, NULL_PTR); } else { host_addr_port_to_string_buf(addr, port, p, buf_size(b)); } return p; }
/** * Verifies "data" against "signature". * * @return TRUE if the signature matches. */ bool svn_release_notification_verify(uint32 revision, time_t date, const struct array *signature) { char rev[12], data[64]; struct array input; uint32_to_string_buf(revision, rev, sizeof rev); input.data = (void *) data; input.size = concat_strings(data, sizeof data, "r", rev, "@", uint32_to_string(date), (void *) 0); return verify_signature(svn_release_notify_certificate(), &input, signature); }