2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
17 * fork/exec a privileged helper to do the bind.
24 #include <sys/types.h>
26 #include <sys/socket.h>
28 #include <netinet/in.h>
29 #include <arpa/inet.h>
32 ksocket_bind_helper(int fd
, struct sockaddr
*addr
, uint_t addrlen
)
36 char addrstr
[INET6_ADDRSTRLEN
];
39 /* LINTED E_BAD_PTR_CAST_ALIGN */
40 struct sockaddr_in
*sin
= (struct sockaddr_in
*)addr
;
41 /* LINTED E_BAD_PTR_CAST_ALIGN */
42 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)addr
;
44 _NOTE(ARGUNUSED(addrlen
));
46 (void) snprintf(familystr
, sizeof (familystr
), "%d", addr
->sa_family
);
47 switch (addr
->sa_family
) {
49 (void) snprintf(portstr
, sizeof (portstr
), "%d",
50 ntohs(sin
->sin_port
));
51 p
= inet_ntop(AF_INET
, &sin
->sin_addr
,
52 addrstr
, sizeof (addrstr
));
55 (void) snprintf(portstr
, sizeof (portstr
), "%d",
56 ntohs(sin6
->sin6_port
));
57 p
= inet_ntop(AF_INET6
, &sin6
->sin6_addr
,
58 addrstr
, sizeof (addrstr
));
66 (void) fprintf(stdout
, "ksocket_bind_helper, inet_ntop %s\n",
71 (void) fprintf(stdout
, "ksocket_bind_helper, "
72 "family=%s addr=%s port=%s\n",
73 familystr
, addrstr
, portstr
);
75 argv
[0] = "/usr/bin/pfexec";
76 argv
[1] = "/usr/lib/smbsrv/bind-helper";
90 (void) execv(argv
[0], argv
);
95 err
= waitpid(pid
, &stat
, 0);
101 if (WIFEXITED(stat
)) {
102 err
= WEXITSTATUS(stat
);
105 (void) fprintf(stderr
, "helper exit %d\n", err
);