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

Add FreeBSD support, round 1 #7765

Closed
wants to merge 6 commits into from
Closed

Add FreeBSD support, round 1 #7765

wants to merge 6 commits into from

Conversation

fluffykhv
Copy link

Port patches from FreeBSD ports tree (https://github.com/freebsd/freebsd-ports/tree/main/security/sssd2/files), round one

@alexey-tikhonov
Copy link
Member

Hi @fluffykhv,
thank you for the contribution.

Is "Add FreeBSD support, round 1" a single huge patch in FreeBSD repo?
If this is a set of patches, wouldn't it make sense to have a commit per patch to make the review easier?

@emaste
Copy link

emaste commented Dec 26, 2024

Patches in the FreeBSD ports collection are typically per-file rather than per-logical-change, so it may not be straightforward to recreate an incremental patch set. If you look at the URL above you'll see the per-file patches. This is admittedly not ideal from the perspective of collaboration with an upstream.

Looking at the history (e.g. https://github.com/freebsd/freebsd-ports/commits/main/security/sssd2/files) gives some insight, and you can see some logical changes that could be applied individually e.g. freebsd/freebsd-ports@9a40ff8.

If you want a patch set of logical changes we'll have to curate the patches in the ports tree.

@alexey-tikhonov
Copy link
Member

alexey-tikhonov commented Jan 6, 2025

Well, that's going to be tough...

As I'm not familiar with FreeBSD, it would help greatly if you could provide a rationale for additional includes.
What especially strikes out:

  • <sys/param.h> (what's there?)
  • <sys/types.h> (why?)
  • <sys/time.h> (why?)
    everywhere.

I think I'll cherry pick trivial / non-questionable patches in a separate PR, and once it's merged, you'll have to rebase.
But in general it would be great to have as little #ifdef __FreeBSD__ in the code as feasible.

In case of headers that might be finding a common ground where possible and, where it's impossible, putting conditional includes in a single common header to reduce clutter overall.

Wrt prctl(): there is HAVE_PRCTL - can it be used instead?
Btw, patches do not touch https://github.com/SSSD/sssd/blob/master/src/util/capabilities.c#L23 -- is this because FreeBSD didn't pick sssd-2.10+ yet?

@arrowd
Copy link

arrowd commented Jan 6, 2025

As I'm not familiar with FreeBSD, it would help greatly if you could provide a rationale for additional includes.

The general answer is - the transitive dependencies between FreeBSD headers are different from the Linux ones. It often comes up when porting software for FreeBSD that a single #include <foo.h> line works for Linux, because at also pulls in bar.h, but on FreeBSD these headers are decoupled from each other, so you have to include both in the source file. I think Dima can provide you exact error messaged if you're interested.

In case of headers that might be finding a common ground where possible and, where it's impossible, putting conditional includes in a single common header to reduce clutter overall.

If I'm not mistaken, POSIX dictates what header should be included to be able to use a given struct or function. So it is not matter of finding a common ground between different OSes, but simply following the standard.

Btw, patches do not touch https://github.com/SSSD/sssd/blob/master/src/util/capabilities.c#L23 -- is this because FreeBSD didn't pick sssd-2.10+ yet?

Yes, we're still at 2.9 at the moment. Hopefully we'll catch up soon.

@alexey-tikhonov
Copy link
Member

If I'm not mistaken, POSIX dictates what header should be included to be able to use a given struct or function.

Where it is POSIX mandated it will be "non questionable" and it is where some help with pointers would be appreciated. It will be just WAY slower for non FreeBSD user to figure out a reason for inclusion of particular header.

Comment on lines +324 to +327
/*
CatchSignal(SIGSEGV, sig_segv_abrt);
CatchSignal(SIGABRT, sig_segv_abrt);
*/

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
@alexey-tikhonov alexey-tikhonov self-assigned this Jan 7, 2025
@alexey-tikhonov alexey-tikhonov self-requested a review January 7, 2025 11:51
@@ -21,6 +21,9 @@

#include "config.h"

#ifdef __FreeBSD__
#include <sys/param.h>
Copy link
Member

@alexey-tikhonov alexey-tikhonov Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since b928dbe , "util/util.h" included below, includes <sys/param.h>

But what in confdb.c requires it?

@@ -18,6 +18,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifdef __FreeBSD__
#include <sys/param.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since b928dbe , "util/util.h" included below, includes <sys/param.h>

But what in radius_kdcpreauth.c requires it?

@@ -22,6 +22,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <sys/types.h>
#include <sys/time.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are those 2 headers required?

@@ -29,6 +29,8 @@
#include <stdbool.h>

#include <core/ntstatus.h>
#include <unistd.h>
#include <time.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What for?

@@ -27,7 +27,9 @@
#include <stdlib.h>
#include <string.h>
#include <popt.h>
#ifndef __FreeBSD__
#include <sys/prctl.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is still a call to prctl() in this file. How do you compile it?

@arrowd
Copy link

arrowd commented Jan 21, 2025

Let's approach this from a different angle. Would you be OK with enabling FreeBSD CI for this project via Cirrus CI? I will be happy to provide a configuration file, but you'll need to enable the Cirrus application for this repo.

With CI in place we can work through all the FreeBSD compilation errors, so it'd be clear what actual problem a commit fixes.

@alexey-tikhonov
Copy link
Member

It seems huge problem for adoption of sssd-2.10+ by FreeBSD will be usage of 'files capabilities' (Linux specific) and management of effective/permitted 'capabilities' (again, as meant in Linux) via prctl()

You are patching sssd-2.9 where prctl() is used to set dumpable flag and it is easy to cut it off.
It will be much more complicated for sssd-2.10+...

@@ -19,6 +19,9 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef __FreeBSD__
#include <sys/param.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What for?

@arrowd
Copy link

arrowd commented Jan 21, 2025

All right, let's close this for now. I'll reach our folks that are maintaining the SSSD port and ask them if they're working on 2.10.

But in case they are, the question about the CI stands.

@@ -32,6 +32,8 @@
#ifdef ldb_val
#error Please make sure to include ad_pac.h before ldb.h
#endif
#include <unistd.h>
#include <time.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What for?

@@ -21,6 +21,9 @@
*/


#include <sys/types.h>
#include <sys/time.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What for?
Also note you already added time.h to ad_pac.h that is included here.

Authors:
Lukas Slebodnik <[email protected]>

Copyright (C) 2013 Red Hat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this file from?


#include <errno.h>

#define BSD_ERR_MASK (0xB5DE <<16)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment would help to understand this mask.


#define BSD_ERR_MASK (0xB5DE <<16)

#ifndef EUCLEAN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EUCLEAN, EMEDIUMTYPE, EOWNERDEAD and ECONNRESET aren't used.

@@ -23,6 +23,9 @@
#include "providers/data_provider/dp.h"
#include "providers/data_provider/dp_private.h"
#include "providers/backend.h"
#ifdef __FreeBSD__
#include "util/sss_bsd_errno.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include it once in util/util_errors.h

@@ -25,6 +25,8 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What for?

@@ -23,6 +23,8 @@
#include "providers/ipa/ipa_deskprofile_rules_util.h"
#include "providers/ipa/ipa_deskprofile_private.h"
#include "providers/ipa/ipa_rules_common.h"
#include <sys/types.h>
#include <signal.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What for?

struct tm tm;
time_t t = 0;
tzset();
localtime_r(&t, &tm);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man page for 'localtime_r' says:

It need  not  set tzname, timezone, and daylight.

so looks like tzset() isn't needed

@@ -64,12 +64,25 @@ typedef void * SEC_CTX;
#endif /* done HAVE_SELINUX */

#include <sys/socket.h>
#ifdef __FreeBSD__
#include <sys/param.h>
#include <sys/ucred.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think

AC_CHECK_MEMBERS([struct ucred.pid, struct ucred.uid, struct ucred.gid], , ,

should be extended to detect availability of xucred

@arrowd
Copy link

arrowd commented Jan 21, 2025

@alexey-tikhonov Like I wrote in #7765 (comment) I see little sense in reviewing this PR in its current state. We (FreeBSD) should start over with master branch and this PR is better be closed.

I still want to hear if you would like us to prepare a FreeBSD CI.

@@ -1445,8 +1446,14 @@ errno_t sss_mmap_cache_init(TALLOC_CTX *mem_ctx, const char *name,
/* Attempt allocation several times, in case of EINTR */
for (int i = 0; i < POSIX_FALLOCATE_ATTEMPTS; i++) {
ret = posix_fallocate(mc_ctx->fd, 0, mc_ctx->mmap_size);
if (ret != EINTR)
break;
if (ret != EINTR && ret == EINVAL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ret != EINTR && part doesn't make sense.

@@ -28,6 +28,7 @@
#include "tests/cmocka/common_mock.h"

#include "util/authtok.h"
#include "util/sss_endian.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header defines htole32 and le32toh that aren't used in this file.

@alexey-tikhonov
Copy link
Member

@arrowd,

@alexey-tikhonov Like I wrote in #7765 (comment) I see little sense in reviewing this PR in its current state. We (FreeBSD) should start over with master branch and this PR is better be closed.

Well, there are some differences, but most of questions will be still valid.

In general I'd like to propose to use ./configure checks more extensively instead of abrupt '#ifdef FreeBSD' inserts.

Could you please take a look at #7808 - will the check of '_XOPEN_SOURCE' work around absence of 'timezone' on FreeBSD?

I still want to hear if you would like us to prepare a FreeBSD CI.

That's more question to @pbrezina.

But there is no CI automation that would not need a maintenance. And we already have quite a lot of items that likes to get broken...

In any case, I would really appreciate comments for '#include'-s being added.
With or without CI, somebody needs to remove those 1-by-1 to see a specific compilation error.

@arrowd
Copy link

arrowd commented Jan 21, 2025

Could you please take a look at #7808 - will the check of '_XOPEN_SOURCE' work around absence of 'timezone' on FreeBSD?

Not sure what's being talked about here - FreeBSD does have timezone. I'll say this again - this PR is prepared very poorly and shouldn't be looked at.

@alexey-tikhonov
Copy link
Member

Could you please take a look at #7808 - will the check of '_XOPEN_SOURCE' work around absence of 'timezone' on FreeBSD?

Not sure what's being talked about here - FreeBSD does have timezone.

I thought this PR gets rids of its usage for a reason...
At least from a quick glance - man tzset on FreeBSD doesn't mention extern long timezone;

I'll say this again - this PR is prepared very poorly and shouldn't be looked at.

Ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants