access_table() - the winners!

Andrew Tridgell tridge at linuxcare.com
Wed Jan 19 04:07:00 GMT 2000


I'm declaring the access_table() challenge closed. I've now had
submissions that produce what must be close to the minimal logic. The
joint winners are Matt Chapman and Paul Mackerras.

I've put Pauls submission at ftp://samba.org/pub/tridge/misc/atable5.c

It is extremely neat, although it does rely on some pre-conditions:

- the precise ordering of the enumerated types is critical for the bitops
- it deliberately misses the impossible (SMB protocol wise)
  combinations that involve DENY_FCB

Thanks to everyone who put in submissions for this challenge - it was
fun!

because the code is so nice, I include below the core of Pauls
algorithm, note the neat bitop tricks. Mattys code is reduced to a
couple of lines in the code below. It is amazing how much simpler this
is than my original function.

If Paul and Matty could send me their mailing addresses I'll get the
t-shirts sent off. Matty gets one as Paul used Mattys analysis to
produce his code.

Cheers, Tridge


static int access_fcb(int new_deny, int old_deny, int old_mode,
                      BOOL same_pid, BOOL isexe)
{
        if (!same_pid || old_deny < DENY_DOS || new_deny < DENY_DOS
            || old_deny == DENY_DOS && (isexe || old_mode == DOS_OPEN_RDONLY))
                return AFAIL;

        return AALL;
}

static int access_dos(int new_deny, int old_deny, int old_mode,
                      BOOL same_pid, BOOL isexe)
{
        if ((new_deny == DENY_DOS && old_deny == DENY_DOS && same_pid)
            || isexe || old_mode == DOS_OPEN_RDONLY)
                return (isexe? AALL: old_mode | AREAD) & ~old_deny;

        return AFAIL;
}

static int access_table2(int new_deny, int old_deny, int old_mode,
                         BOOL same_pid, BOOL isexe)
{
        if (new_deny == DENY_FCB || old_deny == DENY_FCB)
                return access_fcb(new_deny, old_deny, old_mode,
                                  same_pid, isexe);

        if (new_deny & old_mode)
                return AFAIL;

        if (new_deny == DENY_DOS || old_deny == DENY_DOS)
                return access_dos(new_deny, old_deny, old_mode,
                                  same_pid, isexe);

        return AALL & ~old_deny;
}


More information about the samba-technical mailing list