Blame library/adprivate.h

Packit Service 6d40f9
/*
Packit Service 6d40f9
 * adcli
Packit Service 6d40f9
 *
Packit Service 6d40f9
 * Copyright (C) 2012 Red Hat Inc.
Packit Service 6d40f9
 *
Packit Service 6d40f9
 * This program is free software; you can redistribute it and/or modify
Packit Service 6d40f9
 * it under the terms of the GNU Lesser General Public License as
Packit Service 6d40f9
 * published by the Free Software Foundation; either version 2.1 of
Packit Service 6d40f9
 * the License, or (at your option) any later version.
Packit Service 6d40f9
 *
Packit Service 6d40f9
 * This program is distributed in the hope that it will be useful, but
Packit Service 6d40f9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 6d40f9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 6d40f9
 * Lesser General Public License for more details.
Packit Service 6d40f9
 *
Packit Service 6d40f9
 * You should have received a copy of the GNU Lesser General Public
Packit Service 6d40f9
 * License along with this program; if not, write to the Free Software
Packit Service 6d40f9
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
Packit Service 6d40f9
 * MA 02110-1301 USA
Packit Service 6d40f9
 *
Packit Service 6d40f9
 * Author: Stef Walter <stefw@gnome.org>
Packit Service 6d40f9
 */
