summaryrefslogtreecommitdiffstats
path: root/ipapython/ipavalidate.py
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2010-05-03 15:21:51 -0400
committerJason Gerard DeRose <jderose@redhat.com>2010-05-03 13:41:18 -0600
commit04e9056ec2b6e0360f3f3545fd638ecc17aaad2c (patch)
treeb9fefef29f7ba68c1932aac39f7b2bedfc85d356 /ipapython/ipavalidate.py
parent6d35812252cb4fcf34cf13bf88cbb705560afc3a (diff)
Make the installer/uninstaller more aware of its state
We have had a state file for quite some time that is used to return the system to its pre-install state. We can use that to determine what has been configured. This patch: - uses the state file to determine if dogtag was installed - prevents someone from trying to re-install an installed server - displays some output when uninstalling - re-arranges the ipa_kpasswd installation so the state is properly saved - removes pkiuser if it was added by the installer - fetches and installs the CA on both masters and clients
Diffstat (limited to 'ipapython/ipavalidate.py')
0 files changed, 0 insertions, 0 deletions
2 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
/*
   Copyright (C) 2009 Red Hat, Inc.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

#include <pthread.h>
#include <stdio.h>
#include "glz_encoder.h"
#include "glz_encoder_dictionary_protected.h"


/* Holds a specific data for one encoder, and data that is relevant for the current image encoded */
typedef struct Encoder {
    GlzEncoderUsrContext *usr;
    uint8_t id;
    SharedDictionary     *dict;

    struct {
        LzImageType type;
        uint32_t id;
        uint32_t first_win_seg;
    } cur_image;

    struct {
        uint8_t            *start;
        uint8_t            *now;
        uint8_t            *end;
        size_t bytes_count;
        uint8_t            *last_copy;  // pointer to the last byte in which copy count was written
    } io;
} Encoder;


/**************************************************************************
* Handling writing the encoded image to the output buffer
***************************************************************************/
static INLINE int more_io_bytes(Encoder *encoder)
{
    uint8_t *io_ptr;
    int num_io_bytes = encoder->usr->more_space(encoder->usr, &io_ptr);
    encoder->io.bytes_count += num_io_bytes;
    encoder->io.now = io_ptr;
    encoder->io.end = encoder->io.now + num_io_bytes;
    return num_io_bytes;
}

static INLINE void encode(Encoder *encoder, uint8_t byte)
{
    if (encoder->io.now == encoder->io.end) {
        if (more_io_bytes(encoder) <= 0) {
            encoder->usr->error(encoder->usr, "%s: no more bytes\n", __FUNCTION__);
        }
        GLZ_ASSERT(encoder->usr, encoder->io.now);
    }

    GLZ_ASSERT(encoder->usr, encoder->io.now < encoder->io.end);
    *(encoder->io.now++) = byte;
}

static INLINE void encode_32(Encoder *encoder, unsigned int word)
{
    encode(encoder, (uint8_t)(word >> 24));
    encode(encoder, (uint8_t)(word >> 16) & 0x0000ff);
    encode(encoder, (uint8_t)(word >> 8) & 0x0000ff);
    encode(encoder, (uint8_t)(word & 0x0000ff));
}

static INLINE void encode_64(Encoder *encoder, uint64_t word)
{
    encode_32(encoder, (uint32_t)(word >> 32));
    encode_32(encoder, (uint32_t)(word & 0xffffff));
}

static INLINE void encode_copy_count(Encoder *encoder, uint8_t copy_count)
{
    encode(encoder, copy_count);
    encoder->io.last_copy = encoder->io.now - 1; // io_now cannot be the first byte of the buffer
}

static INLINE void update_copy_count(Encoder *encoder, uint8_t copy_count)
{
    GLZ_ASSERT(encoder->usr, encoder->io.last_copy);
    *(encoder->io.last_copy) = copy_count;
}

// decrease the io ptr by 1
static INLINE void compress_output_prev(Encoder *encoder)
{
    // io_now cannot be the first byte of the buffer
    encoder->io.now--;
    // the function should be called only when copy count is written unnecessarily by glz_compress
    GLZ_ASSERT(encoder->usr, encoder->io.now == encoder->io.last_copy)
}

static int encoder_reset(Encoder *encoder, uint8_t *io_ptr, uint8_t *io_ptr_end)
{
    GLZ_ASSERT(encoder->usr, io_ptr <= io_ptr_end);
    encoder->io.bytes_count = io_ptr_end - io_ptr;
    encoder->io.start = io_ptr;
    encoder->io.now = io_ptr;
    encoder->io.end = io_ptr_end;
    encoder->io.last_copy = NULL;

    return TRUE;
}

/**********************************************************
*           Encoding
***********************************************************/

GlzEncoderContext *glz_encoder_create(uint8_t id, GlzEncDictContext *dictionary,
                                      GlzEncoderUsrContext *usr)
{
    Encoder *encoder;

    if (!usr || !usr->error || !usr->warn || !usr->info || !usr->malloc ||
        !usr->free || !usr->more_space) {
        return NULL;
    }

    if (!(encoder = (Encoder *)usr->malloc(usr, sizeof(Encoder)))) {
        return NULL;
    }

    encoder->id = id;
    encoder->usr = usr;
    encoder->dict = (SharedDictionary *)dictionary;

    return (GlzEncoderContext *)encoder;
}

void glz_encoder_destroy(GlzEncoderContext *opaque_encoder)
{
    Encoder *encoder = (Encoder *)opaque_encoder;

    if (!opaque_encoder) {
        return;
    }

    encoder->usr->free(encoder->usr, encoder);
}

/*
 * Give hints to the compiler for branch prediction optimization.
 */
#if defined(__GNUC__) && (__GNUC__ > 2)
#define LZ_EXPECT_CONDITIONAL(c) (__builtin_expect((c), 1))
#define LZ_UNEXPECT_CONDITIONAL(c) (__builtin_expect((c), 0))
#else
#define LZ_EXPECT_CONDITIONAL(c) (c)
#define LZ_UNEXPECT_CONDITIONAL(c) (c)
#endif


typedef uint8_t BYTE;

typedef struct __attribute__ ((__packed__)) one_byte_pixel_t {
    BYTE a;
} one_byte_pixel_t;

typedef struct __attribute__ ((__packed__)) rgb32_pixel_t {
    BYTE b;
    BYTE g;
    BYTE r;
    BYTE pad;
} rgb32_pixel_t;

typedef struct __attribute__ ((__packed__)) rgb24_pixel_t {
    BYTE b;
    BYTE g;
    BYTE r;
} rgb24_pixel_t;

typedef uint16_t rgb16_pixel_t;

#define BOUND_OFFSET 2
#define LIMIT_OFFSET 6