import HEAD into svn+ssh://svn.samba.org/home/svn/samba/trunk
[metze/old/v3-2-winbind-ndr.git] / source / wrepld / partners.c
1 /* 
2    Unix SMB/CIFS implementation.
3    process incoming packets - main loop
4    Copyright (C) Jean Fran├žois Micouleau      1998-2002.
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22 #include "wins_repl.h"
23
24 /* we can exchange info with 64 partners at any given time */
25 WINS_PARTNER current_partners[64];
26 int total_current_partners;
27
28 /*******************************************************************
29 verify if we know this partner
30 ********************************************************************/
31 BOOL check_partner(int assoc)
32 {
33         int i;
34
35         DEBUG(5,("check_partner: total_current_partners: %d\n", total_current_partners));
36
37         for (i=0; i<total_current_partners; i++)
38                 if (current_partners[i].client_assoc==assoc)
39                         return True;
40
41         return False;
42 }
43
44 /*******************************************************************
45 add a new entry to the list
46 ********************************************************************/
47 BOOL add_partner(int client_assoc, int server_assoc, BOOL pull, BOOL push)
48 {
49         DEBUG(5,("add_partner: total_current_partners: %d\n", total_current_partners));
50
51         if (total_current_partners==64)
52                 return False;
53
54         current_partners[total_current_partners].client_assoc=client_assoc;
55         current_partners[total_current_partners].server_assoc=server_assoc;
56         current_partners[total_current_partners].pull_partner=pull;
57         current_partners[total_current_partners].push_partner=push;
58
59         total_current_partners++;
60
61         return True;
62 }
63
64 /*******************************************************************
65 remove an entry to the list
66 ********************************************************************/
67 BOOL remove_partner(int client_assoc)
68 {
69         int i,j;
70
71         DEBUG(5,("remove_partner: total_current_partners: %d\n", total_current_partners));
72
73         for (i=0; current_partners[i].client_assoc!=client_assoc && i<total_current_partners; i++)
74                 ;
75         
76         if (i==total_current_partners)
77                 return False;
78
79         for (j=i+1; j<total_current_partners; j++) {
80                 current_partners[j-1].client_assoc=current_partners[j].client_assoc;
81                 current_partners[j-1].server_assoc=current_partners[j].server_assoc;
82                 current_partners[j-1].pull_partner=current_partners[j].pull_partner;
83                 current_partners[j-1].push_partner=current_partners[j].push_partner;
84                 current_partners[j-1].partner_server.s_addr=current_partners[j].partner_server.s_addr;
85                 current_partners[j-1].other_server.s_addr=current_partners[j].other_server.s_addr;
86         }
87
88         total_current_partners--;
89
90         return True;
91 }
92
93 /*******************************************************************
94 link the client and server context
95 ********************************************************************/
96 BOOL update_server_partner(int client_assoc, int server_assoc)
97 {
98         int i;
99         
100         DEBUG(5,("update_server_partner: total_current_partners: %d\n", total_current_partners));
101
102         for (i=0; i<total_current_partners; i++)
103                 if (current_partners[i].client_assoc==client_assoc) {
104                         current_partners[i].server_assoc=server_assoc;
105                         return True;
106                 }
107
108         return False;
109 }
110
111 /*******************************************************************
112 verify if it's a pull partner
113 ********************************************************************/
114 BOOL check_pull_partner(int assoc)
115 {
116         int i;
117         
118         DEBUG(5,("check_pull_partner: total_current_partners: %d\n", total_current_partners));
119
120         for (i=0; i<total_current_partners; i++)
121                 if (current_partners[i].client_assoc==assoc &&
122                     current_partners[i].pull_partner==True)
123                         return True;
124
125         return False;
126 }
127
128 /*******************************************************************
129 verify if it's a push partner
130 ********************************************************************/
131 BOOL check_push_partner(int assoc)
132 {
133         int i;
134         
135         DEBUG(5,("check_push_partner: total_current_partners: %d\n", total_current_partners));
136
137         for (i=0; i<total_current_partners; i++)
138                 if (current_partners[i].client_assoc==assoc &&
139                     current_partners[i].push_partner==True)
140                         return True;
141
142         return False;
143 }
144
145 /*******************************************************************
146 return the server ctx linked to the client ctx
147 ********************************************************************/
148 int get_server_assoc(int assoc)
149 {
150         int i;
151         
152         DEBUG(5,("get_server_assoc: total_current_partners: %d\n", total_current_partners));
153
154         for (i=0; i<total_current_partners; i++)
155                 if (current_partners[i].client_assoc==assoc)
156                         return current_partners[i].server_assoc;
157
158         return 0;
159 }
160
161
162 /*******************************************************************
163 link the client and server context
164 ********************************************************************/
165 BOOL write_server_assoc_table(int client_assoc, struct in_addr partner, struct in_addr server)
166 {
167         int i;
168         
169         DEBUG(5,("write_server_assoc_table: total_current_partners: %d\n", total_current_partners));
170
171         for (i=0; i<total_current_partners; i++)
172                 if (current_partners[i].client_assoc==client_assoc) {
173                         current_partners[i].partner_server=partner;
174                         current_partners[i].other_server=server;
175                         return True;
176                 }
177
178         return False;
179 }
180
181 /*******************************************************************
182 link the client and server context
183 ********************************************************************/
184 BOOL get_server_assoc_table(int client_assoc, struct in_addr *partner, struct in_addr *server)
185 {
186         int i;
187         
188         DEBUG(5,("get_server_assoc_table: total_current_partners: %d\n", total_current_partners));
189
190         for (i=0; i<total_current_partners; i++)
191                 if (current_partners[i].client_assoc==client_assoc) {
192                         partner->s_addr=current_partners[i].partner_server.s_addr;
193                         server->s_addr=current_partners[i].other_server.s_addr;
194                         return True;
195                 }
196
197         return False;
198 }
199
200