Skip to content

Commit

Permalink
Add macOS support
Browse files Browse the repository at this point in the history
Two targets are provided, "macos" and "macos-gdbm".  "macos" will
successfully compile, but it appears macOS's default POSIX ndbm
implementation is completely broken (db.dptr void pointer to
garbage data).  "macos-gdbm" uses gdbm_compat (same as the "linux"
target), but that requires a Homebrew patch which is not yet
accepted[0].

[0] Homebrew/homebrew-core#56834
  • Loading branch information
rfinnie committed Jun 25, 2020
1 parent ae3b371 commit b11ccb5
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 29 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: ci
on: [push, pull_request]
jobs:
build:
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -10,3 +10,9 @@ jobs:
sudo apt-get -y install libgdbm-dev libgdbm-compat-dev
- name: make
run: make linux
build-macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: make
run: make macos
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ all:
@echo Valid types are aix3, aix4, sunos, sgi4, sgi5,
@echo hp-cc, hp-gcc, solaris, netbsd, svr4, linux,
@echo next, ultrix, osf1, aux, bsdi, sco5
@echo macos, macos-gdbm
@echo If you do not have one of these systems, you must edit
@echo src/Makefile, src/portability.h, src/config.h,
@echo cgi-src/Makefile, and support/Makefile
Expand Down Expand Up @@ -37,6 +38,12 @@ hp-gcc:
linux:
cd src ; make linux ; cd ../cgi-src ; make linux ; cd ../support ; make linux

macos:
cd src ; make macos ; cd ../cgi-src ; make macos ; cd ../support ; make macos

macos-gdbm:
cd src ; make macos-gdbm ; cd ../cgi-src ; make macos-gdbm ; cd ../support ; make macos-gdbm

netbsd:
cd src ; make netbsd ; cd ../cgi-src ; make netbsd ; cd ../support ; make netbsd

Expand Down
6 changes: 6 additions & 0 deletions cgi-src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ hp-cc:
linux:
make all CC=gcc

macos:
make all CC=gcc

macos-gdbm:
make all CC=gcc

netbsd:
make all CC=cc

Expand Down
6 changes: 6 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ linux2: linux
linux1:
make tar AUX_CFLAGS="-DLINUX -DFD_LINUX" CC=gcc CFLAGS=-O2 DBM_LIBS=-lgdbm

macos:
make tar AUX_CFLAGS="-DLINUX -DNEED_SYS_MALLOC_H" CC=gcc CFLAGS=-O2 DBM_LIBS="-ldbm"

macos-gdbm:
make tar AUX_CFLAGS="-DLINUX -DNEED_SYS_MALLOC_H -DGDBM_NDBM" CC=gcc CFLAGS=-O2 DBM_LIBS="-lgdbm -lgdbm_compat"

netbsd:
make tar AUX_CFLAGS=-DNETBSD EXTRA_LIBS=-lcrypt CC=cc CFLAGS=-O2

