#endif
#endif
#ifdef SHADOW_PWD
+#if _LINUX_C_LIB_VERSION_MAJOR < 5
#ifndef crypt
#define crypt pw_encrypt
#endif
#endif
#endif
+#endif
#ifdef SUNOS4
#define SIGNAL_CAST (void (*)(int))
int reply_lanman1(char *outbuf);
int reply_lanman2(char *outbuf);
int reply_nt1(char *outbuf);
-void parse_connect(char *buf,char *service,char *user,char *password,int *pwlen,char *dev);
void close_cnum(int cnum, int uid);
BOOL yield_connection(int cnum,char *name,int max_connections);
BOOL claim_connection(int cnum,char *name,int max_connections,BOOL Clear);
for (i = 0; i < n->num_ips; i++)
{
- DEBUG(3,("%15s NB=%2x ",
- inet_ntoa(n->ip_flgs[i].ip),
- n->ip_flgs[i].nb_flags));
+ DEBUG(3,("%15s NB=%2x source=%d",
+ inet_ntoa(n->ip_flgs[i].ip),
+ n->ip_flgs[i].nb_flags,n->source));
}
DEBUG(3,("\n"));
for (d = subnetlist; d; d = d->next)
{
for (n = d->namelist; n; n = next)
+ {
+ next = n->next;
+ if (n->death_time && n->death_time < t)
{
- if (n->death_time && n->death_time < t)
- {
+ if (n->source == SELF) {
+ DEBUG(3,("not expiring SELF name %s\n", namestr(&n->name)));
+ n->death_time += 300;
+ continue;
+ }
DEBUG(3,("Removing dead name %s\n", namestr(&n->name)));
- next = n->next;
-
if (n->prev) n->prev->next = n->next;
if (n->next) n->next->prev = n->prev;
free(n->ip_flgs);
free(n);
}
- else
- {
- next = n->next;
- }
- }
+ }
}
}
for (work = d->workgrouplist; work; work = work->next)
{
- if (listening_name(work, &dgram->dest_name) &&
- strequal(work->work_group, lp_workgroup()))
+ if (strequal(work->work_group, lp_workgroup()))
{
if (win_election(work, version,criterion,timeup,name))
{
DEBUG(3,("No domain logons\n"));
return;
}
- if (!listening_name(work, &dgram->dest_name))
- {
- DEBUG(4,("Not listening to that domain\n"));
- return;
- }
code = SVAL(buf,0);
switch (code) {
p.timestamp = time(NULL);
p.packet_type = NMB_PACKET;
- if (!send_packet(&p)) *id = 0xffff;
+ if (!send_packet(&p)) {
+ DEBUG(3,("send_packet to %s %d failed\n",inet_ntoa(p.ip),p.port));
+ *id = 0xffff;
+ }
return;
}
packet->prev = p;
}
+/****************************************************************************
+ determine if a packet is for us. Note that to have any chance of
+ being efficient we need to drop as many packets as possible at this
+ stage as subsequent processing is expensive.
+
+ We also must make absolutely sure we don't tread on another machines
+ property by answering a packet that is not for us.
+ ****************************************************************************/
+static BOOL listening(struct packet_struct *p,struct nmb_name *n)
+{
+ struct subnet_record *d;
+ struct name_record *n1;
+
+ d = find_subnet(p->ip);
+
+ n1 = find_name_search(&d,n,FIND_LOCAL|FIND_WINS|FIND_SELF,p->ip);
+
+ return (n1 != NULL);
+}
+
/****************************************************************************
process udp 138 datagrams
int len;
struct dgram_packet *dgram = &p->packet.dgram;
+ /* if we aren't listening to the destination name then ignore the packet */
+ if (!listening(p,&dgram->dest_name))
+ return;
+
+
if (dgram->header.msg_type != 0x10 &&
dgram->header.msg_type != 0x11 &&
dgram->header.msg_type != 0x12) {
}
-/*******************************************************************
- am I listening on a name. XXXX check the type of name as well.
- ******************************************************************/
-BOOL listening_name(struct work_record *work, struct nmb_name *n)
-{
- if (strequal(n->name,myname) ||
- strequal(n->name,work->work_group) ||
- strequal(n->name,MSBROWSE))
- {
- return(True);
- }
-
- return(False);
-}
-
-
/*******************************************************************
process a domain announcement frame
}
-/****************************************************************************
-depending on what announce has been made, we are only going to
-accept certain types of name announce. XXXX untested code
-
-check listening name type
-****************************************************************************/
-BOOL listening_type(struct packet_struct *p, int command)
-{
- struct dgram_packet *dgram = &p->packet.dgram;
- int type = dgram->dest_name.name_type;
-
- switch (command)
- {
- case ANN_HostAnnouncement:
- {
- if (type != 0x0 || type != 0x20) return (False);
- break;
- }
-
- case ANN_AnnouncementRequest:
- {
- return (True);
- break;
- }
-
- case ANN_Election:
- {
- return (True);
- break;
- }
-
- case ANN_GetBackupListReq:
- {
- return (True);
- break;
- }
-
- case ANN_GetBackupListResp:
- {
- return (True);
- break;
- }
-
- case ANN_DomainAnnouncement:
- {
- if (type != 0x1b || type != 0x1c) return (False);
- break;
- }
-
- case ANN_MasterAnnouncement:
- {
- if (type != 0x1d) return (False);
- break;
- }
-
- case ANN_LocalMasterAnnouncement:
- {
- if (type != 0x1c || type != 0x1d) return (False);
- break;
- }
- }
- return (True); /* we're not dealing with unknown packet types */
-}
-
/****************************************************************************
process a browse frame
int f_len, s_len;
struct srv_info_struct *servers=NULL;
int counted=0,total=0;
- int i;
+ int i,missed;
fstring domain;
BOOL domain_request;
BOOL local_request = servertype & SV_TYPE_LOCAL_LIST_ONLY;
total = get_server_info(servertype,&servers,domain);
data_len = fixed_len = string_len = 0;
+ missed = 0;
qsort(servers,total,sizeof(servers[0]),QSORT_CAST srv_comp);
DEBUG(4,("fill_srv_info %20s %8x %25s %15s\n",
s->name, s->type, s->comment, s->domain));
- if (data_len <= buf_len)
- {
+ if (data_len <= buf_len) {
counted++;
fixed_len += f_len;
string_len += s_len;
- }
+ } else {
+ missed++;
+ }
}
}
SSVAL(*rparam,0,NERR_Success);
SSVAL(*rparam,2,0);
SSVAL(*rparam,4,counted);
- SSVAL(*rparam,6,total);
+ SSVAL(*rparam,6,counted+missed);
if (servers) free(servers);
DEBUG(3,("NetServerEnum domain = %s uLevel=%d counted=%d total=%d\n",
- domain,uLevel,counted,total));
+ domain,uLevel,counted,counted+missed));
return(True);
}
}
+
+/****************************************************************************
+ parse a share descriptor string
+****************************************************************************/
+static void parse_connect(char *p,char *service,char *user,
+ char *password,int *pwlen,char *dev)
+{
+ char *p2;
+
+ DEBUG(4,("parsing connect string %s\n",p));
+
+ p2 = strrchr(p,'\\');
+ if (p2 == NULL)
+ strcpy(service,p);
+ else
+ strcpy(service,p2+1);
+
+ p += strlen(p) + 2;
+
+ strcpy(password,p);
+ *pwlen = strlen(password);
+
+ p += strlen(p) + 2;
+
+ strcpy(dev,p);
+
+ *user = 0;
+ p = strchr(service,'%');
+ if (p != NULL)
+ {
+ *p = 0;
+ strcpy(user,p+1);
+ }
+}
+
+
+
+
/****************************************************************************
reply to a tcon
****************************************************************************/
vuid = valid_uid(uid);
- parse_connect(inbuf,service,user,password,&pwlen,dev);
+ parse_connect(smb_buf(inbuf)+1,service,user,password,&pwlen,dev);
connection_num = make_connection(service,user,password,pwlen,dev,vuid);
if (check_name(directory,cnum))
dirptr = OpenDir(directory);
+ /* XXXX the CIFS spec says that if bit0 of the flags2 field is set then
+ the pattern matches against the long name, otherwise the short name
+ We don't implement this yet XXXX
+ */
+
if (dirptr)
{
error = ERRbadfile;
}
-/****************************************************************************
- parse a connect packet
-****************************************************************************/
-void parse_connect(char *buf,char *service,char *user,char *password,int *pwlen,char *dev)
-{
- char *p = smb_buf(buf) + 1;
- char *p2;
-
- DEBUG(4,("parsing connect string %s\n",p));
-
- p2 = strrchr(p,'\\');
- if (p2 == NULL)
- strcpy(service,p);
- else
- strcpy(service,p2+1);
-
- p += strlen(p) + 2;
-
- strcpy(password,p);
- *pwlen = strlen(password);
-
- p += strlen(p) + 2;
-
- strcpy(dev,p);
-
- *user = 0;
- p = strchr(service,'%');
- if (p != NULL)
- {
- *p = 0;
- strcpy(user,p+1);
- }
-}
-
-
/****************************************************************************
close all open files for a connection
****************************************************************************/
outbuf2 = orig_outbuf + SVAL(outbuf,smb_vwv1) + 4 - smb_wct;
/* remember the original command type */
- smb_com1 = CVAL(orig_outbuf,smb_com);
+ smb_com1 = CVAL(orig_inbuf,smb_com);
/* save the data which will be overwritten by the new headers */
memcpy(inbuf_saved,inbuf2,smb_wct);
memcpy(outbuf_saved,outbuf2,smb_wct);
- /* give the new packet the same header as the first part of the SMB */
- memmove(inbuf2,orig_inbuf,smb_wct);
+ /* give the new packet the same header as the last part of the SMB */
+ memmove(inbuf2,inbuf,smb_wct);
/* create the in buffer */
CVAL(inbuf2,smb_com) = smb_com2;
outsize2 = switch_message(smb_com2,inbuf2,outbuf2,size-chain_size,
bufsize-chain_size);
- /* copy the new reply header over the old one, but preserve
- the smb_com field */
+ /* copy the new reply and request headers over the old ones, but
+ preserve the smb_com field */
memmove(orig_outbuf,outbuf2,smb_wct);
CVAL(orig_outbuf,smb_com) = smb_com1;