Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroduce quota support, modernized with meson build system #1034

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ env:
libpam0g-dev \
libssl-dev \
libtalloc-dev \
libtirpc-dev \
libtool \
libtool-bin \
libtracker-sparql-3.0-dev \
libwrap0-dev \
meson \
ninja-build \
quota \
systemtap-sdt-dev \
tcpd \
tracker \
Expand Down Expand Up @@ -87,6 +89,7 @@ jobs:
krb5-dev \
libevent-dev \
libgcrypt-dev \
libtirpc-dev \
libtool \
libtracker \
linux-pam-dev \
Expand All @@ -96,6 +99,7 @@ jobs:
openrc \
openssl-dev \
pkgconfig \
rpcsvc-proto-dev \
talloc-dev \
tracker \
tracker-dev
Expand All @@ -122,7 +126,8 @@ jobs:
run: |
meson setup build \
-Dbuild-tests=true \
-Dwith-init-style=openrc
-Dwith-init-style=openrc \
-Dwith-libtirpc=true
- name: Meson - Build
run: ninja -C build
- name: Meson - Run tests
Expand Down Expand Up @@ -215,13 +220,15 @@ jobs:
libpam0g-dev \
libssl-dev \
libtalloc-dev \
libtirpc-dev \
libtool \
libtool-bin \
libtracker-sparql-3.0-dev \
libwrap0-dev \
make \
meson \
ninja-build \
quota \
systemtap-sdt-dev \
tcpd \
tracker
Expand All @@ -233,8 +240,10 @@ jobs:
--disable-dependency-tracking \
--enable-krbV-uam \
--enable-pgp-uam \
--enable-quota \
--with-cracklib \
--with-init-style=debian-sysv \
--with-libtirpc \
--with-tracker-pkgconfig-version=3.0
- name: Autotools - Build
run: make -j $(nproc) all
Expand All @@ -252,7 +261,8 @@ jobs:
run: |
meson setup build \
-Dbuild-tests=true \
-Dwith-init-style=debian-sysv
-Dwith-init-style=debian-sysv \
-Dwith-libtirpc=true
- name: Meson - Build
run: ninja -C build
- name: Meson - Run tests
Expand Down Expand Up @@ -429,9 +439,11 @@ jobs:
--disable-init-hooks \
--enable-krbV-uam \
--enable-pgp-uam \
--enable-quota \
--with-cracklib \
--with-docbook=/usr/share/xml/docbook/stylesheet/docbook-xsl \
--with-init-style=debian-systemd \
--with-libtirpc \
--with-tracker-pkgconfig-version=3.0
- name: Autotools - Generate manual pages
run: make html
Expand All @@ -455,7 +467,8 @@ jobs:
-Dbuild-tests=true \
-Dbuild-manual=true \
-Ddisable-init-hooks=true \
-Dwith-init-style=debian-systemd
-Dwith-init-style=debian-systemd \
-Dwith-libtirpc=true
- name: Meson - Build and generate manual pages
run: ninja -C build
- name: Meson - Run tests
Expand Down
4 changes: 2 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Changes in 3.2.0
Enable with afp.conf option: "fce sendwait"
* NEW: afppasswd: Add -w option to set password from the CLI, GitHub #936
* UPD: BREAKING: Remove legacy cdb and tdb CNID backends, GitHub #508
* UPD: BREAKING: Remove quota functionality, GitHub #493
* UPD: BREAKING: Remove Andrew File System (AFS) support, GitHub #554
* UPD: BREAKING: Remove bundled talloc, GitHub #479
Get the stand-alone talloc library from the Samba project
Expand All @@ -38,7 +37,8 @@ Changes in 3.2.0
* UPD: docs: Document libraries, init scripts in manual, GitHub #808
* FIX: afpd: Prevent theoretical crash in FPSetACL, GitHub #364
* FIX: libatalk: Restore invalid EA metadata cleanup, GitHub #400
* FIX: Shore up error handling and type safety, GItHub #952
* FIX: quota: Use the NetBSD 6 quota API, GitHub #1028
* FIX: Shore up error handling and type safety, GitHub #952
* UPD: Rewrite the afpstats script in Perl, GitHub #893
And, improve the formatting of the standard output.
Requires the Net::DBus Perl extension.
Expand Down
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ AC_NETATALK_CHECK_ICONV
dnl Check for CNID database backends
AC_NETATALK_CNID([bdb_required=yes],[bdb_required=no])

