openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/shadow/4.6-r0/shadow-4.6/lib/subordinateio.c
static int remove_range(struct commonio_db* db, const char* owner,
                        unsigned long start, unsigned long count)
{
    struct commonio_entry* ent;
    unsigned long end;

    if (count == 0)
    {
        return 1;
    }

    end = start + count - 1;
    for (ent = db->head; NULL != ent; ent = ent->next)
    {
        struct subordinate_range* range = ent->eptr;
        unsigned long first;
        unsigned long last;

        /* Skip unparsed entries */
        if (NULL == range)
        {
            continue;
        }

        first = range->start;
        last = first + range->count - 1;

        /* Skip entries with a different owner */
        if (0 != strcmp(range->owner, owner))
        {
            continue;
        }

        /* Skip entries outside of the range to remove */
        if ((end < first) || (start > last))
        {
            continue;
        }

        if (start <= first)
        {
            if (end >= last)
            {
                /* to be removed: [start,      end]
                 * range:           [first, last] */
                /* entry completely contained in the
                 * range to remove */
                commonio_del_entry(db, ent);
            }
            else
            {
                /* to be removed: [start,  end]
                 * range:           [first, last] */
                /* Remove only the start of the entry */
                range->start = end + 1;
                range->count = (last - range->start) + 1;

                ent->changed = true;
                db->changed = true;
            }
        }
        else
        {
            if (end >= last)
            {
                /* to be removed:   [start,  end]
                 * range:         [first, last] */
                /* Remove only the end of the entry */
                range->count = start - range->start;

                ent->changed = true;
                db->changed = true;
            }
            else
            {
                /* to be removed:   [start, end]
                 * range:         [first,    last] */
                /* Remove the middle of the range
                 * This requires to create a new range */
                struct subordinate_range tail;
                tail.owner = range->owner;
                tail.start = end + 1;
                tail.count = (last - tail.start) + 1;

                if (commonio_append(db, &tail) == 0)
                {
                    return 0;
                }

                range->count = start - range->start;

                ent->changed = true;
                db->changed = true;
            }
        }
    }

    return 1;
}
/*
 * remove_range:  remove a range of subuids from an owning uid's list
 *                of authorized subuids.
 * @db: database to work on
 * @owner: owning uid whose range is being removed
 * @start: start of the range to be removed
 * @count: number of uids in the range.
 *
 * Returns 0 on failure, 1 on success.  Failure means that we needed to
 * create a new range to represent the new limits, and failed doing so.
 */
remove a range of subuids from an owning uid's list
of authorized subuids.
@db: database to work on
@owner: owning uid whose range is being removed
@start: start of the range to be removed
@count: number of uids in the range.

Returns 0 on failure, 1 on success.  Failure means that we needed to
create a new range to represent the new limits, and failed doing so.
remove a range of subuids from an owning uid ' s list of authorized subuids . @db : database to work on @owner : owning uid whose range is being removed @start : start of the range to be removed @count : number of uids in the range . Returns 0 on failure 1 on success . Failure means that we needed to create a new range to represent the new limits and failed doing so .
static int remove_range(struct commonio_db* db, const char* owner,
                        unsigned long start, unsigned long count)
{
    struct commonio_entry* ent;
    unsigned long end;
    if (count == 0)
    {
        return 1;
    }
    end = start + count - 1;
    for (ent = db->head; NULL != ent; ent = ent->next)
    {
        struct subordinate_range* range = ent->eptr;
        unsigned long first;
        unsigned long last;
        if (NULL == range)
        {
            continue;
        }
        first = range->start;
        last = first + range->count - 1;
        if (0 != strcmp(range->owner, owner))
        {
            continue;
        }
        if ((end < first) || (start > last))
        {
            continue;
        }
        if (start <= first)
        {
            if (end >= last)
            {
                commonio_del_entry(db, ent);
            }
            else
            {
                range->start = end + 1;
                range->count = (last - range->start) + 1;
                ent->changed = true;
                db->changed = true;
            }
        }
        else
        {
            if (end >= last)
            {
                range->count = start - range->start;
                ent->changed = true;
                db->changed = true;
            }
            else
            {
                struct subordinate_range tail;
                tail.owner = range->owner;
                tail.start = end + 1;
                tail.count = (last - tail.start) + 1;
                if (commonio_append(db, &tail) == 0)
                {
                    return 0;
                }
                range->count = start - range->start;
                ent->changed = true;
                db->changed = true;
            }
        }
    }
    return 1;
}
static int remove_range ( struct commonio_db * db , const char * owner , unsigned long start , unsigned long count ) { struct commonio_entry * ent ; unsigned long end ; if ( count == 0 ) { return 1 ; } end = start + count - 1 ; for ( ent = db -> head ; NULL != ent ; ent = ent -> next ) { struct subordinate_range * range = ent -> eptr ; unsigned long first ; unsigned long last ; if ( NULL == range ) { continue ; } first = range -> start ; last = first + range -> count - 1 ; if ( 0 != strcmp ( range -> owner , owner ) ) { continue ; } if ( ( end < first ) || ( start > last ) ) { continue ; } if ( start <= first ) { if ( end >= last ) { commonio_del_entry ( db , ent ) ; } else { range -> start = end + 1 ; range -> count = ( last - range -> start ) + 1 ; ent -> changed = true ; db -> changed = true ; } } else { if ( end >= last ) { range -> count = start - range -> start ; ent -> changed = true ; db -> changed = true ; } else { struct subordinate_range tail ; tail . owner = range -> owner ; tail . start = end + 1 ; tail . count = ( last - tail . start ) + 1 ; if ( commonio_append ( db , & tail ) == 0 ) { return 0 ; } range -> count = start - range -> start ; ent -> changed = true ; db -> changed = true ; } } } return 1 ; }
remove_range:  remove a range of subuids from an owning uid's list
                of authorized subuids.
remove_range : remove a range of subuids from an owning uid ' s list of authorized subuids .
/* Skip unparsed entries */ /* Skip entries with a different owner */ /* Skip entries outside of the range to remove */ /* to be removed: [start,      end]
                 * range:           [first, last] */ /* entry completely contained in the
                 * range to remove */ /* to be removed: [start,  end]
                 * range:           [first, last] */ /* Remove only the start of the entry */ /* to be removed:   [start,  end]
                 * range:         [first, last] */ /* Remove only the end of the entry */ /* to be removed:   [start, end]
                 * range:         [first,    last] */ /* Remove the middle of the range
                 * This requires to create a new range */