コード例 #1
0
/* ------------------------------------------------------------------
 *	get_attributes_local ()
 */
static bool get_attributes_local ( struct od_user_opts *in_out_opts, const char *in_user_guid )
{
	bool b_out = FALSE;

	/* look in local file first */
	CFDictionaryRef cf_dict_data = (CFDictionaryRef)read_user_settings( user_settings_path, kCFPropertyListImmutable );
	if ( !cf_dict_data )
		return( FALSE );

	CFStringRef cf_str = CFStringCreateWithCString( NULL, in_user_guid, kCFStringEncodingUTF8 );
	if ( cf_str ) {
		if ( CFDictionaryContainsKey( cf_dict_data, cf_str ) ) {
			CFDictionaryRef cf_dict_user = (CFDictionaryRef)CFDictionaryGetValue( cf_dict_data, cf_str );
			if ( cf_dict_user && (CFGetTypeID( cf_dict_user ) == CFDictionaryGetTypeID()) ) {
				get_acct_state( cf_dict_user, NULL, in_out_opts );
				get_alt_loc( cf_dict_user, NULL );
				get_mail_quota( cf_dict_user, NULL );
				b_out = TRUE;
			}
		}
		CFRelease( cf_str );
	}
	CFRelease( cf_dict_data );

	return( b_out );
} /* get_attributes_local */
コード例 #2
0
/* ------------------------------------------------------------------
 *	set_attributes_local ()
 */
static void set_attributes_local ( CFMutableDictionaryRef in_user_dict, const char *in_user_guid )
{
	/* Get the file data */
	CFDictionaryRef cf_dict_data = (CFDictionaryRef)read_user_settings(user_settings_path, kCFPropertyListMutableContainers);
	if ( !cf_dict_data )
			cf_dict_data = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
								&kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

	if ( cf_dict_data && in_user_dict ) {
		CFStringRef cf_str = CFStringCreateWithCString( NULL, in_user_guid, kCFStringEncodingUTF8 );
		if ( cf_str != NULL ) {
			CFMutableDictionaryRef cf_mut_dict = CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, cf_dict_data);
			if ( cf_mut_dict != NULL ) {
				CFDictionaryAddValue( cf_mut_dict, cf_str, in_user_dict );
				write_user_settings(user_settings_path, (CFPropertyListRef)cf_mut_dict );
				CFRelease(cf_mut_dict);
			}
			CFRelease(cf_str);
		}
	}
} /* set_attributes_local */
コード例 #3
0
ファイル: relink.c プロジェクト: Oxyoptia/x3270
/*
 * Read an existing session file.
 * Returns 1 for success (file read and editable), 0 for failure.
 */
int
read_session(FILE *f, session_t *s, char **usp)
{
    char buf[1024];
    int saw_hex = 0;
    int saw_star = 0;
    unsigned long csum;
    unsigned long fcsum = 0;
    int ver;
    int s_off = 0;

    /*
     * Look for the checksum and version.  Verify the version.
     *
     * XXX: It might be a good idea to validate each '!x' line and
     * make sure that the length is right.
     */
    while (fgets(buf, sizeof(buf), f) != NULL) {
	if (buf[0] == '!' && buf[1] == 'x')
	    saw_hex = 1;
	else if (buf[0] == '!' && buf[1] == '*')
	    saw_star = 1;
	else if (buf[0] == '!' && buf[1] == 'c') {
	    if (sscanf(buf + 2, "%lx %d", &csum, &ver) != 2) {
#if defined(DEBUG_EDIT) /*[*/
		printf("[bad !c line '%s']\n", buf);
#endif /*]*/
		return 0;
	    }
	    if (ver > WIZARD_VER) {
#if defined(DEBUG_EDIT) /*[*/
		printf("[bad ver %d > %d]\n", ver, WIZARD_VER);
#endif /*]*/
		return 0;
	    }
	}
    }
    if (!saw_hex || !saw_star) {
#if defined(DEBUG_EDIT) /*[*/
	printf("[missing%s%s]\n", saw_hex? "": "hex", saw_star? "": "star");
#endif /*]*/
	return 0;
    }

    /* Checksum from the top up to the '!c' line. */
    fflush(f);
    fseek(f, 0, SEEK_SET);
    fcsum = 0;
    while (fgets(buf, sizeof(buf), f) != NULL) {
	char *t;

	if (buf[0] == '!' && buf[1] == 'c') {
	    break;
	}

	for (t = buf; *t; t++) {
	    fcsum += *t & 0xff;
	}
    }
    if (fcsum != csum) {
#if defined(DEBUG_EDIT) /*[*/
	printf("[checksum mismatch, want 0x%08lx got 0x%08lx]\n", csum, fcsum);
#endif /*]*/
	return 0;
    }

    /* Once more, with feeling.  Scribble onto the session structure. */
    fflush(f);
    fseek(f, 0, SEEK_SET);
    s_off = 0;
    while (fgets(buf, sizeof(buf), f) != NULL) {

	if (buf[0] == '!' && buf[1] == 'x') {
	    char *t;

	    for (t = buf + 2; *t; t += 2) {
		if (*t == '\n') {
		    break;
		}
		if (s_off > sizeof(*s)) {
#if defined(DEBUG_EDIT) /*[*/
		    printf("[s overflow: %d > %d]\n", s_off, sizeof(*s));
#endif /*]*/
		    return 0;
		}
		((char *)s)[s_off++] = (hex(*t) << 4) | hex(*(t + 1));
	    }
	} else if (buf[0] == '!' && buf[1] == 'c') {
	    break;
	}
    }

    /*
     * Read the balance of the file into a temporary buffer, ignoring
     * the '!*' line.
     */
    if (usp != NULL && read_user_settings(f, usp) == 0) {
	return 0;
    }

    /* Success */
    return 1;
}