[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: NIS support in APT



Sorry, didn't comment on the patch in the last email.  Doing so now.

On Sat, 28 Oct 2000, Livio Baldini Soares wrote:

>  About the NIS map you should create, I couldn't find a clean
> method... Look at an example of a map like `sources.list`:
> 
> deb file:/bla/ble bli blo
> deb file:/ha/he   hi  ho
> ^^^
> Here there's a problem cause DBM's (NIS compiled internal files)
> woun't let you have two keys that are equal (deb == deb), so everyone
> execept the last will be overwritten. What I did (which is a VERY BACD
> solution, but the only I could think of), was to make the map like
> this:
> 
> rule1 deb file:/bla/ble bli blo
> rule2 deb file:/ha/he   hi  ho
> ^^^^
> Actually these can be any word that is unique among the others keys.
> So in my implementation the key is ignored, all I work with is the
> value, sorry for the lame implementation.

Where is your script to build the map?

> Then you have to edit your `sources.list', with somehing like:
> 
> +desired.map
> ^
> I'm demanding this plus signal '+' to diferenciate nis maps from
> regular sources lines.

Standard practice.  I note that your patch allows for recursive maps, which is
good(mine does as well).

> 
> To apply the patch (which I created with `diff -pru`):
> 
> $ cd apt-0.3.19  ( the original one )
> $ patch -p1 < ${patch-file}
> $ autoconf
> $ ./configure
> $ make
> 
>   The autoconf was necessary cause I needed the Makefile to link
> libapt-pkg.so.2.7.1 with nss_nis. I don't know if I messed with too
> many makefiles, but I don't think so.

You weren't good enough with your autoconf.  Never hard code anything.  See my
attached patch.

Add this near the top of /var/yp/Makefile:
===
SOURCES_LIST= $(CLIENTSRC)/sources.list
===
Then, create a new rule in that Makefile, with the following snippet:
sources.list: $(SOURCES_LIST) $(YPDIR)/Makefile
	@echo "Updating $@..."
	@$(AWK) '/^.+$$/{key=$$1;$$1="";if ( key ~ / *#/) next;c=count[key]+1;map[key,c]=$$0;count[key]=c;}END{for(a in count){printf "%s", a, ount[a];for(i=1;i <= count[a]; i++){printf "\t%s", map[a,i];}printf "\n";}}' $(SOURCES_LIST) \
                | $(DBLOAD) -i $(SOURCES_LIST) -o $(YPMAPDIR)/$@ - $@
        -@$(NOPUSH) || $(YPPUSH) -d $(DOMAIN) $@
===
This removes comments, and combined like keyed lines into a single key/value
pair, with each embedded line separated by a tab.  I used tab, as the original
c++ code expands tabs into spaces, so it should be safe.

Er, erk, just noticed the above awk doesn't handle the case when there are
tabs in the input sources.list.  Should be easy to fix, tho.

Yes, I know apt 0.4.x is almost out.  I'll see if I can rework this patch
later(need to find time).

----BEGIN GEEK CODE BLOCK----
Version: 3.12
GCS d- s: a-- c+++ UL++++ P+ L++++ !E W+ M o+ K- W--- !O M- !V PS--
PE++ Y+ PGP++ t* 5++ X+ tv b+ D++ G e h*! !r z?
-----END GEEK CODE BLOCK-----
----BEGIN PGP INFO----
Adam Heath <doogie@debian.org>        Finger Print | KeyID
67 01 42 93 CA 37 FB 1E    63 C9 80 1D 08 CF 84 0A | DE656B05 PGP
AD46 C888 F587 F8A3 A6DA  3261 8A2C 7DC2 8BD4 A489 | 8BD4A489 GPG
-----END PGP INFO-----
diff -ruN --exclude configure --exclude config.log apt-0.3.19.orig/apt-pkg/sourcelist.cc apt-0.3.19/apt-pkg/sourcelist.cc
--- apt-0.3.19.orig/apt-pkg/sourcelist.cc	Sun Oct 17 02:30:23 1999
+++ apt-0.3.19/apt-pkg/sourcelist.cc	Thu Jun  1 20:46:50 2000
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/stat.h>
+#include <rpcsvc/ypclnt.h>
 									/*}}}*/
 
 // SourceList::pkgSourceList - Constructors				/*{{{*/
@@ -62,49 +63,112 @@
    {
       F.getline(Buffer,sizeof(Buffer));
       CurLine++;
-      _strtabexpand(Buffer,sizeof(Buffer));
-      _strstrip(Buffer);
-      
-      // Comment or blank
-      if (Buffer[0] == '#' || Buffer[0] == 0)
-	 continue;
-      
-      // Grok it
-      string Type;
-      string URI;
-      Item Itm;
-      const char *C = Buffer;
-      if (ParseQuoteWord(C,Type) == false)
-	 return _error->Error("Malformed line %u in source list %s (type)",CurLine,File.c_str());
-      if (ParseQuoteWord(C,URI) == false)
-	 return _error->Error("Malformed line %u in source list %s (URI)",CurLine,File.c_str());
-      if (ParseQuoteWord(C,Itm.Dist) == false)
-	 return _error->Error("Malformed line %u in source list %s (dist)",CurLine,File.c_str());
-      if (Itm.SetType(Type) == false)
-	 return _error->Error("Malformed line %u in source list %s (type parse)",CurLine,File.c_str());
-      if (Itm.SetURI(URI) == false)
-	 return _error->Error("Malformed line %u in source list %s (URI parse)",CurLine,File.c_str());
-
-      // Check for an absolute dists specification.
-      if (Itm.Dist.empty() == false && Itm.Dist[Itm.Dist.size() - 1] == '/')
-      {
-	 if (ParseQuoteWord(C,Itm.Section) == true)
-	    return _error->Error("Malformed line %u in source list %s (Absolute dist)",CurLine,File.c_str());
-	 Itm.Dist = SubstVar(Itm.Dist,"$(ARCH)",_config->Find("APT::Architecture"));
-	 List.push_back(Itm);
-	 continue;
-      }
+      if (!ParseLine(Buffer,File.c_str(),CurLine))
+	 break;
+   }
+   return true;
+}
+									/*}}}*/
+// SourceList::ParseLine - Parses a line from the sourcelist file	/*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool pkgSourceList::ParseLine(char *Buffer, const char *source, int CurLine)
+{
+   _strtabexpand(Buffer,sizeof(Buffer));
+   _strstrip(Buffer);
+
+   // Comment or blank
+   if (Buffer[0] == '#' || Buffer[0] == 0)
+      return true;
 
-      // Grab the rest of the dists
-      if (ParseQuoteWord(C,Itm.Section) == false)
-	    return _error->Error("Malformed line %u in source list %s (dist parse)",CurLine,File.c_str());
-      
-      do
-      {
-	 List.push_back(Itm);
+   // Grok it
+   string Type;
+   string URI;
+   Item Itm;
+   const char *C = Buffer;
+   if (ParseQuoteWord(C,Type) == false)
+      return _error->Error("Malformed line %u in source list %s (type)",CurLine,source);
+   if (_config->FindB("APT::NIS")) {
+      if (Type[0] == '+') {
+	 const char *map = Type.substr(1).c_str();
+	 char *domainname = (char *)_config->Find("APT::NIS::Domainname").c_str();
+	 int error;
+	 if (domainname[ 0 ] == '\0') {
+	    if ((error = yp_get_default_domain (&domainname)) != 0) {
+	       _error->Warning("can't get local yp domain: %s", yperr_string(error));
+	       return true;
+	    }
+	 }
+	 char *key, *value;
+	 int keylen = 0, valuelen = 0;
+	 int localCurLine = 0;
+	 error = yp_first(domainname, map, &key, &keylen, &value, &valuelen);
+	 while(error == YPERR_SUCCESS)
+	 {
+	    localCurLine++;
+	    char *line = (char *)malloc(keylen + 1 + valuelen + 1);
+	    if (line == NULL) {
+	       _error->Error("out of memory inside nis loop"); 
+	       return false;
+	    }
+	    memcpy(line, key, keylen);
+	    *(line + keylen) = ' ';
+	    char *lptr = value, *ptr;
+	    int length;
+	    while( lptr - value + 1 < valuelen )
+	    {
+	       if ((ptr = strstr(lptr, "\t")) == NULL)
+		  ptr = value + valuelen;
+	       length = ptr - lptr;
+	       memcpy((line + keylen + 1), lptr, length);
+	       *(line + keylen + 1 + length) = '\0';
+	       if (!ParseLine(line, Type.c_str(), localCurLine)) {
+		  free(line);
+		  return false;
+	       }
+	       lptr = ptr + 1;
+	    }
+	    char *oldkey = key;
+	    int oldkeylen = keylen;
+	    error = yp_next(domainname, Type.substr(1).c_str(), oldkey, oldkeylen, &key, &keylen, &value, &valuelen);
+	    free(line);
+	 };
+	 return true;
       }
-      while (ParseQuoteWord(C,Itm.Section) == true);
+   } else {
+      if (Type[0] == '+') {
+//_error->Warning("NIS entry found %s, with NIS disabled", Type.c_str());
+	 return true;
+      }
+   }
+   if (ParseQuoteWord(C,URI) == false)
+      return _error->Error("Malformed line %u in source list %s (URI)",CurLine,source);
+   if (ParseQuoteWord(C,Itm.Dist) == false)
+      return _error->Error("Malformed line %u in source list %s (dist)",CurLine,source);
+   if (Itm.SetType(Type) == false)
+      return _error->Error("Malformed line %u in source list %s (type parse)",CurLine,source);
+   if (Itm.SetURI(URI) == false)
+      return _error->Error("Malformed line %u in source list %s (URI parse)",CurLine,source);
+
+   // Check for an absolute dists specification.
+   if (Itm.Dist.empty() == false && Itm.Dist[Itm.Dist.size() - 1] == '/')
+   {
+      if (ParseQuoteWord(C,Itm.Section) == true)
+	 return _error->Error("Malformed line %u in source list %s (Absolute dist)",CurLine,source);
+      Itm.Dist = SubstVar(Itm.Dist,"$(ARCH)",_config->Find("APT::Architecture"));
+      List.push_back(Itm);
+      return true;
+   }
+
+   // Grab the rest of the dists
+   if (ParseQuoteWord(C,Itm.Section) == false)
+      return _error->Error("Malformed line %u in source list %s (dist parse)",CurLine,source);
+
+   do
+   {
+      List.push_back(Itm);
    }
+   while (ParseQuoteWord(C,Itm.Section) == true);
    return true;
 }
 									/*}}}*/
diff -ruN --exclude configure --exclude config.log apt-0.3.19.orig/apt-pkg/sourcelist.h apt-0.3.19/apt-pkg/sourcelist.h
--- apt-0.3.19.orig/apt-pkg/sourcelist.h	Wed Apr  7 00:30:18 1999
+++ apt-0.3.19/apt-pkg/sourcelist.h	Thu Jun  1 20:26:41 2000
@@ -64,6 +64,7 @@
 
    bool ReadMainList();
    bool Read(string File);
+   bool ParseLine(char *buffer, const char *source, int CurLine);
    
    // List accessors
    inline const_iterator begin() const {return List.begin();};
diff -ruN --exclude configure --exclude config.log apt-0.3.19.orig/buildlib/environment.mak.in apt-0.3.19/buildlib/environment.mak.in
--- apt-0.3.19.orig/buildlib/environment.mak.in	Tue Dec 21 01:37:56 1999
+++ apt-0.3.19/buildlib/environment.mak.in	Thu Jun  1 18:51:46 2000
@@ -12,6 +12,8 @@
 PICFLAGS+= -fPIC -DPIC
 LFLAGS+= @LDFLAGS@
 LEFLAGS+= 
+LIBS:= @LIBS@
+LFLAGS += $(LIBS)
 XLIBS:= @X_LIBS@ @X_PRE_LIBS@ @X11LIB@ @X_EXTRA_LIBS@
 SOCKETLIBS:= @SOCKETLIBS@
 AR:=@AR@
diff -ruN --exclude configure --exclude config.log apt-0.3.19.orig/configure.in apt-0.3.19/configure.in
--- apt-0.3.19.orig/configure.in	Fri May 12 23:10:29 2000
+++ apt-0.3.19/configure.in	Thu Jun  1 18:43:07 2000
@@ -35,6 +35,7 @@
 AC_PROG_RANLIB
 AC_CHECK_TOOL(AR,ar,"ar")
 
+AC_CHECK_LIB(nsl, yp_get_default_domain)
 dnl Checks for sockets
 SAVE_LIBS="$LIBS"
 LIBS=""
@@ -43,6 +44,8 @@
 SOCKETLIBS="$LIBS"
 AC_SUBST(SOCKETLIBS)
 LIBS="$SAVE_LIBS"
+
+AC_CHECK_HEADERS(rpcsvc/ypclnt.h)
 
 dnl Section Disabled pending removal of deity widget library  -- jgg
 if test "yes" != "yes"; then
diff -ruN --exclude configure --exclude config.log apt-0.3.19.orig/debian/changelog apt-0.3.19/debian/changelog
--- apt-0.3.19.orig/debian/changelog	Fri May 12 23:10:54 2000
+++ apt-0.3.19/debian/changelog	Thu Jun  1 18:54:36 2000
@@ -1,3 +1,9 @@
+apt (0.3.19.1) frozen unstable; urgency=low
+
+  * Experiment build with nis support.
+
+ -- Adam Heath <doogie@debian.org>  Thu,  1 Jun 2000 18:54:30 -0500
+
 apt (0.3.19) frozen unstable; urgency=low
   
   * Updates to apt-cdrom to support integrated non-us nicely, thanks to

Reply to: