From 9912711071a334e91f44f75b7491012839fc4f32 Mon Sep 17 00:00:00 2001 From: nocuser Date: Fri, 28 Oct 1994 13:41:46 +0000 Subject: [PATCH] fixed bug with IP address uniqueness check --- server/qsetup.dc | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/server/qsetup.dc b/server/qsetup.dc index 39e0f43f..51716283 100644 --- a/server/qsetup.dc +++ b/server/qsetup.dc @@ -977,17 +977,35 @@ setup_ahst(q,argv,cl) } if (value == 0) return(MR_ADDRESS); if (value != -1) { + /* + * an address or unique was specified. + */ id = *(int *)argv[8+row]; EXEC SQL SELECT saddr, mask, high, low INTO :addr, :mask, :high, :low FROM subnet WHERE snet_id = :id; if (ingres_errno) return(mr_errcode); if (value != -2) { + /* + * someone specified an IP address for the host record + */ if ((value & mask) != addr) return(MR_ADDRESS); - name = argv[9+row]; + /* + * run the address argument through inet_addr(). This + * has the effect that any out of bounds host addrs will + * be converted to a valid host addr. We do this now + * so that the uniqueness check works. We should also + * link in an inet_addr() that returns an error for + * this case. + */ + name = inet_ntoa(inet_addr(argv[9+row])); EXEC SQL SELECT count(mach_id) INTO :cnt FROM machine WHERE address = :name; if (ingres_errno) return(mr_errcode); if (cnt > 0) { + /* + * make IP address is unique. If this a modify request + * (row == 1), then we expect one record to exist. + */ if (row == 0 || row == 1 && cnt > 1) return(MR_ADDRESS); if (row == 1 && cnt == 1) { EXEC SQL SELECT mach_id INTO :id FROM machine @@ -996,6 +1014,11 @@ setup_ahst(q,argv,cl) } } } else { + /* + * a "unique" address was specified. Walk through the + * range specified in the network record, return + * error if no room left. + */ for (id = low; id <= high; id++) { if (((id & 0xff) == 0) || ((id & 0xff) == 255)) @@ -1012,6 +1035,9 @@ setup_ahst(q,argv,cl) else value = htonl(value); } + /* + * we have an address in value. Convert it to a string and store it. + */ value = htonl(value); strcpy(argv[9+row], inet_ntoa(value)); } else { -- 2.45.2