summaryrefslogtreecommitdiff
path: root/source3/wrepld/partners.c
blob: 8560c07be40479946ee456602a2644dbc55a3033 (plain)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* 
   Unix SMB/Netbios implementation.
   Version 1.9.
   process incoming packets - main loop
   Copyright (C) Jean François Micouleau      1998-2002.
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "includes.h"
#include "wins_repl.h"

/* we can exchange info with 64 partners at any given time */
WINS_PARTNER current_partners[64];
int total_current_partners;

/*******************************************************************
verify if we know this partner
********************************************************************/
BOOL check_partner(int assoc)
{
	int i;
	
	for (i=0; i<total_current_partners; i++)
		if (current_partners[i].client_assoc==assoc)
			return True;

	return False;
}

/*******************************************************************
add a new entry to the list
********************************************************************/
BOOL add_partner(int client_assoc, int server_assoc, BOOL pull, BOOL push)
{
	if (total_current_partners==64)
		return False;

	current_partners[total_current_partners].client_assoc=client_assoc;
	current_partners[total_current_partners].server_assoc=server_assoc;
	current_partners[total_current_partners].pull_partner=pull;
	current_partners[total_current_partners].push_partner=push;

	total_current_partners++;

	return True;
}

/*******************************************************************
remove an entry to the list
********************************************************************/
BOOL remove_partner(int client_assoc)
{
	int i,j;

	for (i=0; current_partners[i].client_assoc!=client_assoc && i<total_current_partners; i++)
		;
	
	if (i==total_current_partners)
		return False;

	for (j=i+1; j<total_current_partners; j++) {
		current_partners[j-1].client_assoc=current_partners[j].client_assoc;
		current_partners[j-1].server_assoc=current_partners[j].server_assoc;
		current_partners[j-1].pull_partner=current_partners[j].pull_partner;
		current_partners[j-1].push_partner=current_partners[j].push_partner;
		current_partners[j-1].partner_server.s_addr=current_partners[j].partner_server.s_addr;
		current_partners[j-1].other_server.s_addr=current_partners[j].other_server.s_addr;
	}

	total_current_partners--;

	return True;
}

/*******************************************************************
link the client and server context
********************************************************************/
BOOL update_server_partner(int client_assoc, int server_assoc)
{
	int i;
	
	for (i=0; i<total_current_partners; i++)
		if (current_partners[i].client_assoc==client_assoc) {
			current_partners[i].server_assoc=server_assoc;
			return True;
		}

	return False;
}

/*******************************************************************
verify if it's a pull partner
********************************************************************/
BOOL check_pull_partner(int assoc)
{
	int i;
	
	for (i=0; i<total_current_partners; i++)
		if (current_partners[i].client_assoc==assoc &&
		    current_partners[i].pull_partner==True)
			return True;

	return False;
}

/*******************************************************************
verify if it's a push partner
********************************************************************/
BOOL check_push_partner(int assoc)
{
	int i;
	
	for (i=0; i<total_current_partners; i++)
		if (current_partners[i].client_assoc==assoc &&
		    current_partners[i].push_partner==True)
			return True;

	return False;
}

/*******************************************************************
return the server ctx linked to the client ctx
********************************************************************/
int get_server_assoc(int assoc)
{
	int i;
	
	for (i=0; i<total_current_partners; i++)
		if (current_partners[i].client_assoc==assoc)
			return current_partners[i].server_assoc;

	return 0;
}


/*******************************************************************
link the client and server context
********************************************************************/
BOOL write_server_assoc_table(int client_assoc, struct in_addr partner, struct in_addr server)
{
	int i;
	
	for (i=0; i<total_current_partners; i++)
		if (current_partners[i].client_assoc==client_assoc) {
			current_partners[i].partner_server=partner;
			current_partners[i].other_server=server;
			return True;
		}

	return False;
}

/*******************************************************************
link the client and server context
********************************************************************/
BOOL get_server_assoc_table(int client_assoc, struct in_addr *partner, struct in_addr *server)
{
	int i;
	
	for (i=0; i<total_current_partners; i++)
		if (current_partners[i].client_assoc==client_assoc) {
			partner->s_addr=current_partners[i].partner_server.s_addr;
			server->s_addr=current_partners[i].other_server.s_addr;
			return True;
		}

	return False;
}