dnl Check for quota support
AC_NETATALK_CHECK_QUOTA

dnl Check for optional Zeroconf support
AC_NETATALK_ZEROCONF

Expand Down
6 changes: 4 additions & 2 deletions etc/afpd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ afpd_SOURCES = \
main.c \
mangle.c \
messages.c \
nfsquota.c \
ofork.c \
quota.c \
status.c \
switch.c \
uam.c \
Expand All @@ -41,12 +43,12 @@ afpd_SOURCES = \

afpd_LDADD = \
$(top_builddir)/libatalk/libatalk.la \
@LIBGCRYPT_LIBS@ @WRAP_LIBS@ @LIBADD_DL@ @ACL_LIBS@ @PTHREAD_LIBS@ @GSSAPI_LIBS@ @KRB5_LIBS@ @MYSQL_LIBS@
@LIBGCRYPT_LIBS@ @QUOTA_LIBS@ @WRAP_LIBS@ @LIBADD_DL@ @ACL_LIBS@ @PTHREAD_LIBS@ @GSSAPI_LIBS@ @KRB5_LIBS@ @MYSQL_LIBS@

afpd_LDFLAGS = -export-dynamic

afpd_CFLAGS = \
@GSSAPI_CFLAGS@ @KRB5_CFLAGS@ @PTHREAD_CFLAGS@ \
@GSSAPI_CFLAGS@ @KRB5_CFLAGS@ @PTHREAD_CFLAGS@ @QUOTA_CFLAGS@\
-DAPPLCNAME \
-DSERVERTEXT=\"$(SERVERTEXT)/\" \
-D_PATH_AFPDPWFILE=\"$(pkgconfdir)/afppasswd\" \
Expand Down
7 changes: 7 additions & 0 deletions etc/afpd/afp_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ static void show_version_extended(void )
puts( "No" );
#endif

printf( " Quota support:\t" );
#ifndef NO_QUOTA_SUPPORT
puts( "Yes" );
#else
puts( "No" );
#endif

printf( " Admin group support:\t" );
puts( "Yes" );

