Re: NIS support in APT
Adam Heath writes:
> On Sat, 28 Oct 2000, Livio Baldini Soares wrote:
>
> > So if anybody's interested just e-mail me back at
> > livio@linux.ime.usp.br, or if I sent this to the wrong place, please
> > indicate me the right e-mail to contact APT development team.
>
> Send it here. I once did this as well, but never sent in a patch, altho Jason
> knew that I had done it.
Ok, here it goes.
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.
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.
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.
I really hope this helps, but my implementation might be ugly hence
I'm still in an undergrad student and I know nothing of C++. If
there's any doubts or comments (even nasty ones), please don't
hesitate to write me back!
Cheers!
--
Livio
diff -pru apt-0.3.19/apt-pkg/makefile apt-0.3.19.my/apt-pkg/makefile
--- apt-0.3.19/apt-pkg/makefile Mon Jan 31 17:11:09 2000
+++ apt-0.3.19.my/apt-pkg/makefile Sat Oct 28 03:04:58 2000
@@ -13,7 +13,7 @@ include ../buildlib/defaults.mak
LIBRARY=apt-pkg
MAJOR=2.7
MINOR=1
-SLIBS=$(PTHREADLIB)
+SLIBS=$(PTHREADLIB) $(NSSNISLIB)
# Source code for the contributed non-core things
SOURCE = contrib/mmap.cc contrib/error.cc contrib/strutl.cc \
diff -pru apt-0.3.19/apt-pkg/sourcelist.cc apt-0.3.19.my/apt-pkg/sourcelist.cc
--- apt-0.3.19/apt-pkg/sourcelist.cc Sun Oct 17 04:30:23 1999
+++ apt-0.3.19.my/apt-pkg/sourcelist.cc Sat Oct 28 08:47:54 2000
@@ -22,6 +22,8 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
+#include <rpcsvc/yp.h>
+#include <rpcsvc/ypclnt.h>
/*}}}*/
// SourceList::pkgSourceList - Constructors /*{{{*/
@@ -43,7 +45,55 @@ bool pkgSourceList::ReadMainList()
{
return Read(_config->FindFile("Dir::Etc::sourcelist"));
}
- /*}}}*/
+ /*}}}*/
+// SourceList::GrokIt - Parse one line only of the sourcelist /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool pkgSourceList::GrokIt(char *Buffer, string File)
+{
+ static int CurLine = 0;
+
+ CurLine++;
+
+ 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;
+ 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);
+ }
+ while (ParseQuoteWord(C,Itm.Section) == true);
+
+ return true;
+}
+ /*}}}*/
// SourceList::Read - Parse the sourcelist file /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -57,55 +107,108 @@ bool pkgSourceList::Read(string File)
List.erase(List.begin(),List.end());
char Buffer[300];
- int CurLine = 0;
while (F.eof() == false)
{
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);
+
+ // NIS map
+ if (Buffer[0] == '+'){
+ ReadNIS(Buffer+1);
continue;
}
-
- // 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);
- }
- while (ParseQuoteWord(C,Itm.Section) == true);
+ if (GrokIt(Buffer, File) == false)
+ return false;
}
return true;
+}
+ /*}}}*/
+char *NisBuf = NULL; // this will contain all of NIS sourcelist
+// SourceList::GrokNis - Wrapper for GrokIt while using NIS /*{{{*/
+/* */
+static int GrokNis (int status, char *inkey, int inkeylen, char *inval,
+ int invallen, char *indata)
+{
+ int offset=0;
+ if (NisBuf){
+ offset = strlen(NisBuf);
+ NisBuf = (char *)realloc(NisBuf, (strlen(NisBuf)+invallen+2)*sizeof(char));
+ }
+ else
+ NisBuf = (char *)malloc((inkeylen+invallen+2)*sizeof(char));
+
+ if (status != YP_TRUE)
+ return status;
+
+ sprintf(NisBuf+offset, "%s\n", inval); // append it to the previous
+
+ return 0;
+}
+ /*}}}*/
+// SourceList::ReadNIS - Parse the NIS map content /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool pkgSourceList::ReadNIS(char * Map)
+{
+ struct ypall_callback ypcb;
+ int error;
+ char *domainname;
+
+ if (Map == NULL)
+ Map = "sources.list";
+
+ if ((error = yp_get_default_domain (&domainname)) != 0)
+ {
+ fputs (yperr_string (error), stderr);
+ fputs ("\n", stderr);
+ return false;
+ }
+
+ ypcb.foreach = GrokNis;
+ ypcb.data = NULL;
+
+ /* Do a "for all" in the Map */
+ error = yp_all(domainname, Map, &ypcb);
+
+ switch (error)
+ {
+ case YPERR_SUCCESS:
+ break;
+ case YPERR_YPBIND:
+ fprintf (stderr, ("Ypbind not running!\n"));
+ return false;
+ default:
+ fprintf (stderr, ("Map %s not found. Reason: %s\n"),
+ Map, yperr_string (error));
+ return false;
+ }
+
+ if (NisBuf){
+ char *index = NisBuf, *new_index;
+ char Buffer[300], *tmp;
+
+ tmp = (char *)malloc( (strlen("Nis Map: ")+strlen(Map)+1)*sizeof(char));
+ sprintf(tmp, "Nis Map: %s", Map);
+ string File(tmp);
+ free(tmp);
+
+ while (index && (new_index = strchr(index, '\n'))){
+ strncpy(Buffer, index, new_index - index);
+ Buffer[new_index-index] = '\0';
+ index = new_index+1;
+ GrokIt(Buffer, File);
+ }
+
+ }
+
+ free(NisBuf);
+ NisBuf = 0;
}
/*}}}*/
// SourceList::Item << - Writes the item to a stream /*{{{*/
diff -pru apt-0.3.19/apt-pkg/sourcelist.h apt-0.3.19.my/apt-pkg/sourcelist.h
--- apt-0.3.19/apt-pkg/sourcelist.h Wed Apr 7 02:30:18 1999
+++ apt-0.3.19.my/apt-pkg/sourcelist.h Sat Oct 28 07:17:29 2000
@@ -62,9 +62,11 @@ class pkgSourceList
public:
+ bool GrokIt(char *Buffer, string File);
bool ReadMainList();
bool Read(string File);
-
+ bool ReadNIS(char * Map);
+
// List accessors
inline const_iterator begin() const {return List.begin();};
inline const_iterator end() const {return List.end();};
diff -pru apt-0.3.19/buildlib/library.mak apt-0.3.19.my/buildlib/library.mak
--- apt-0.3.19/buildlib/library.mak Fri Dec 10 03:39:46 1999
+++ apt-0.3.19.my/buildlib/library.mak Sat Oct 28 03:29:35 2000
@@ -20,7 +20,7 @@ $(LOCAL)-OBJS := $(addprefix $(OBJ)/,$(a
$(LOCAL)-DEP := $(addprefix $(DEP)/,$(addsuffix .opic.d,$(notdir $(basename $(SOURCE)))))
$(LOCAL)-HEADERS := $(addprefix $(INCLUDE)/,$(HEADERS))
$(LOCAL)-SONAME := lib$(LIBRARY).so.$(MAJOR)
-$(LOCAL)-SLIBS := $(SLIBS)
+$(LOCAL)-SLIBS := $(SLIBS) -lnss_nis
$(LOCAL)-LIBRARY := $(LIBRARY)
# Install the command hooks
diff -pru apt-0.3.19/configure.in apt-0.3.19.my/configure.in
--- apt-0.3.19/configure.in Sat May 13 01:10:29 2000
+++ apt-0.3.19.my/configure.in Sat Oct 28 03:07:29 2000
@@ -81,6 +81,9 @@ AC_SUBST(PTHREADLIB)
# AC_MSG_ERROR(failed: I need posix threads, pthread)
#fi
+dnl Checks for nss_nis
+AC_SUBST(NSSNISLIB)
+
dnl Converts the ARCH to be the same as dpkg
AC_MSG_CHECKING(system architecture)
archset="`awk \"{ if(\\\$1 == \\\"$host_cpu\\\") print \\\$2 }\" $srcdir/buildlib/archtable`"
Reply to: