From: Andreas Schneider Date: Mon, 13 May 2019 14:55:49 +0000 (+0200) Subject: s3:smbspool: Add the 'lp' group to the users groups X-Git-Tag: ldb-2.0.5~679 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6086efb6808089c431e7307fa239924bfda1185b;p=thirdparty%2Fsamba.git s3:smbspool: Add the 'lp' group to the users groups This is required to access files in /var/spool/cups which have been temporarily created in there by CUPS. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13939 Signed-off-by: Andreas Schneider Reviewed-by: Guenther Deschner --- diff --git a/source3/client/smbspool_krb5_wrapper.c b/source3/client/smbspool_krb5_wrapper.c index 5c4da33238b..e6684fc0d0c 100644 --- a/source3/client/smbspool_krb5_wrapper.c +++ b/source3/client/smbspool_krb5_wrapper.c @@ -82,6 +82,7 @@ int main(int argc, char *argv[]) { char smbspool_cmd[PATH_MAX] = {0}; struct passwd *pwd; + struct group *g = NULL; char gen_cc[PATH_MAX] = {0}; struct stat sb; char *env = NULL; @@ -89,6 +90,7 @@ int main(int argc, char *argv[]) char device_uri[4096] = {0}; uid_t uid = (uid_t)-1; gid_t gid = (gid_t)-1; + gid_t groups[1] = { (gid_t)-1 }; unsigned long tmp; int cmp; int rc; @@ -176,6 +178,26 @@ int main(int argc, char *argv[]) return CUPS_BACKEND_FAILED; } + /* + * We need the primary group of the 'lp' user. This is needed to access + * temporary files in /var/spool/cups/. + */ + g = getgrnam("lp"); + if (g == NULL) { + CUPS_SMB_ERROR("Failed to find user 'lp' - %s", + strerror(errno)); + return CUPS_BACKEND_FAILED; + } + + CUPS_SMB_DEBUG("Adding group 'lp' (%u)", g->gr_gid); + groups[0] = g->gr_gid; + rc = setgroups(sizeof(groups), groups); + if (rc != 0) { + CUPS_SMB_ERROR("Failed to set groups for 'lp' - %s", + strerror(errno)); + return CUPS_BACKEND_FAILED; + } + CUPS_SMB_DEBUG("Switching to gid=%d", gid); rc = setgid(gid); if (rc != 0) {