Expand Down
13 changes: 11 additions & 2 deletions etc/afpd/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ afpd_sources = [
'hash.c',
'mangle.c',
'messages.c',
'nfsquota.c',
'ofork.c',
'quota.c',
'status.c',
'switch.c',
'uam.c',
Expand Down Expand Up @@ -95,6 +97,7 @@ libafpd = static_library(
libgcrypt,
libcnid_deps,
threads,
tirpc,
],
c_args: [
'-DAPPLCNAME', confdir,
Expand All @@ -104,7 +107,10 @@ libafpd = static_library(
statedir,
uamdir,
],
link_args: netatalk_common_link_args,
link_args: [
netatalk_common_link_args,
quota_link_args,
],
install: false,
build_by_default: false,
)
Expand Down Expand Up @@ -181,7 +187,10 @@ executable(
statedir,
uamdir,
],
link_args: netatalk_common_link_args,
link_args: [
netatalk_common_link_args,
quota_link_args,
],
export_dynamic: true,
install: true,
install_dir: sbindir,
Expand Down
183 changes: 183 additions & 0 deletions etc/afpd/nfsquota.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*
* Copyright (c) 1980, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Robert Elz at The University of Melbourne.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Ported for AIX (jfs) by Joerg Schumacher ([email protected]) at the
* Technische Universitaet Braunschweig, FRG
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */

#if !defined(NO_QUOTA_SUPPORT) || defined(HAVE_LIBQUOTA)
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/param.h> /* for DEV_BSIZE */
#include <sys/time.h>
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif /* HAVE_NETDB_H */
#include <netinet/in.h>
#ifndef PORTMAP
#define PORTMAP 1
#endif
#include <rpc/rpc.h>
#include <rpc/pmap_prot.h>
#include <rpcsvc/rquota.h>


#include <atalk/afp.h>
#include <atalk/logger.h>

#include "unix.h"

/* lifted (with modifications) from the bsd quota program */
static int
callaurpc(struct vol *vol,
u_long prognum, u_long versnum, u_long procnum,
xdrproc_t inproc, char *in,
xdrproc_t outproc, char *out)
{
enum clnt_stat clnt_stat;
struct timeval tottimeout;

if (!vol->v_nfsclient) {
struct hostent *hp;
struct sockaddr_in server_addr;
struct timeval timeout;
int socket = RPC_ANYSOCK;

if ((hp = gethostbyname(vol->v_gvs)) == NULL)
return ((int) RPC_UNKNOWNHOST);
timeout.tv_usec = 0;
timeout.tv_sec = 6;
memcpy(&server_addr.sin_addr, hp->h_addr, hp->h_length);
server_addr.sin_family = AF_INET;
server_addr.sin_port = 0;

if ((vol->v_nfsclient = (void *)
clntudp_create(&server_addr, prognum, versnum,
timeout, &socket)) == NULL)
return ((int) rpc_createerr.cf_stat);

((CLIENT *) vol->v_nfsclient)->cl_auth = authunix_create_default();
}

tottimeout.tv_sec = 10;
tottimeout.tv_usec = 0;
clnt_stat = clnt_call((CLIENT *) vol->v_nfsclient, procnum,
inproc, in, outproc, out, tottimeout);
return ((int) clnt_stat);
}


#define GQR_STATUS status
#define GQR_RQUOTA getquota_rslt_u.gqr_rquota

int getnfsquota(struct vol *vol, const int uid, const uint32_t bsize,
struct dqblk *dqp)
{

struct getquota_args gq_args;
struct getquota_rslt gq_rslt;
struct timeval tv;
char *hostpath;

/* figure out the host and path */
if ((hostpath = strchr(vol->v_gvs, ':')) == NULL) {
LOG(log_error, logtype_afpd, "can't find hostname for %s", vol->v_gvs);
return AFPERR_PARAM;
}

if (*(hostpath + 1) != '/')
return AFPERR_PARAM;

/* separate host from hostpath */
*hostpath = '\0';

gq_args.gqa_pathp = hostpath + 1;
gq_args.gqa_uid = uid;

if(callaurpc(vol, RQUOTAPROG, RQUOTAVERS, RQUOTAPROC_GETQUOTA,
(xdrproc_t) xdr_getquota_args, (char *) &gq_args,
(xdrproc_t) xdr_getquota_rslt, (char *) &gq_rslt) != 0) {
LOG(log_info, logtype_afpd, "nfsquota: can't retrieve nfs quota information. \
make sure that rpc.rquotad is running on %s.", vol->v_gvs);
*hostpath = ':';
return AFPERR_PARAM;
}

switch (gq_rslt.GQR_STATUS) {
case Q_NOQUOTA:
break;

case Q_EPERM:
LOG(log_error, logtype_afpd, "nfsquota: quota permission error, host: %s",
vol->v_gvs);
break;

case Q_OK: /* we only copy the bits that we need. */
gettimeofday(&tv, NULL);

#if defined(__svr4__)
/* why doesn't using bsize work? */
#define NFS_BSIZE gq_rslt.GQR_RQUOTA.rq_bsize / DEV_BSIZE
#else /* __svr4__ */
/* NOTE: linux' rquotad program doesn't currently report the
* correct rq_bsize. */
/* NOTE: This is integer division and can introduce rounding errors */
#define NFS_BSIZE gq_rslt.GQR_RQUOTA.rq_bsize / bsize
#endif /* __svr4__ */

dqp->dqb_bhardlimit =
gq_rslt.GQR_RQUOTA.rq_bhardlimit*NFS_BSIZE;
dqp->dqb_bsoftlimit =
gq_rslt.GQR_RQUOTA.rq_bsoftlimit*NFS_BSIZE;
dqp->dqb_curblocks =
gq_rslt.GQR_RQUOTA.rq_curblocks*NFS_BSIZE;
dqp->dqb_btimelimit =
tv.tv_sec + gq_rslt.GQR_RQUOTA.rq_btimeleft;

*hostpath = ':';
return AFP_OK;
break;

default:
LOG(log_info, logtype_afpd, "bad rpc result, host: %s", vol->v_gvs);
break;
}

*hostpath = ':';
return AFPERR_PARAM;
}
#endif /* ! NO_QUOTA_SUPPORT || HAVE_LIBQUOTA */
Loading
Loading