Packit Service 6d40f9
Packit Service 6d40f9
#ifndef ADPRIVATE_H_
Packit Service 6d40f9
#define ADPRIVATE_H_
Packit Service 6d40f9
Packit Service 6d40f9
#include "adattrs.h"
Packit Service 6d40f9
#include "adconn.h"
Packit Service 6d40f9
Packit Service 6d40f9
#include <stdarg.h>
Packit Service 6d40f9
#include <limits.h>
Packit Service 6d40f9
#include <stdlib.h>
Packit Service 6d40f9
#include <stdio.h>
Packit Service 384833
#include <stdint.h>
Packit Service 6d40f9
Packit Service 6d40f9
#include <ldap.h>
Packit Service 6d40f9
Packit Service 6d40f9
#ifndef HOST_NAME_MAX
Packit Service 6d40f9
#define HOST_NAME_MAX 255
Packit Service 6d40f9
#endif
Packit Service 6d40f9
Packit Service 6d40f9
/* Utilities */
Packit Service 6d40f9
Packit Service 6d40f9
#if !defined(__cplusplus) && (__GNUC__ > 2)
Packit Service 6d40f9
#define GNUC_PRINTF(x, y) __attribute__((__format__(__printf__, x, y)))
Packit Service 6d40f9
#define GNUC_WARN_UNUSED __attribute__((warn_unused_result))
Packit Service 6d40f9
#else
Packit Service 6d40f9
#define GNUC_PRINTF(x, y)
Packit Service 6d40f9
#define GNUC_WARN_UNUSED
Packit Service 6d40f9
#endif
Packit Service 6d40f9
Packit Service 6d40f9
/* For detecting clang features */
Packit Service 6d40f9
#ifndef __has_feature
Packit Service 6d40f9
#define __has_feature(x) 0
Packit Service 6d40f9
#endif
Packit Service 6d40f9
Packit Service 6d40f9
#ifndef CLANG_ANALYZER_NORETURN
Packit Service 6d40f9
#if __has_feature(attribute_analyzer_noreturn)
Packit Service 6d40f9
#define CLANG_ANALYZER_NORETURN __attribute__((analyzer_noreturn))
Packit Service 6d40f9
#else
Packit Service 6d40f9
#define CLANG_ANALYZER_NORETURN
Packit Service 6d40f9
#endif
Packit Service 6d40f9
#endif
Packit Service 6d40f9
Packit Service 6d40f9
#define return_val_if_fail(x, v) \
Packit Service 6d40f9
	do { if (!(x)) { \
Packit Service 6d40f9
	     _adcli_precond_failed ("adcli: '%s' not true at %s\n", #x, __func__); \
Packit Service 6d40f9
	     return v; \
Packit Service 6d40f9
	} } while (0)
Packit Service 6d40f9
Packit Service 6d40f9
#define return_unexpected_if_fail(x) \
Packit Service 6d40f9
	return_val_if_fail ((x), ADCLI_ERR_UNEXPECTED)
Packit Service 6d40f9
Packit Service 6d40f9
#define return_if_fail(x) \
Packit Service 6d40f9
	do { if (!(x)) { \
Packit Service 6d40f9
	     _adcli_precond_failed ("adcli: '%s' not true at %s\n", #x, __func__); \
Packit Service 6d40f9
	     return; \
Packit Service 6d40f9
	} } while (0)
Packit Service 6d40f9
Packit Service 6d40f9
#define return_if_reached() \
Packit Service 6d40f9
	do { \
Packit Service 6d40f9
	     _adcli_precond_failed ("adcli: shouldn't be reached at %s\n", __func__); \
Packit Service 6d40f9
	     return; \
Packit Service 6d40f9
	} while (0)
Packit Service 6d40f9
Packit Service 6d40f9
#define return_val_if_reached(v) \
Packit Service 6d40f9
	do { \
Packit Service 6d40f9
	     _adcli_precond_failed ("adcli: shouldn't be reached at %s\n", __func__); \
Packit Service 6d40f9
	     return v; \
Packit Service 6d40f9
	} while (0)
Packit Service 6d40f9
Packit Service 6d40f9
#define return_unexpected_if_reached() \
Packit Service 6d40f9
	return_val_if_reached (ADCLI_ERR_UNEXPECTED)
Packit Service 6d40f9
Packit Service 6d40f9
void           _adcli_precond_failed         (const char *message,
Packit Service 6d40f9
                                              ...) GNUC_PRINTF (1, 2)
Packit Service 6d40f9
                                              CLANG_ANALYZER_NORETURN;
Packit Service 6d40f9
Packit Service 6d40f9
void           _adcli_err                    (const char *format,
Packit Service 6d40f9
                                             ...) GNUC_PRINTF(1, 2);
Packit Service 6d40f9
Packit Service 6d40f9
void           _adcli_warn                   (const char *format,
Packit Service 6d40f9
                                             ...) GNUC_PRINTF(1, 2);
Packit Service 6d40f9
Packit Service 6d40f9
void           _adcli_info                   (const char *format,
Packit Service 6d40f9
                                             ...) GNUC_PRINTF(1, 2);
Packit Service 6d40f9
Packit Service 6d40f9
int            _adcli_strv_len               (char **strv);
Packit Service 6d40f9
Packit Service 6d40f9
char **        _adcli_strv_add               (char **strv,
Packit Service 6d40f9
                                              char *string,
Packit Service 6d40f9
                                              int *length) GNUC_WARN_UNUSED;
Packit Service 6d40f9
Packit Service 6d40f9
void           _adcli_strv_free              (char **strv);
Packit Service 6d40f9
Packit Service 6d40f9
int            _adcli_strv_has               (char **strv,
Packit Service 6d40f9
                                              const char *str);
Packit Service 6d40f9
Packit Service 6d40f9
char **        _adcli_strv_dup               (char **strv) GNUC_WARN_UNUSED;
Packit Service 6d40f9
Packit Service 6d40f9
char *         _adcli_strv_join              (char **strv,
Packit Service 6d40f9
                                              const char *delim);
Packit Service 6d40f9
Packit Service 6d40f9
void           _adcli_str_up                 (char *str);
Packit Service 6d40f9
Packit Service 6d40f9
void           _adcli_str_down               (char *str);
Packit Service 6d40f9
Packit Service 6d40f9
int            _adcli_str_is_up              (const char *str);
Packit Service 6d40f9
Packit Service 6d40f9
int            _adcli_str_has_prefix         (const char *str,
Packit Service 6d40f9
		                              const char *prefix);
Packit Service 6d40f9
Packit Service 6d40f9
int            _adcli_str_has_suffix         (const char *str,
Packit Service 6d40f9
		                              const char *suffix);
Packit Service 6d40f9
Packit Service 384833
char *          _adcli_bin_sid_to_str        (const uint8_t *data,
Packit Service 384833
                                              size_t len);
Packit Service 384833
Packit Service 6d40f9
char *         _adcli_str_dupn               (void *data,
Packit Service 6d40f9
                                              size_t len);
Packit Service 6d40f9
Packit Service 6d40f9
void           _adcli_str_set                (char **field,
Packit Service 6d40f9
                                              const char *value);
Packit Service 6d40f9
Packit Service 6d40f9
void           _adcli_strv_set               (char ***field,
Packit Service 6d40f9
                                              const char **value);
Packit Service 6d40f9
Packit Service 6d40f9
int            _adcli_password_free          (char *password);
Packit Service 6d40f9
Packit Service 6d40f9
int            _adcli_write_all              (int fd,
Packit Service 6d40f9
                                              const char *buf,
Packit Service 6d40f9
                                              int len);
Packit Service 6d40f9
Packit Service 6d40f9
/* Connection helpers */
Packit Service 6d40f9
Packit Service 6d40f9
char *        _adcli_calc_reset_password     (const char *computer_name);
Packit Service 6d40f9
Packit Service 6d40f9
char *        _adcli_calc_netbios_name       (const char *host_fqdn);
Packit Service 6d40f9
Packit Service 6d40f9
krb5_error_code  _adcli_kinit_computer_creds      (adcli_conn *conn,
Packit Service 6d40f9
                                                   const char *in_tkt_service,
Packit Service 6d40f9
                                                   krb5_ccache ccache,
Packit Service 6d40f9
                                                   krb5_creds *creds);
Packit Service 6d40f9
Packit Service 6d40f9
krb5_error_code  _adcli_kinit_user_creds          (adcli_conn *conn,
Packit Service 6d40f9
                                                   const char *in_tkt_service,
Packit Service 6d40f9
                                                   krb5_ccache ccache,
Packit Service 6d40f9
                                                   krb5_creds *creds);
Packit Service 6d40f9
Packit Service 6d40f9
/* LDAP helpers */
Packit Service 6d40f9
Packit Service 6d40f9
adcli_result  _adcli_ldap_handle_failure     (LDAP *ldap,
Packit Service 6d40f9
                                              adcli_result defres,
Packit Service 6d40f9
                                              const char *desc,
Packit Service 6d40f9
                                              ...) GNUC_PRINTF(3, 4);
Packit Service 6d40f9
Packit Service 7f07f7
char *         _adcli_ldap_parse_sid         (LDAP *ldap,
Packit Service 7f07f7
                                              LDAPMessage *results,
Packit Service 7f07f7
                                              const char *attr_name);
Packit Service 7f07f7
Packit Service 6d40f9
char *        _adcli_ldap_parse_value        (LDAP *ldap,
Packit Service 6d40f9
                                              LDAPMessage *results,
Packit Service 6d40f9
                                              const char *attr_name);
Packit Service 6d40f9
Packit Service 6d40f9
char **       _adcli_ldap_parse_values       (LDAP *ldap,
Packit Service 6d40f9
                                              LDAPMessage *results,
Packit Service 6d40f9
                                              const char *attr_name);
Packit Service 6d40f9
Packit Service 6d40f9
char *        _adcli_ldap_parse_dn           (LDAP *ldap,
Packit Service 6d40f9
                                              LDAPMessage *results);
Packit Service 6d40f9
Packit Service 6d40f9
int           _adcli_ldap_ber_case_equal     (struct berval *one,
Packit Service 6d40f9
                                              struct berval *two);
Packit Service 6d40f9
Packit Service 6d40f9
int           _adcli_ldap_have_vals          (struct berval **want,
Packit Service 6d40f9
                                              struct berval **have);
Packit Service 6d40f9
Packit Service 6d40f9
int           _adcli_ldap_have_in_mod        (LDAPMod *want,
Packit Service 6d40f9
                                              struct berval **have);
Packit Service 6d40f9
Packit Service 6d40f9
char *        _adcli_ldap_escape_filter      (const char *value);
Packit Service 6d40f9
Packit Service 6d40f9
int           _adcli_ldap_dn_has_ancestor    (const char *dn,
Packit Service 6d40f9
                                              const char *ancestor);
Packit Service 6d40f9
Packit Service 6d40f9
int           _adcli_ldap_mod_compar         (void *match,
Packit Service 6d40f9
                                              void *mod);
Packit Service 6d40f9
Packit Service 6d40f9
int           _adcli_ldap_filter_for_add     (void *unused,
Packit Service 6d40f9
                                              void *mod);
Packit Service 6d40f9
Packit Service 6d40f9
LDAPMod *     _adcli_ldap_mod_new            (int mod_op,
Packit Service 6d40f9
                                              const char *type,
Packit Service 6d40f9
                                              const char **values);
Packit Service 6d40f9
Packit Service 6d40f9
LDAPMod *     _adcli_ldap_mod_new1           (int mod_op,
Packit Service 6d40f9
                                              const char *type,
Packit Service 6d40f9
                                              const char *value);
Packit Service 6d40f9
Packit Service 6d40f9
void          _adcli_ldap_mod_free           (void *mod);
Packit Service 6d40f9
Packit Service 6d40f9
char *        _adcli_ldap_mods_to_string     (LDAPMod **mods);
Packit Service 6d40f9
Packit Service 6d40f9
/* KRB5 helpers */
Packit Service 6d40f9
Packit Service 6d40f9
adcli_result     _adcli_krb5_init_context         (krb5_context *k5);
Packit Service 6d40f9
Packit Service 6d40f9
adcli_result     _adcli_krb5_open_keytab          (krb5_context k5,
Packit Service 6d40f9
                                                   const char *keytab_name,
Packit Service 6d40f9
                                                   krb5_keytab *keytab);
Packit Service 6d40f9
Packit Service 6d40f9
krb5_error_code  _adcli_krb5_build_principal      (krb5_context k5,
Packit Service 6d40f9
                                                   const char *user,
Packit Service 6d40f9
                                                   const char *realm,
Packit Service 6d40f9
                                                   krb5_principal *principal);
Packit Service 6d40f9
Packit Service 6d40f9
krb5_error_code  _adcli_krb5_keytab_clear         (krb5_context k5,
Packit Service 6d40f9
                                                   krb5_keytab keytab,
Packit Service 6d40f9
                                                   krb5_boolean (* match_func) (krb5_context,
Packit Service 6d40f9
                                                                krb5_keytab_entry *, void *),
Packit Service 6d40f9
                                                   void *match_data);
Packit Service 6d40f9
Packit Service 6d40f9
krb5_error_code  _adcli_krb5_keytab_clear_all     (krb5_context k5,
Packit Service 6d40f9
                                                   krb5_keytab keytab);
Packit Service 6d40f9
Packit Service 6d40f9
krb5_error_code  _adcli_krb5_keytab_enumerate     (krb5_context k5,
Packit Service 6d40f9
                                                   krb5_keytab keytab,
Packit Service 6d40f9
                                                   krb5_boolean (* match_func) (krb5_context,
Packit Service 6d40f9
                                                                krb5_keytab_entry *, void *),
Packit Service 6d40f9
                                                   void *match_data);
Packit Service 6d40f9
Packit Service 6d40f9
krb5_error_code  _adcli_krb5_keytab_add_entries   (krb5_context k5,
Packit Service 6d40f9
                                                   krb5_keytab keytab,
Packit Service 6d40f9
                                                   krb5_principal princpal,
Packit Service 6d40f9
                                                   krb5_kvno kvno,
Packit Service 6d40f9
                                                   krb5_data *password,
Packit Service 6d40f9
                                                   krb5_enctype *enctypes,
Packit Service 6d40f9
                                                   krb5_data *salt);
Packit Service 6d40f9
Packit Service 6d40f9
krb5_error_code  _adcli_krb5_keytab_test_salt     (krb5_context k5,
Packit Service 6d40f9
                                                   krb5_keytab scratch,
Packit Service 6d40f9
                                                   krb5_principal principal,
Packit Service 6d40f9
                                                   krb5_kvno kvno,
Packit Service 6d40f9
                                                   krb5_data *password,
Packit Service 6d40f9
                                                   krb5_enctype *enctypes,
Packit Service 6d40f9
                                                   krb5_data *salt);
Packit Service 6d40f9
Packit Service 6d40f9
krb5_error_code  _adcli_krb5_keytab_discover_salt (krb5_context k5,
Packit Service 6d40f9
                                                   krb5_principal principal,
Packit Service 6d40f9
                                                   krb5_kvno kvno,
Packit Service 6d40f9
                                                   krb5_data *password,
Packit Service 6d40f9
                                                   krb5_enctype *enctypes,
Packit Service 6d40f9
                                                   krb5_data *salts,
Packit Service 6d40f9
                                                   int *discovered);
Packit Service 6d40f9
Packit Service 6d40f9
krb5_error_code  _adcli_krb5_w2k3_salt            (krb5_context k5,
Packit Service 6d40f9
                                                   krb5_principal principal,
Packit Service 6d40f9
                                                   const char *host_netbios,
Packit Service 6d40f9
                                                   krb5_data *salt);
Packit Service 6d40f9
Packit Service 6d40f9
krb5_enctype *   _adcli_krb5_parse_enctypes       (const char *value);
Packit Service 6d40f9
Packit Service 6d40f9
char *           _adcli_krb5_format_enctypes      (krb5_enctype *enctypes);
Packit Service 6d40f9
Packit Service 6d40f9
struct _adcli_attrs {
Packit Service 6d40f9
	LDAPMod **mods;
Packit Service 6d40f9
	int len;
Packit Service 6d40f9
};
Packit Service 6d40f9
Packit Service 6d40f9
bool             _adcli_check_nt_time_string_lifetime (const char *nt_time_string, unsigned int lifetime);
Packit Service 6d40f9
Packit Service 637682
adcli_result     _adcli_call_external_program     (const char *binary,
Packit Service 637682
                                                   char * const *argv,
Packit Service 637682
                                                   const char *stdin_data,
Packit Service 637682
                                                   uint8_t **stdout_data,
Packit Service 637682
                                                   size_t *stdout_data_len);
Packit Service 637682
Packit Service 6d40f9
#endif /* ADPRIVATE_H_ */