upg dhcpcd ppp

This commit is contained in:
joborun linux 2023-12-22 20:01:43 +02:00
parent 03a43ef01c
commit 2a6169f358
10 changed files with 437 additions and 32 deletions

View file

@ -6,7 +6,7 @@
#-----------------------------------------| DESCRIPTION |---------------------------------------
pkgname=dhcpcd
pkgver=10.0.5
pkgver=10.0.6
pkgrel=01
pkgdesc="RFC2131 compliant DHCP client daemon w/o systemd"
#url="https://roy.marples.name/projects/dhcpcd/"
@ -83,12 +83,11 @@ validpgpkeys=('A785ED2755955D9E93EA59F6597F97EA9AD45549') # Roy Marples (NetBSD
#https://github.com/NetworkConfiguration/dhcpcd/releases
sha256sums=(eb1f3cfef3069781ff8c896d7cea922639964afe22db28c069dc3f37f57eb428 # dhcpcd-10.0.5.tar.xz
a2b4e69f35fbe2756cbf4ca4ab490ade193c8f5f386a11913cdcb0a9f1b83be9 # dhcpcd-10.0.5.tar.xz.asc
sha256sums=(779d3ae514e8f24d7449503e1f0a20f5137c773bd04ca98c62386bf81e99f482 # dhcpcd-10.0.6.tar.xz
b46b79a0b77981079b26c359fe50b27167e4855106cf2256a6d725091e59da27 # dhcpcd-10.0.6.tar.xz.asc
d40d51367fcf7e9596e42cd2bab59404633bedbab4d0a3183e7246b4677937b7 # dhcpcd.install
06788ad9f5f7ccb5d2a2da6f0322ff5771f8de82cfbe8b9ad954f2c38265e21b # dhcpcd.sysusers
55d57b958f6b7e4d4a538ee88b0fcc1a522050c2d38efb5d680139f618234b35) # dhcpcd.tmpfiles
## ff4777f7c9489684665103c48e18d17efc56e4dc49fa1b87123bb0a76709a960 dhcpcd-10.0.5-01-x86_64.pkg.tar.lz
## e5a84c837cdc2c05f8c7b7469b0d4c4d194af55984c9b56062d20ae020590b00 dhcpcd-10.0.6-01-x86_64.pkg.tar.lz

View file

@ -5,7 +5,7 @@
# Contributor: Judd Vinet <jvinet.zeroflux.org>
pkgname=dhcpcd
pkgver=10.0.5
pkgver=10.0.6
pkgrel=1
pkgdesc="DHCP/ IPv4LL/ IPv6RA/ DHCPv6 client"
url="https://roy.marples.name/projects/dhcpcd/"
@ -29,13 +29,13 @@ source=(
$pkgname.sysusers
$pkgname.tmpfiles
)
sha256sums=('eb1f3cfef3069781ff8c896d7cea922639964afe22db28c069dc3f37f57eb428'
sha256sums=('779d3ae514e8f24d7449503e1f0a20f5137c773bd04ca98c62386bf81e99f482'
'SKIP'
'a2495b4a4632f9ee6d5d40877eb9667aaa3f64e035dbd8ccfc029a3a2339f069'
'843913ee4cd77ca51ab1f1d21eb13650df3791db2b8526a9b0c9acf2d6b9c63f'
'06788ad9f5f7ccb5d2a2da6f0322ff5771f8de82cfbe8b9ad954f2c38265e21b'
'1ca593a91d537766d073e71cfab87881e6f6a2ccb5236a45531d5520b3af7a31')
b2sums=('52435e2afa4fa5563b629af3f69b149b87de75097d20819423429741e8f2d16df136409180c509ff08b28fd060ad74da4d73057556349b8041c716dbeb7dbcc3'
b2sums=('4afd08cf7377b2262d33bf3f7ac503e081572a7c1ffd53b285842a92d99d88fae44e7e6384134bbe1eb839001f822fa7fb43718c42f9e8e6d11a05ec66fa2fc6'
'SKIP'
'7589109b275c823b80002cbb273113d0e1b5635fc79859bbfc55c287d3d1ce9a539116e33f60d118f6251d7301b6376c40ff9346d5947b02f75cb9261c6488ef'
'ceb051db7d43464992ffd804f95fb6c96ba6f450a0ec7a97d595f0700299916d1ebb049a1b97671e4b58f8829510bc44af2a36bfdccb79f9c34330162e6fdedb'

View file

@ -1,6 +1,6 @@
real 0m15.570s
user 0m14.401s
sys 0m1.512s
real 0m19.514s
user 0m17.519s
sys 0m2.541s

View file

@ -7,12 +7,15 @@
pkgname=ppp
pkgver=2.5.0
pkgrel=01
pkgrel=02
pkgdesc="A daemon which implements the Point-to-Point Protocol for dial-up networking - w/o systemd & ipv6"
url="https://www.samba.org/ppp/"
depends=('glibc' 'libpcap' 'libxcrypt' 'openssl')
backup=(etc/ppp/{chap-secrets,pap-secrets,options,ip-up,ip-down,ip-down.d/00-dns.sh,ip-up.d/00-dns.sh,ipv6-up.d/00-iface-config.sh})
backup=(etc/ppp/{chap-secrets,ip-down,ip-down.d/00-dns.sh,ip-up,ip-up.d/00-dns.sh,ipv6-down,ipv6-up,ipv6-up.d/00-iface-config.sh,options,pap-secrets})
source=(https://download.samba.org/pub/ppp/ppp-$pkgver.tar.gz{,.asc}
ppp-revert-var-lock.patch::https://github.com/ppp-project/ppp/commit/99cbf5e269994482edaf64624be8b1c806f9587c.patch
ppp-utils-mkdir.patch::https://github.com/ppp-project/ppp/commit/b0e7307b3569a5dad0f2606d2736cc8317851598.patch
ppp-create-rundir.patch::https://github.com/ppp-project/ppp/commit/3a4fec968174fd6f387d5ec872a56343f256f645.patch
options
ip-up
ip-down
@ -20,18 +23,13 @@ source=(https://download.samba.org/pub/ppp/ppp-$pkgver.tar.gz{,.asc}
ip-down.d.dns.sh
LICENSE)
#prepare() {
# cd $pkgname-$pkgver
#
# patch -p1 -i "$srcdir"/ppp-2.4.6-makefiles.patch
#
# # enable active filter
# sed -i "s:^#FILTER=y:FILTER=y:" pppd/Makefile.linux
# # enable ipv6 support
## sed -i "s:^#HAVE_INET6=y:HAVE_INET6=y:" pppd/Makefile.linux
# # Enable Microsoft proprietary Callback Control Protocol
# sed -i "s:^#CBCP=y:CBCP=y:" pppd/Makefile.linux
#}
prepare() {
cd $pkgname-$pkgver
patch -Np1 -i ../ppp-revert-var-lock.patch
patch -Np1 -i ../ppp-utils-mkdir.patch
patch -Np1 -i ../ppp-create-rundir.patch
}
build() {
cd $pkgname-$pkgver
@ -108,6 +106,9 @@ validpgpkeys=('631E179E370CD727A7F2A33A9E4295D605F66CE9' # Paul Mackerras (Sign
sha256sums=(5cae0e8075f8a1755f16ca290eb44e6b3545d3f292af4da65ecffe897de636ff # ppp-2.5.0.tar.gz
a8f99019f6d3c7ded5069dbd61283953eae06e8321e3acbc9fe341722766865e # ppp-2.5.0.tar.gz.asc
25726f3937c3ef13edf0547f285238bb2f1516732f02424add8c89930f8e32d6 # ppp-revert-var-lock.patch
be925b10fca2f84a46ad369c15e6faeac5d281e1897e9c80a9e7577ef887389e # ppp-utils-mkdir.patch
af01d3721a61079e7afb3aa262508721e4c759187f4643f01cb547682d900f61 # ppp-create-rundir.patch
c74f0e09724b90d9fbdbb921b5d6f27812d650945d6d8015f4f06089f5562d9c # options
ddef42b2cc5d49e81556dc9dbacf5ee3bf8dc32704f3670c2233eed42c4a4efd # ip-up
658630ba4c5cb583df80af6d4df81df8ae20798f63cc4b9cec8d4dad13a6a897 # ip-down
@ -115,4 +116,5 @@ sha256sums=(5cae0e8075f8a1755f16ca290eb44e6b3545d3f292af4da65ecffe897de636ff #
17b486fa69a71dafcbe543dc4f2b8cb9ed31e675aabc5f6c98ef94dbc1561c85 # ip-down.d.dns.sh
96fd35104e3d0ec472517afecead88419913ae73ae0189476d5dad9029c2be42) # LICENSE
## 5e3baa73c5457d0aad43b111b335470917f87b5f971648197305daf1962e6c4f ppp-2.5.0-01-x86_64.pkg.tar.lz
## 419642ff90c8025959448e4f64c73f36785f633437e3dedb20ce2927baccb5bc ppp-2.5.0-02-x86_64.pkg.tar.lz

View file

@ -3,14 +3,17 @@
pkgname=ppp
pkgver=2.5.0
pkgrel=1
pkgrel=2
pkgdesc="A daemon which implements the Point-to-Point Protocol for dial-up networking"
arch=(x86_64)
url="https://www.samba.org/ppp/"
license=('GPL' 'BSD')
depends=('glibc' 'libpcap' 'libxcrypt' 'openssl')
backup=(etc/ppp/{chap-secrets,pap-secrets,options,ip-up,ip-down,ip-down.d/00-dns.sh,ip-up.d/00-dns.sh,ipv6-up.d/00-iface-config.sh})
backup=(etc/ppp/{chap-secrets,ip-down,ip-down.d/00-dns.sh,ip-up,ip-up.d/00-dns.sh,ipv6-down,ipv6-up,ipv6-up.d/00-iface-config.sh,options,pap-secrets})
source=(https://download.samba.org/pub/ppp/ppp-$pkgver.tar.gz{,.asc}
ppp-revert-var-lock.patch::https://github.com/ppp-project/ppp/commit/99cbf5e269994482edaf64624be8b1c806f9587c.patch
ppp-utils-mkdir.patch::https://github.com/ppp-project/ppp/commit/b0e7307b3569a5dad0f2606d2736cc8317851598.patch
ppp-create-rundir.patch::https://github.com/ppp-project/ppp/commit/3a4fec968174fd6f387d5ec872a56343f256f645.patch
options
ip-up
ip-down
@ -23,6 +26,9 @@ source=(https://download.samba.org/pub/ppp/ppp-$pkgver.tar.gz{,.asc}
LICENSE)
sha512sums=('094368ea2aa6c6e8dfba4443509857a7c1c7ff839bb6d6657743802477208c01e87db31593cef0932d3725c640e9c103179da6b742825034cda82bd31ddcc2ed'
'SKIP'
'eaf83b5d1204032f95dce12383a45ddc8050b4f85ba45bcc77f332fcbf8b73bf5f6fcf06f97e0606d37610249a013da8b36109f42a4901a477741970711ce73b'
'444eb247f1d3d8a83a8180b0593f2b79005fbcddfe38d33845d76324f8aa584e17fce36906b9a03b9be9092b9afbe5ebce3365d64887c08b6b4e19069a70d1fa'
'1bff91daaa61d4e3dcce82095be35f63c7025f22b956bf8b9ee48307a2ca437b61b55fd9f0172c514f3f6bee16aa9c615e6a11aeca663032d6a6d6f9166d4341'
'4324a9abe79b20735b87de2158bb73b6449415a4760f06a06b648dfb53517f8d9907b094a88d1b492b24c8720cfd9b17d491fbe236fbd51ba9042af60483b231'
'bdaaac792dd448ff31da6da2749d8c2f9c4e0311b1d4639de7c68038fcaa333cc28e25f5a6308de0ecb24b60b2e7284a811482df990da5f54d5581a746964f3c'
'92f3a5e383f2c888938e891ba831042e7f8c026b0ddf5ce8c3523d06ac32fa81742e638a4c665975cbc79868b98806d92574ee2ee8e034e33b065a90ee3ab28b'
@ -31,11 +37,19 @@ sha512sums=('094368ea2aa6c6e8dfba4443509857a7c1c7ff839bb6d6657743802477208c01e87
'256941b220ad54119daf1c76237fecd0b2e9ede1d74b0950c45e373252ce20c1d4cd35a26b4d35f94ad2b7f49569fc9050c44731d672317994b562c750020326'
'1b8dc6300f746607c0cce835e69ed444f24ba81874ba061b2b0377f0b9c1cb41a383d6845b364dfabb249a461422972ba5010bacf55c5f85f5eb0d3c0f4c71cd'
'5b92a05bcf3ad4b7a88434546884e088069ce7c16a10c472589ca5ecc648f86ca02c2f608fb856ac6cb6ef14b508c2e0dec146c953128693bfb6c988f1963de8'
'b9978c4038fb764a1bbe9dea92850673e14978450c0dcd7a1b0b24c4ebd515fcc4c5cc82cd4b97d826d483261e96945208b9fe97d6fea09a7a5c7910541db24c'
'a73ae90ed8b3df166123ed5b977869efb957cb9c78538ff067f230ada894741e77a72caa3f32c14319eb4d4ad739579411ec6a30d9c197bd397dae25b1d90355'
'ab3acd0387a7966ac3d220f2b0b6880302f827125d978991f83dd3f1a30340c2a98ca5aedf0b81ec6a9e5eb49b0b0a0a5356419f3b8415c892c2df8b52d3994a')
validpgpkeys=('631E179E370CD727A7F2A33A9E4295D605F66CE9' # Paul Mackerras (Signing key) <paulus@samba.org>
'DE8E01561D8276A4DBFAEFCC040F1D49EC9DBB8C') # Paul Mackerras <paulus@ozlabs.org>
prepare() {
cd $pkgname-$pkgver
patch -Np1 -i ../ppp-revert-var-lock.patch
patch -Np1 -i ../ppp-utils-mkdir.patch
patch -Np1 -i ../ppp-create-rundir.patch
}
build() {
cd $pkgname-$pkgver

View file

@ -1,2 +1,4 @@
automake
autoconf

View file

@ -0,0 +1,44 @@
From 3a4fec968174fd6f387d5ec872a56343f256f645 Mon Sep 17 00:00:00 2001
From: Dominique Martinet <dominique.martinet@atmark-techno.com>
Date: Thu, 3 Aug 2023 16:37:27 +0900
Subject: [PATCH] try to create rundir if missing
Runtime dir changed from /run to /run/pppd in commit 66a8c74c3f73 ("Let
./configure control the paths for pppd") and is likely to not exist on
some distros, in which case the pppdb will not be created.
See: #419 (lock directory moved in ppp-2.5.0)
Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---
pppd/tdb.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/pppd/tdb.c b/pppd/tdb.c
index 8a563f88b..62644171a 100644
--- a/pppd/tdb.c
+++ b/pppd/tdb.c
@@ -60,8 +60,11 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <signal.h>
+
+#include "pppd-private.h"
#include "tdb.h"
#include "spinlock.h"
+#include "pathnames.h"
#define TDB_MAGIC_FOOD "TDB file\n"
#define TDB_VERSION (0x26011967 + 6)
@@ -1728,7 +1731,12 @@ TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
goto internal;
}
+again:
if ((tdb->fd = open(name, open_flags, mode)) == -1) {
+ if ((open_flags & O_CREAT) && errno == ENOENT &&
+ mkdir_recursive(PPP_PATH_VARRUN) == 0)
+ goto again;
+
TDB_LOG((tdb, 5, "tdb_open_ex: could not open file %s: %s\n",
name, strerror(errno)));
goto fail; /* errno set by open(2) */

View file

@ -0,0 +1,58 @@
From 99cbf5e269994482edaf64624be8b1c806f9587c Mon Sep 17 00:00:00 2001
From: Dominique Martinet <asmadeus@codewreck.org>
Date: Tue, 10 Oct 2023 10:05:50 +0900
Subject: [PATCH] Revert lock path to /var/lock (#435)
lock dir changed on linux from /var/lock to /run/pppd/lock with
pppd-2.5.0, which makes pppd fail to start if the distribution does not
pre-create the directory.
This reverts it back to /var/lock.
The paths for other OS should be identical as LOCALSTATEDIR should be
/var, but also revert them back as well just in case.
Since the variable is no longer used remove it from makefiles.
Fixes: 66a8c74c3f73 ("Let ./configure control the paths for pppd")
Fixes: #419
Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
Co-authored-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---
pppd/Makefile.am | 2 +-
pppd/pathnames.h | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/pppd/Makefile.am b/pppd/Makefile.am
index e5bedf26a..7cb300533 100644
--- a/pppd/Makefile.am
+++ b/pppd/Makefile.am
@@ -83,7 +83,7 @@ pppd_SOURCES = \
upap.c \
utils.c
-pppd_CPPFLAGS = -DSYSCONFDIR=\"${sysconfdir}\" -DLOCALSTATEDIR=\"${localstatedir}\" -DPPPD_RUNTIME_DIR='"@PPPD_RUNTIME_DIR@"' -DPPPD_LOGFILE_DIR='"@PPPD_LOGFILE_DIR@"'
+pppd_CPPFLAGS = -DSYSCONFDIR=\"${sysconfdir}\" -DPPPD_RUNTIME_DIR='"@PPPD_RUNTIME_DIR@"' -DPPPD_LOGFILE_DIR='"@PPPD_LOGFILE_DIR@"'
pppd_LDFLAGS =
pppd_LIBS =
diff --git a/pppd/pathnames.h b/pppd/pathnames.h
index de2fb6889..12609a969 100644
--- a/pppd/pathnames.h
+++ b/pppd/pathnames.h
@@ -120,12 +120,12 @@
#define PPP_PATH_PPPDB PPP_PATH_VARRUN "/pppd2.tdb"
#ifdef __linux__
-#define PPP_PATH_LOCKDIR PPP_PATH_VARRUN "/lock"
+#define PPP_PATH_LOCKDIR "/var/lock"
#else
#ifdef SVR4
-#define PPP_PATH_LOCKDIR LOCALSTATEDIR "/spool/locks"
+#define PPP_PATH_LOCKDIR "/var/spool/locks"
#else
-#define PPP_PATH_LOCKDIR LOCALSTATEDIR "/spool/lock"
+#define PPP_PATH_LOCKDIR "/var/spool/lock"
#endif
#endif

286
ppp/ppp-utils-mkdir.patch Normal file
View file

@ -0,0 +1,286 @@
From b0e7307b3569a5dad0f2606d2736cc8317851598 Mon Sep 17 00:00:00 2001
From: Dominique Martinet <dominique.martinet@atmark-techno.com>
Date: Wed, 30 Aug 2023 11:46:01 +0900
Subject: [PATCH] utils: add mkdir_recursive
This will be used in the next commit.
A test file for utils has also been added to check mkdir works as
intended.
Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---
pppd/Makefile.am | 6 ++
pppd/pppd-private.h | 1 +
pppd/utils.c | 82 ++++++++++++++++++++++++++
pppd/utils_utest.c | 139 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 228 insertions(+)
create mode 100644 pppd/utils_utest.c
diff --git a/pppd/Makefile.am b/pppd/Makefile.am
index 7cb300533..c5fe10776 100644
--- a/pppd/Makefile.am
+++ b/pppd/Makefile.am
@@ -20,6 +20,12 @@ utest_pppcrypt_LDFLAGS =
check_PROGRAMS += utest_crypto
+utest_utils_SOURCES = utils.c utils_utest.c
+utest_utils_CPPFLAGS = -DUNIT_TEST
+utest_utils_LDFLAGS =
+
+check_PROGRAMS += utest_utils
+
if WITH_SRP
sbin_PROGRAMS += srp-entry
dist_man8_MANS += srp-entry.8
diff --git a/pppd/pppd-private.h b/pppd/pppd-private.h
index 2883e4622..46ce0c8bd 100644
--- a/pppd/pppd-private.h
+++ b/pppd/pppd-private.h
@@ -437,6 +437,7 @@ int sifproxyarp(int, u_int32_t);
int cifproxyarp(int, u_int32_t);
/* Delete proxy ARP entry for peer */
u_int32_t GetMask(u_int32_t); /* Get appropriate netmask for address */
+int mkdir_recursive(const char *); /* Recursively create directory */
int lock(char *); /* Create lock file for device */
int relock(int); /* Rewrite lock file with new pid */
void unlock(void); /* Delete previously-created lock file */
diff --git a/pppd/utils.c b/pppd/utils.c
index c1bdbbbfe..c47192e67 100644
--- a/pppd/utils.c
+++ b/pppd/utils.c
@@ -781,6 +781,88 @@ complete_read(int fd, void *buf, size_t count)
}
#endif
+/*
+ * mkdir_check - helper for mkdir_recursive, creates a directory
+ * but do not error on EEXIST if and only if entry is a directory
+ * The caller must check for errno == ENOENT if appropriate.
+ */
+static int
+mkdir_check(const char *path)
+{
+ struct stat statbuf;
+
+ if (mkdir(path, 0755) >= 0)
+ return 0;
+
+ if (errno == EEXIST) {
+ if (stat(path, &statbuf) < 0)
+ /* got raced? */
+ return -1;
+
+ if ((statbuf.st_mode & S_IFMT) == S_IFDIR)
+ return 0;
+
+ /* already exists but not a dir, treat as failure */
+ errno = EEXIST;
+ return -1;
+ }
+
+ return -1;
+}
+
+/*
+ * mkdir_parent - helper for mkdir_recursive, modifies the string in place
+ * Assumes mkdir(path) already failed, so it first creates the parent then
+ * full path again.
+ */
+static int
+mkdir_parent(char *path)
+{
+ char *slash;
+ int rc;
+
+ slash = strrchr(path, '/');
+ if (!slash)
+ return -1;
+
+ *slash = 0;
+ if (mkdir_check(path) < 0) {
+ if (errno != ENOENT) {
+ *slash = '/';
+ return -1;
+ }
+ if (mkdir_parent(path) < 0) {
+ *slash = '/';
+ return -1;
+ }
+ }
+ *slash = '/';
+
+ return mkdir_check(path);
+}
+
+/*
+ * mkdir_recursive - recursively create directory if it didn't exist
+ */
+int
+mkdir_recursive(const char *path)
+{
+ char *copy;
+ int rc;
+
+ // optimistically try on full path first to avoid allocation
+ if (mkdir_check(path) == 0)
+ return 0;
+
+ copy = strdup(path);
+ if (!copy)
+ return -1;
+
+ rc = mkdir_parent(copy);
+ free(copy);
+ return rc;
+}
+
/* Procedures for locking the serial device using a lock file. */
static char lock_file[MAXPATHLEN];
diff --git a/pppd/utils_utest.c b/pppd/utils_utest.c
new file mode 100644
index 000000000..cdca97e6d
--- /dev/null
+++ b/pppd/utils_utest.c
@@ -0,0 +1,139 @@
+#include <fcntl.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "pppd-private.h"
+
+/* globals used in test.c... */
+int debug = 1;
+int error_count;
+int unsuccess;
+
+/* check if path exists and returns its type */
+static int
+file_type(char *path)
+{
+ struct stat statbuf;
+
+ if (stat(path, &statbuf) < 0)
+ return -1;
+
+ return statbuf.st_mode & S_IFMT;
+}
+
+int
+test_simple() {
+ if (mkdir_recursive("dir"))
+ return -1;
+
+ if (file_type("dir") != S_IFDIR)
+ return -1;
+
+ rmdir("dir");
+ return 0;
+}
+
+int
+test_recurse() {
+ if (mkdir_recursive("dir/subdir/subsubdir"))
+ return -1;
+
+ if (file_type("dir/subdir/subsubdir") != S_IFDIR)
+ return -1;
+
+ rmdir("dir/subdir/subsubdir");
+
+ /* try again with partial existence */
+ if (mkdir_recursive("dir/subdir/subsubdir"))
+ return -1;
+
+ if (file_type("dir/subdir/subsubdir") != S_IFDIR)
+ return -1;
+
+ rmdir("dir/subdir/subsubdir");
+ rmdir("dir/subdir");
+ rmdir("dir");
+ return 0;
+}
+
+int
+test_recurse_multislash() {
+ if (mkdir_recursive("dir/subdir///subsubdir"))
+ return -1;
+
+ if (file_type("dir/subdir/subsubdir") != S_IFDIR)
+ return -1;
+
+ rmdir("dir/subdir/subsubdir");
+ rmdir("dir/subdir");
+
+ /* try again with partial existence */
+ if (mkdir_recursive("dir/subdir/subsubdir///"))
+ return -1;
+
+ if (file_type("dir/subdir/subsubdir") != S_IFDIR)
+ return -1;
+
+ rmdir("dir/subdir/subsubdir");
+ rmdir("dir/subdir");
+ rmdir("dir");
+ return 0;
+}
+
+int
+test_parent_notdir() {
+ int fd = open("file", O_CREAT, 0600);
+ if (fd < 0)
+ return -1;
+ close(fd);
+
+ if (mkdir_recursive("file") == 0)
+ return -1;
+ if (mkdir_recursive("file/dir") == 0)
+ return -1;
+
+ unlink("file");
+ return 0;
+}
+
+int
+main()
+{
+ char *base_dir = strdup("/tmp/ppp_utils_utest.XXXXXX");
+ int failure = 0;
+
+ if (mkdtemp(base_dir) == NULL) {
+ printf("Could not create test directory, aborting\n");
+ return 1;
+ }
+
+ if (chdir(base_dir) < 0) {
+ printf("Could not enter newly created test dir, aborting\n");
+ return 1;
+ }
+
+ if (test_simple()) {
+ printf("Could not create simple directory\n");
+ failure++;
+ }
+
+ if (test_recurse()) {
+ printf("Could not create recursive directory\n");
+ failure++;
+ }
+
+ if (test_recurse_multislash()) {
+ printf("Could not create recursive directory with multiple slashes\n");
+ failure++;
+ }
+
+ if (test_parent_notdir()) {
+ printf("Creating over a file appeared to work?\n");
+ failure++;
+ }
+
+ rmdir(base_dir);
+ free(base_dir);
+ return failure;
+}

View file

@ -1,6 +1,6 @@
real 0m21.674s
user 0m20.093s
sys 0m2.539s
real 0m33.211s
user 0m29.791s
sys 0m4.816s