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 * This program is installed with an RBAC exec_attr
18 * that allows it to bind a reserved address.
19 * (Or just make it setuid root.)
21 * To grant privileges to the program using RBAC,
22 * add the following line to /etc/security/exec_attr
23 * Forced Privilege:solaris:cmd:::\
24 * /usr/lib/smbsrv/bind-helper:\
25 * privs=net_privaddr,sys_smb\
27 * Args: family address port
28 * Does a bind on fileno(stdin)
36 #include <sys/types.h>
37 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #include <arpa/inet.h>
42 main(int argc
, char **argv
)
45 /* LINTED E_BAD_PTR_CAST_ALIGN */
46 struct sockaddr_in
*sin
= (struct sockaddr_in
*)&sa
;
47 /* LINTED E_BAD_PTR_CAST_ALIGN */
48 struct sockaddr_in6
*sin6
= (struct sockaddr_in6
*)&sa
;
52 (void) fprintf(stderr
, "usage: %s family address port\n",
57 (void) memset(&sa
, 0, sizeof (sa
));
58 sa
.sa_family
= atoi(argv
[1]);
59 switch (sa
.sa_family
) {
61 rc
= inet_pton(AF_INET
, argv
[2], &sin
->sin_addr
);
62 sin
->sin_port
= htons(atoi(argv
[3]));
65 rc
= inet_pton(AF_INET6
, argv
[2], &sin6
->sin6_addr
);
66 sin6
->sin6_port
= htons(atoi(argv
[3]));
80 (void) fprintf(stderr
, "%s: bad proto addr %s %s %s\n",
81 argv
[0], argv
[1], argv
[2], argv
[3]);
85 if (bind(0, &sa
, sizeof (sa
)) < 0) {
87 (void) fprintf(stderr
, "%s: bind: %s\n",
88 argv
[0], strerror(err
));