예제 #1
0
static int
spoolss_getservername(char *name, size_t namelen)
{
	char		hostname[MAXHOSTNAMELEN];
	char		ipstr[INET6_ADDRSTRLEN];
	smb_inaddr_t	ipaddr;
	struct hostent	*h;
	const char	*p;
	int		error;

	if (smb_gethostname(hostname, MAXHOSTNAMELEN, 0) != 0) {
		smb_tracef("spoolss_s_GetPrinter: gethostname failed");
		return (-1);
	}

	if ((h = smb_gethostbyname(hostname, &error)) == NULL) {
		smb_tracef("spoolss_s_GetPrinter: gethostbyname failed: %d",
		    error);
		return (-1);
	}

	bcopy(h->h_addr, &ipaddr, h->h_length);
	ipaddr.a_family = h->h_addrtype;
	freehostent(h);

	p = smb_inet_ntop(&ipaddr, ipstr, SMB_IPSTRLEN(ipaddr.a_family));
	if (p == NULL) {
		smb_tracef("spoolss_s_GetPrinter: inet_ntop failed");
		return (-1);
	}

	(void) snprintf(name, namelen, "\\\\%s", ipstr);
	return (0);
}
예제 #2
0
/*
 * Get information about the Domain Controller in the joined resource domain.
 *
 * Returns NT status codes.
 */
uint32_t
smb_get_dcinfo(char *namebuf, uint32_t namebuflen, smb_inaddr_t *ipaddr)
{
    smb_string_t	dcname;
    struct hostent	*h;
    int		rc;

    assert((namebuf != NULL) && (namebuflen != 0));
    *namebuf = '\0';
    bzero(&dcname, sizeof (smb_string_t));

    rc = smb_door_call(SMB_DR_GET_DCINFO, NULL, NULL,
                       &dcname, smb_string_xdr);

    if (rc != 0) {
        syslog(LOG_DEBUG, "smb_get_dcinfo: %m");
        if (dcname.buf)
            xdr_free(smb_string_xdr, (char *)&dcname);
        return (NT_STATUS_INTERNAL_ERROR);
    }

    if (dcname.buf) {
        (void) strlcpy(namebuf, dcname.buf, namebuflen);

        if ((h = smb_gethostbyname(dcname.buf, &rc)) == NULL) {
            bzero(ipaddr, sizeof (smb_inaddr_t));
        } else {
            (void) memcpy(ipaddr, h->h_addr, h->h_length);
            ipaddr->a_family = h->h_addrtype;
            freehostent(h);
        }
        xdr_free(smb_string_xdr, (char *)&dcname);
    }

    return (NT_STATUS_SUCCESS);
}