Expand Down
2 changes: 1 addition & 1 deletion src/digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ int get_digest(per_request *reqInfo, char *user, char *realm, char *digest,
dtRec = dbm_fetch(db, dtKey);
DBM_Close(db);
if (dtRec.dptr) {
strncpy(digest, dtRec.dptr, dtRec.dsize);
strncpy(digest, (char *)dtRec.dptr, dtRec.dsize);
digest[dtRec.dsize] = '\0';
return 1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/http_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ int get_pw(per_request *reqInfo, char *user, char *pw, security_data* sec)
dtRec = dbm_fetch(db, dtKey);
DBM_Close(db);
if (dtRec.dptr) {
strncpy(pw, dtRec.dptr, dtRec.dsize);
strncpy(pw, (char *)dtRec.dptr, dtRec.dsize);
pw[dtRec.dsize] = '\0';
return 1;
}
Expand Down Expand Up @@ -336,7 +336,7 @@ int dbm_group_lookup(per_request *reqInfo, char *user, char *group, DBM *db)
dtKey.dsize = strlen(group);
dtRec = dbm_fetch(db, dtKey);
if (dtRec.dptr) {
Found = in_listn(user,dtRec.dptr,dtRec.dsize);
Found = in_listn(user,(char *)dtRec.dptr,dtRec.dsize);
}
return Found;
}
Expand Down
6 changes: 6 additions & 0 deletions support/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ hp-gcc:
linux:
make all CC=gcc CFLAGS="-DLINUX -DGDBM_NDBM" EXTRA_LIBS="-lgdbm -lgdbm_compat -lcrypt"

macos:
make all CC=gcc CFLAGS="-DLINUX -DNEED_SYS_MALLOC_H" EXTRA_LIBS="-ldbm"

macos-gdbm:
make all CC=gcc CFLAGS="-DLINUX -DNEED_SYS_MALLOC_H -DGDBM_NDBM" EXTRA_LIBS="-lgdbm -lgdbm_compat"

netbsd:
make all CC=cc CFLAGS="-DNETBSD" EXTRA_LIBS=-lcrypt

Expand Down
13 changes: 4 additions & 9 deletions support/dbm2std.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ int main (int argc, char *argv[])
datum dtKey, dtRec;
char rec[MAX_STRING_LEN];
char key[MAX_STRING_LEN];
char *pch1, *pch2;
int ndx;

if (argc != 3)
Expand All @@ -58,15 +57,11 @@ int main (int argc, char *argv[])
for (dtKey = dbm_firstkey(db); dtKey.dptr; dtKey = dbm_nextkey(db)) {
dtRec = dbm_fetch (db, dtKey);

pch1 = key;
for (ndx = 0; ndx < dtKey.dsize; ndx++)
*pch1++ = dtKey.dptr[ndx];
*pch1 = '\0';
strncpy(key, (char *)dtKey.dptr, dtKey.dsize);
key[dtKey.dsize] = '\0';

pch2 = rec;
for (ndx = 0; ndx < dtRec.dsize; ndx++)
*pch2++ = dtRec.dptr[ndx];
*pch2 = '\0';
strncpy(rec, (char *)dtRec.dptr, dtRec.dsize);
rec[dtRec.dsize] = '\0';

printf ("Storing data <%s> with key <%s>\n",
rec, key);
Expand Down
21 changes: 11 additions & 10 deletions support/dbmgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,21 @@ void dbm_add_user(DBM *dbmgroup, char *group, char *user) {
resp = dbm_fetch(dbmgroup,key);
if (resp.dptr) {
printf("Adding %s to group %s.\n",user,group);
if (resp.dptr[0]) {
if (((char *)resp.dptr)[0]) {
if (!(newusers = (char *)malloc(resp.dsize + strlen(user) + 2))) {
fprintf(stderr,"Not enough memory to complete operation.\n");
perror("malloc");
exit(1);
}
tmp = resp.dptr;
tmp = (char *)resp.dptr;
while ((tmp = strstr(tmp,user))) {
if ((tmp[strlen(user)] == '\0') || (tmp[strlen(user)] == ' ') ||
(tmp[strlen(user)] == ',')) {
printf("User %s is already in group %s.\n",user,group);
exit(0);
} else tmp++;
}
strcpy(newusers,resp.dptr);
strcpy(newusers,(char *)resp.dptr);
sprintf(newusers,"%s %s",newusers,user);
resp.dptr = newusers;
resp.dsize = strlen(newusers);
Expand Down Expand Up @@ -173,13 +173,14 @@ void dbm_del_user(DBM *dbmgroup, char *group, char *user) {
resp = dbm_fetch(dbmgroup,key);

if (resp.dptr) {
if (resp.dptr[0] != '\0') {
if (!strcmp(resp.dptr,user)) {
resp.dptr[0] = '\0';
if (((char *)resp.dptr)[0] != '\0') {
tmp = (char *)resp.dptr;
if (!strcmp((char *)resp.dptr,user)) {
resp.dptr = tmp;
tmp[0] = '\0';
resp.dsize = 1;
dbm_store(dbmgroup,key,resp,DBM_REPLACE);
} else {
tmp = resp.dptr;
while ((tmp = strstr(tmp,user))) {
if ((tmp[strlen(user)] == '\0') || (tmp[strlen(user)] == ' ') ||
(tmp[strlen(user)] == ',')) {
Expand All @@ -191,9 +192,9 @@ void dbm_del_user(DBM *dbmgroup, char *group, char *user) {
exit(1);
}
printf("Deleting user %s from group %s.\n",user,group);
userlist = (char *)malloc(strlen(resp.dptr) - strlen(user)+1);
if (tmp != resp.dptr) {
strncpy(userlist,resp.dptr,tmp-resp.dptr-1);
userlist = (char *)malloc(strlen((char *)resp.dptr) - strlen(user)+1);
if (tmp != (char *)resp.dptr) {
strncpy(userlist,(char *)resp.dptr,tmp-(char *)resp.dptr-1);
strcat(userlist,(tmp+strlen(user)));
} else {
strcpy(userlist,(tmp+strlen(user)));
Expand Down
12 changes: 6 additions & 6 deletions support/webgrab.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
#include <stdio.h>
#include <fcntl.h>

#ifdef __bsdi__
# include <sys/malloc.h>
#else
# ifndef NeXT
#ifndef NO_MALLOC_H
# ifdef NEED_SYS_MALLOC_H
# include <sys/malloc.h>
# else
# include <malloc.h>
# endif
#endif
# endif /* NEED_SYS_MALLOC_H */
#endif /* NO_MALLOC_H */

#include <sys/time.h>
#include <sys/types.h>
Expand Down

0 comments on commit b11ccb5

Please sign in to comment.