1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
#
# Copyright 2013 Nexenta Systems, Inc. All rights reserved.
#
PROG= bind-helper
SRCS= bind-helper.c
include ../../Makefile.cmd
include ../Makefile.smbsrv.defs
LDLIBS += -lsocket -lnsl
ROOTLIBSMBSRVDIR = $(ROOTLIB)/smbsrv
ROOTLIBSMBSRVPROG = $(PROG:%=$(ROOTLIBSMBSRVDIR)/%)
.KEEP_STATE:
all: $(PROG)
clean:
$(RM) $(OBJS)
lint: lint_SRCS
$(PROG): $(OBJS)
$(LINK.c) -o $@ $(OBJS) $(LDLIBS)
$(POST_PROCESS)
include ../../Makefile.targ
$(ROOTLIBSMBSRVDIR)/%: %
$(INS.file)
install: all .WAIT $(ROOTLIBSMBSRVPROG)
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/
/*
* Copyright 2013 Nexenta Systems, Inc. All rights reserved.
*/
/*
* This program is installed with an RBAC exec_attr
* that allows it to bind a reserved address.
* (Or just make it setuid root.)
*
* To grant privileges to the program using RBAC,
* add the following line to /etc/security/exec_attr
* Forced Privilege:solaris:cmd:::\
* /usr/lib/smbsrv/bind-helper:\
* privs=net_privaddr,sys_smb\
*
* Args: family address port
* Does a bind on fileno(stdin)
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int
main(int argc, char **argv)
{
struct sockaddr sa;
/* LINTED E_BAD_PTR_CAST_ALIGN */
struct sockaddr_in *sin = (struct sockaddr_in *)&sa;
/* LINTED E_BAD_PTR_CAST_ALIGN */
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&sa;
int rc, err = 0;
if (argc < 4) {
(void) fprintf(stderr, "usage: %s family address port\n",
argv[0]);
exit(1);
}
(void) memset(&sa, 0, sizeof (sa));
sa.sa_family = atoi(argv[1]);
switch (sa.sa_family) {
case AF_INET:
rc = inet_pton(AF_INET, argv[2], &sin->sin_addr);
sin->sin_port = htons(atoi(argv[3]));
break;
case AF_INET6:
rc = inet_pton(AF_INET6, argv[2], &sin6->sin6_addr);
sin6->sin6_port = htons(atoi(argv[3]));
break;
default:
rc = 0;
break;
}
if (rc > 0)
err = 0;
else if (rc == 0)
err = EINVAL;
else if (rc < 0)
err = errno;
if (err != 0) {
(void) fprintf(stderr, "%s: bad proto addr %s %s %s\n",
argv[0], argv[1], argv[2], argv[3]);
exit(1);
}
if (bind(0, &sa, sizeof (sa)) < 0) {
err = errno;
(void) fprintf(stderr, "%s: bind: %s\n",
argv[0], strerror(err));
exit(2);
}
exit(0);
}
|