From: Wichert Akkerman Date: Sun, 28 May 2000 16:06:44 +0000 (+0000) Subject: dpkg-deb/build.c: remove extra closing brace X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb9580eefbd0b81dce996068fa391b018d22281d;p=dpkg dpkg-deb/build.c: remove extra closing brace include/dpkg.h.in: add define for statusoveride file main/filedb.[ch]: add code to manage the statoverride list main/archives.c: modify tarobject() to check for statoverrides TODO: remove integrating suidmanager note, it's partially done now --- diff --git a/ChangeLog b/ChangeLog index 97db6542..ef32cfac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Sun May 28 17:24:09 CEST 2000 Wichert Akkerman + + * dpkg-deb/build.c: remove extra closing brace + * include/dpkg.h.in: add define for statusoveride file + * main/filedb.[ch]: add code to manage the statoverride list + * main/archives.c: modify tarobject() to check for statoverrides + * TODO: remove integrating suidmanager note, it's partially done now + Sun Apr 30 14:19:41 CEST 2000 Wichert Akkerman * doc/*: remove all references to GNU/Linux and just mention `Debian diff --git a/TODO b/TODO index 55d9a5f8..d0203dc1 100644 --- a/TODO +++ b/TODO @@ -13,7 +13,6 @@ dpkg * signatures & checksums * integrate debconf (add new status) * allow external program to specify how to handle conffiles -* integrate suidmanager * log our actions * try to remove directories again after removing conffiles * allow versioned provides diff --git a/debian/changelog b/debian/changelog index 7e4b685f..3135ef2a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,6 @@ dpkg (1.7.0) unstable; urgency=low + * Allow the administrator to override file mode and ownership * Use objdump instead of ldd in dpkg-shlibdeps * HURD updates, Closes: Bug#57753,#57754,#57755 * dpkg-architecture: -q should not imply -f, Closes: Bug#57761 diff --git a/dpkg-deb/build.c b/dpkg-deb/build.c index 024a6e4a..56530a72 100644 --- a/dpkg-deb/build.c +++ b/dpkg-deb/build.c @@ -126,7 +126,6 @@ static void add_to_filist(struct _finfo* fi, struct _finfo** start, struct _finf *start=*end=fi; else *end=(*end)->next=fi; - } } /* Free the memory for all entries in a list of _finfo structs diff --git a/include/dpkg.h.in b/include/dpkg.h.in index b053969d..81ec4d15 100644 --- a/include/dpkg.h.in +++ b/include/dpkg.h.in @@ -66,22 +66,23 @@ #define POSTRMFILE "postrm" #define LISTFILE "list" -#define ADMINDIR "#ADMINDIR#" -#define STATUSFILE "status" -#define AVAILFILE "available" -#define LOCKFILE "lock" -#define CMETHOPTFILE "cmethopt" -#define METHLOCKFILE "methlock" -#define DIVERSIONSFILE "diversions" -#define UPDATESDIR "updates/" -#define INFODIR "info/" -#define PARTSDIR "parts/" -#define CONTROLDIRTMP "tmp.ci/" -#define IMPORTANTTMP "tmp.i" -#define REASSEMBLETMP "reassemble" DEBEXT -#define IMPORTANTMAXLEN 10 -#define IMPORTANTFMT "%04d" /* change => also change lib/database.c:cleanup_updates */ -#define MAXUPDATES 50 +#define ADMINDIR "#ADMINDIR#" +#define STATUSFILE "status" +#define AVAILFILE "available" +#define LOCKFILE "lock" +#define CMETHOPTFILE "cmethopt" +#define METHLOCKFILE "methlock" +#define DIVERSIONSFILE "diversions" +#define STATOVERRIDEFILE "statoverride" +#define UPDATESDIR "updates/" +#define INFODIR "info/" +#define PARTSDIR "parts/" +#define CONTROLDIRTMP "tmp.ci/" +#define IMPORTANTTMP "tmp.i" +#define REASSEMBLETMP "reassemble" DEBEXT +#define IMPORTANTMAXLEN 10 +#define IMPORTANTFMT "%04d" /* change => also change lib/database.c:cleanup_updates */ +#define MAXUPDATES 50 #define LIBDIR "#LIBDIR#" #define LOCALLIBDIR "/usr/local/lib/dpkg" diff --git a/main/archives.c b/main/archives.c index 1067144b..6ff310e7 100644 --- a/main/archives.c +++ b/main/archives.c @@ -225,6 +225,7 @@ int tarobject(struct TarInfo *ti) { struct fileinlist *nifd; struct pkginfo *divpkg, *otherpkg; struct filepackages *packageslump; + mode_t am; /* Append to list of files. * The trailing / put on the end of names in tarfiles has already @@ -412,7 +413,14 @@ int tarobject(struct TarInfo *ti) { if (fwrite(databuf,1,wsz,thefile) != wsz) ohshite(_("error writing to `%.255s'"),ti->Name); } - if (fchown(fd,ti->UserID,ti->GroupID)) + if (nifd->namenode->statoverride) + debug(dbg_eachfile, _("tarobject ... stat override, uid=%d, gid=%d, mode=%04o"), + nifd->namenode->statoverride->uid, + nifd->namenode->statoverride->gid, + nifd->namenode->statoverride->mode); + if (fchown(fd, + nifd->namenode->statoverride ? nifd->namenode->statoverride->uid : ti->UserID, + nifd->namenode->statoverride ? nifd->namenode->statoverride->gid : ti->GroupID)) ohshite(_("error setting ownership of `%.255s'"),ti->Name); /* We flush the stream here to avoid any future * writes, which will mask any setuid or setgid @@ -420,7 +428,8 @@ int tarobject(struct TarInfo *ti) { */ if (fflush(thefile) == EOF) ohshite(_("error flushing `%.255s'"),ti->Name); - if (fchmod(fd,ti->Mode & ~S_IFMT)) + am=(nifd->namenode->statoverride ? nifd->namenode->statoverride->mode : ti->Mode) & ~S_IFMT; + if (fchmod(fd,am)) ohshite(_("error setting permissions of `%.255s'"),ti->Name); pop_cleanup(ehflag_normaltidy); /* thefile= fdopen(fd) */ if (fclose(thefile)) @@ -428,13 +437,13 @@ int tarobject(struct TarInfo *ti) { newtarobject_utime(fnamenewvb.buf,ti); break; case FIFO: - if (mkfifo(fnamenewvb.buf,ti->Mode & S_IFMT)) + if (mkfifo(fnamenewvb.buf,am)) ohshite(_("error creating pipe `%.255s'"),ti->Name); debug(dbg_eachfiledetail,"tarobject FIFO"); newtarobject_allmodes(fnamenewvb.buf,ti); break; case CharacterDevice: case BlockDevice: - if (mknod(fnamenewvb.buf,ti->Mode & S_IFMT,ti->Device)) + if (mknod(fnamenewvb.buf,am,ti->Device)) ohshite(_("error creating device `%.255s'"),ti->Name); debug(dbg_eachfiledetail,"tarobject CharacterDevice|BlockDevice"); newtarobject_allmodes(fnamenewvb.buf,ti); @@ -454,16 +463,18 @@ int tarobject(struct TarInfo *ti) { ohshite(_("error creating symbolic link `%.255s'"),ti->Name); debug(dbg_eachfiledetail,"tarobject SymbolicLink creating"); #ifdef HAVE_LCHOWN - if (lchown(fnamenewvb.buf,ti->UserID,ti->GroupID)) + if (lchown(fnamenewvb.buf, #else - if (chown(fnamenewvb.buf,ti->UserID,ti->GroupID)) + if (chown(fnamenewvb.buf, #endif + nifd->namenode->statoverride ? nifd->namenode->statoverride->uid : ti->UserID, + nifd->namenode->statoverride ? nifd->namenode->statoverride->gid : ti->GroupID)) ohshite(_("error setting ownership of symlink `%.255s'"),ti->Name); break; case Directory: /* We've already checked for an existing directory. */ if (mkdir(fnamenewvb.buf, - ti->Mode & (S_IRUSR|S_IRGRP|S_IROTH | S_IXUSR|S_IXGRP|S_IXOTH))) + am & (S_IRUSR|S_IRGRP|S_IROTH | S_IXUSR|S_IXGRP|S_IXOTH))) ohshite(_("error creating directory `%.255s'"),ti->Name); debug(dbg_eachfiledetail,"tarobject Directory creating"); newtarobject_allmodes(fnamenewvb.buf,ti); @@ -792,6 +803,7 @@ void archivefiles(const char *const *argv) { fnameidlu= fnamevb.used; ensure_diversions(); + ensure_statoverrides(); while ((thisarg= *argp++) != 0) { if (setjmp(ejbuf)) { @@ -889,3 +901,5 @@ int wanttoinstall(struct pkginfo *pkg, const struct versionrevision *ver, int sa } } +/* vi: ts=8 sw=2 + */ diff --git a/main/filesdb.c b/main/filesdb.c index 3d390aa3..0702ddea 100644 --- a/main/filesdb.c +++ b/main/filesdb.c @@ -25,6 +25,10 @@ #include #include +#include +#include +#include + #include #include #include @@ -42,6 +46,7 @@ static int allpackagesdone= 0; static int nfiles= 0; static struct diversion *diversions= 0; static FILE *diversionsfile= 0; +static FILE *statoverridefile= 0; void note_must_reread_files_inpackage(struct pkginfo *pkg) { allpackagesdone= 0; @@ -312,6 +317,136 @@ void reversefilelist_abort(struct reversefilelistiter *iterptr) { while (reversefilelist_next(iterptr)); } +void ensure_statoverrides(void) { + static struct varbuf vb; + + struct stat stab1, stab2; + FILE *file; + char *loaded_list, *loaded_list_end, *thisline, *nextline, *ptr; + ssize_t bytes, readden; + struct filestatoverride *fso; + struct filenamenode *fnn; + + varbufreset(&vb); + varbufaddstr(&vb,admindir); + varbufaddstr(&vb,"/" STATOVERRIDEFILE); + varbufaddc(&vb,0); + + onerr_abort++; + + file= fopen(vb.buf,"r"); + if (!file) { + if (errno != ENOENT) ohshite(_("failed to open statoverride file")); + if (!statoverridefile) { onerr_abort--; return; } + } else if (statoverridefile) { + if (fstat(fileno(statoverridefile),&stab1)) + ohshite(_("failed to fstat previous statoverride file")); + if (fstat(fileno(file),&stab2)) + ohshite(_("failed to fstat statoverride file")); + if (stab1.st_dev == stab2.st_dev && stab1.st_ino == stab2.st_ino) { + fclose(file); onerr_abort--; return; + } + } + if (statoverridefile) fclose(statoverridefile); + statoverridefile= file; + + push_cleanup(cu_closefile,ehflag_bombout, 0,0,1,(void*)file); + + loaded_list = nfmalloc(stab1.st_size); + loaded_list_end = loaded_list + stab1.st_size; + readden=0; + while (readdenuid=strtol(thisline, &endptr, 10); + if (*endptr!=0) + ohshit("syntax error: invalid uid in statusoverride file "); + } else { + struct passwd* pw = getpwnam(thisline); + if (pw==NULL) + ohshit("syntax error: unknown user `%s' in statusoverride file ", thisline); + fso->uid=pw->pw_uid; + } + + /* Move to the next bit */ + thisline=ptr+1; + if (thisline>=loaded_list_end) + ohshit("unexecpted end of line in statusoverride file"); + + /* Extract the gid */ + if (!(ptr=memchr(thisline, ' ', nextline-thisline))) + ohshit("syntax error in statusoverride file "); + *ptr=0; + if (thisline[0]=='#') { + fso->gid=strtol(thisline, &endptr, 10); + if (*endptr!=0) + ohshit("syntax error: invalid gid in statusoverride file "); + } else { + struct group* gr = getgrnam(thisline); + if (gr==NULL) + ohshit("syntax error: unknown group `%s' in statusoverride file ", thisline); + fso->gid=gr->gr_gid; + } + + /* Move to the next bit */ + thisline=ptr+1; + if (thisline>=loaded_list_end) + ohshit("unexecpted end of line in statusoverride file"); + + /* Extract the mode */ + if (!(ptr=memchr(thisline, ' ', nextline-thisline))) + ohshit("syntax error in statusoverride file "); + *ptr=0; + fso->mode=strtol(thisline, &endptr, 8); + if (*endptr!=0) + ohshit("syntax error: invalid mode in statusoverride file "); + + /* Move to the next bit */ + thisline=ptr+1; + if (thisline>=loaded_list_end) + ohshit("unexecpted end of line in statusoverride file"); + + fnn= findnamenode(thisline, 0); + if (fnn->statoverride) + ohshit("multiple statusoverides present for file `%.250s'", thisline); + fnn->statoverride=fso; + /* Moving on.. */ + thisline=nextline; + } + + pop_cleanup(ehflag_normaltidy); /* file= fopen() */ + + onerr_abort--; +} + void ensure_diversions(void) { static struct varbuf vb; @@ -397,7 +532,6 @@ void ensure_diversions(void) { } if (ferror(file)) ohshite(_("read error in diversions [i]")); - diversionsfile= file; onerr_abort--; } @@ -637,6 +771,7 @@ static struct filenamenode *findnamenode_low(const char *name, traverse->here->packages= 0; traverse->here->flags= 0; traverse->here->divert= 0; + traverse->here->statoverride= 0; traverse->here->filestat= 0; if((flags & fnn_nocopy) && name > orig_name && name[-1] == '/') { @@ -698,9 +833,13 @@ struct filenamenode *findnamenode_high(const char *name, newnode->flags= 0; newnode->next= 0; newnode->divert= 0; + newnode->statoverride= 0; newnode->filestat= 0; *pointerp= newnode; nfiles++; return newnode; } + +/* vi: ts=8 sw=2 + */ diff --git a/main/filesdb.h b/main/filesdb.h index 7b8c9afd..e50d7407 100644 --- a/main/filesdb.h +++ b/main/filesdb.h @@ -57,6 +57,7 @@ struct filenamenode { char *name; struct filepackages *packages; struct diversion *divert; + struct filestatoverride *statoverride; /* Fields from here on are used by archives.c &c, and cleared by * filesdbinit. */ @@ -76,6 +77,18 @@ struct fileinlist { struct filenamenode *namenode; }; +struct filestatoverride { + /* We allow the administrator to override the owner, group and mode of + * a file. If such an override is present we use that instead of the + * stat information stored in the archive. + * + * This functionality used to be in the suidmanager package. + */ + uid_t uid; + gid_t gid; + mode_t mode; +}; + struct diversion { /* When we deal with an `overridden' file, every package except * the overriding one is considered to contain the other file @@ -117,6 +130,7 @@ struct filenamenode *iterfilenext(struct fileiterator *i); void iterfileend(struct fileiterator *i); void ensure_diversions(void); +void ensure_statoverrides(void); void ensure_packagefiles_available(struct pkginfo *pkg); void ensure_allinstfiles_available(void);