Beispiel #1
0
/**
 * Read file data into address cache.
 * Note that one LDIF record identifies one entity uniquely with the
 * distinguished name (dn) tag. Each person can have multiple E-Mail
 * addresses. Also, each person can have many common name (cn) tags.
 *
 * \param  ldifFile LDIF import control object.
 * \param  cache    Address cache to be populated with data.
 */
static void ldif_read_file( LdifFile *ldifFile, AddressCache *cache ) {
	gchar *tagName = NULL, *tagValue = NULL;
	gchar *lastTag = NULL, *fullValue = NULL;
	GSList *listValue = NULL;
	gboolean flagEOF = FALSE, flagEOR = FALSE;
	gboolean flag64 = FALSE, last64 = FALSE;
	Ldif_ParsedRec *rec;
	long posEnd = 0L;
	long posCur = 0L;
	GHashTable *hashField;
	gsize len;

	hashField = ldifFile->hashFields;
	rec = g_new0( Ldif_ParsedRec, 1 );
	ldif_clear_rec( rec );

	/* Find EOF for progress indicator */
	fseek( ldifFile->file, 0L, SEEK_END );
	posEnd = ftell( ldifFile->file );
	fseek( ldifFile->file, 0L, SEEK_SET );

	while( ! flagEOF ) {
		gchar *line =  ldif_get_line( ldifFile );

		posCur = ftell( ldifFile->file );
		if( ldifFile->cbProgress ) {
			/* Call progress indicator */
			( ldifFile->cbProgress ) ( ldifFile, & posEnd, & posCur );
		}

		flag64 = FALSE;
		if( line == NULL ) {
			flagEOF = flagEOR = TRUE;
		}
		else if( *line == '\0' ) {
			flagEOR = TRUE;
		}

		if( flagEOR ) {
			/* EOR, Output address data */
			if( lastTag ) {
				/* Save record */
				fullValue = mgu_list_coalesce( listValue );
				if (fullValue && last64) {
					gchar *tmp = g_base64_decode_zero(fullValue, &len);
					g_free(fullValue);
					fullValue = tmp;
				}

				ldif_add_value( rec, lastTag, fullValue, hashField );
				/* ldif_print_record( rec, stdout ); */
				ldif_build_items( ldifFile, rec, cache );
				ldif_clear_rec( rec );
				g_free( lastTag );
				mgu_free_list( listValue );
				g_free(fullValue);
				lastTag = NULL;
				listValue = NULL;
				last64 = FALSE;
			}
		}
		if( line ) {
			flagEOR = FALSE;
			if( *line == ' ' ) {
				/* Continuation line */
				listValue = g_slist_append(
					listValue, g_strdup( line+1 ) );
			}
			else if( *line == '=' ) {
				/* Base-64 encoded continuation field */
				listValue = g_slist_append(
					listValue, g_strdup( line ) );
			}
			else {
				/* Parse line */
				tagName = ldif_get_tagname( line, &flag64 );
				if( tagName ) {
					tagValue = ldif_get_tagvalue( line );
					if( tagValue ) {
						if( lastTag ) {
							/* Save data */
							fullValue =
								mgu_list_coalesce( listValue );
							if (fullValue && last64) {
								gchar *tmp = g_base64_decode_zero(fullValue, &len);
								g_free(fullValue);
								fullValue = tmp;
							}
							/* Base-64 encoded data */
							/*
							if( last64 ) {
								ldif_dump_b64( fullValue );
							}
							*/

							ldif_add_value(
								rec, lastTag, fullValue,
								hashField );
							g_free( lastTag );
							mgu_free_list( listValue );
							lastTag = NULL;
							listValue = NULL;
						}

						lastTag = g_strdup( tagName );
						listValue = g_slist_append(
							listValue,
							g_strdup( tagValue ) );
						g_free( tagValue );
						last64 = flag64;
					}
					g_free( tagName );
				}
			}
		}
		g_free( line );
	}

	/* Release data */
	ldif_clear_rec( rec );
	g_free( rec );
	g_free( lastTag );
	mgu_free_list( listValue );
}
Beispiel #2
0
static gint smtp_auth_recv(SMTPSession *session, const gchar *msg)
{
	gchar buf[MESSAGEBUFSIZE], *tmp;

	switch (session->auth_type) {
	case SMTPAUTH_LOGIN:
		session->state = SMTP_AUTH_LOGIN_USER;

		if (!strncmp(msg, "334 ", 4)) {
			tmp = g_base64_encode(session->user, strlen(session->user));

			if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL,
					 tmp) < 0) {
				g_free(tmp);
				return SM_ERROR;
			}
			g_free(tmp);
			log_print(LOG_PROTOCOL, "ESMTP> [USERID]\n");
		} else {
			/* Server rejects AUTH */
			if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL,
					 "*") < 0)
				return SM_ERROR;
			log_print(LOG_PROTOCOL, "ESMTP> *\n");
		}
		break;
	case SMTPAUTH_CRAM_MD5:
		session->state = SMTP_AUTH_CRAM_MD5;

		if (!strncmp(msg, "334 ", 4)) {
			gchar *response;
			gchar *response64;
			gchar *challenge;
			gsize challengelen;
			guchar hexdigest[33];

			challenge = g_base64_decode_zero(msg + 4, &challengelen);
			log_print(LOG_PROTOCOL, "ESMTP< [Decoded: %s]\n", challenge);

			g_snprintf(buf, sizeof(buf), "%s", session->pass);
			md5_hex_hmac(hexdigest, challenge, challengelen,
				     buf, strlen(session->pass));
			g_free(challenge);

			response = g_strdup_printf
				("%s %s", session->user, hexdigest);
			log_print(LOG_PROTOCOL, "ESMTP> [Encoded: %s]\n", response);

			response64 = g_base64_encode(response, strlen(response));
			g_free(response);

			if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL,
					 response64) < 0) {
				g_free(response64);
				return SM_ERROR;
			}
			log_print(LOG_PROTOCOL, "ESMTP> %s\n", response64);
			g_free(response64);
		} else {
			/* Server rejects AUTH */
			if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL,
					 "*") < 0)
				return SM_ERROR;
			log_print(LOG_PROTOCOL, "ESMTP> *\n");
		}
		break;
	case SMTPAUTH_DIGEST_MD5:
        default:
        	/* stop smtp_auth when no correct authtype */
		if (session_send_msg(SESSION(session), SESSION_MSG_NORMAL, "*") < 0)
			return SM_ERROR;
		log_print(LOG_PROTOCOL, "ESMTP> *\n");
		break;
	}

	return SM_OK;
}