]> git.saurik.com Git - apple/ipsec.git/blame - ipsec-tools/racoon/isakmp_unity.c
ipsec-34.tar.gz
[apple/ipsec.git] / ipsec-tools / racoon / isakmp_unity.c
CommitLineData
52b7d2ce
A
1/* $Id: isakmp_unity.c,v 1.5.4.1 2005/05/10 09:45:46 manubsd Exp $ */
2
3/*
4 * Copyright (C) 2004 Emmanuel Dreyfus
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include "config.h"
33
34#include <sys/types.h>
35#include <sys/param.h>
36#include <sys/socket.h>
37#include <sys/queue.h>
38
39#include <netinet/in.h>
40#include <arpa/inet.h>
41
42#include <stdlib.h>
43#include <stdio.h>
44#include <fcntl.h>
45#include <string.h>
46#include <errno.h>
47#if TIME_WITH_SYS_TIME
48# include <sys/time.h>
49# include <time.h>
50#else
51# if HAVE_SYS_TIME_H
52# include <sys/time.h>
53# else
54# include <time.h>
55# endif
56#endif
57#include <netdb.h>
58#ifdef HAVE_UNISTD_H
59#include <unistd.h>
60#endif
61#include <ctype.h>
62
63#include "var.h"
64#include "misc.h"
65#include "vmbuf.h"
66#include "plog.h"
67#include "sockmisc.h"
68#include "schedule.h"
69#include "debug.h"
70
71#include "isakmp_var.h"
72#include "isakmp.h"
73#include "handler.h"
74#include "isakmp_xauth.h"
75#include "isakmp_unity.h"
76#include "isakmp_cfg.h"
77#include "strnames.h"
78
79vchar_t *
80isakmp_unity_req(iph1, attr)
81 struct ph1handle *iph1;
82 struct isakmp_data *attr;
83{
84 int type;
85 vchar_t *reply_attr = NULL;
86
87 if ((iph1->mode_cfg->flags & ISAKMP_CFG_VENDORID_UNITY) == 0) {
88 plog(LLV_ERROR, LOCATION, NULL,
89 "Unity mode config request but the peer "
90 "did not declare itself as unity compliant\n");
91 return NULL;
92 }
93
94 type = ntohs(attr->type);
95
96 /* Handle short attributes */
97 if ((type & ISAKMP_GEN_MASK) == ISAKMP_GEN_TV) {
98 type &= ~ISAKMP_GEN_MASK;
99
100 plog(LLV_DEBUG, LOCATION, NULL,
101 "Short attribute %d = %d\n",
102 type, ntohs(attr->lorv));
103
104 switch (type) {
105 default:
106 plog(LLV_DEBUG, LOCATION, NULL,
107 "Ignored short attribute %d\n", type);
108 break;
109 }
110
111 return reply_attr;
112 }
113
114 switch(type) {
115 case UNITY_BANNER: {
116#define MAXMOTD 65536
117 char buf[MAXMOTD + 1];
118 int fd;
119 char *filename = &isakmp_cfg_config.motd[0];
120 size_t len;
121
122 if ((fd = open(filename, O_RDONLY, 0)) == -1) {
123 plog(LLV_ERROR, LOCATION, NULL,
124 "Cannot open \"%s\"\n", filename);
125 return NULL;
126 }
127
128 if ((len = read(fd, buf, MAXMOTD)) == -1) {
129 plog(LLV_ERROR, LOCATION, NULL,
130 "Cannot read \"%s\"\n", filename);
131 close(fd);
132 return NULL;
133 }
134 close(fd);
135
136 buf[len] = '\0';
137 reply_attr = isakmp_cfg_string(iph1, attr, buf);
138
139 break;
140 }
141
142 case UNITY_PFS:
143 reply_attr = isakmp_cfg_short(iph1, attr,
144 isakmp_cfg_config.pfs_group);
145 break;
146
147 case UNITY_SAVE_PASSWD:
148 reply_attr = isakmp_cfg_short(iph1, attr,
149 isakmp_cfg_config.save_passwd);
150 break;
151
152 case UNITY_DDNS_HOSTNAME:
153 reply_attr = isakmp_cfg_copy(iph1, attr);
154 break;
155
156 case UNITY_DEF_DOMAIN:
157 case UNITY_FW_TYPE:
158 case UNITY_SPLITDNS_NAME:
159 case UNITY_SPLIT_INCLUDE:
160 case UNITY_NATT_PORT:
161 case UNITY_BACKUP_SERVERS:
162 default:
163 plog(LLV_DEBUG, LOCATION, NULL,
164 "Ignored attribute %d\n", type);
165 return NULL;
166 break;
167 }
168
169 return reply_attr;
170}
171
172