022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik Lukas Slebodnik <slebodnikl@redhat.com>
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik Copyright (C) 2014 Red Hat
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik This program is free software; you can redistribute it and/or modify
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik it under the terms of the GNU General Public License as published by
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik the Free Software Foundation; either version 3 of the License, or
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik (at your option) any later version.
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik This program is distributed in the hope that it will be useful,
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik but WITHOUT ANY WARRANTY; without even the implied warranty of
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik GNU General Public License for more details.
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik You should have received a copy of the GNU General Public License
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik along with this program. If not, see <http://www.gnu.org/licenses/>.
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik const char *input_str = "Lorem ipsum dolor sit amet";
1f3127e88a87953f059c9a70d3582ae1719594b1Jakub Hrozek res = sss_replace_space(mem_ctx, input_str, '\0');
1f3127e88a87953f059c9a70d3582ae1719594b1Jakub Hrozek res = sss_replace_space(mem_ctx, input_str, '\0');
1f3127e88a87953f059c9a70d3582ae1719594b1Jakub Hrozek res = sss_replace_space(mem_ctx, data_set[i].input,
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik assert_string_equal(res, data_set[i].output);
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik assert_true(check_leaks_pop(mem_ctx) == true);
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnikvoid test_reverse_replace_whitespaces(void **state)
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik char *input_str = discard_const_p(char, "Lorem ipsum dolor sit amet");
1f3127e88a87953f059c9a70d3582ae1719594b1Jakub Hrozek res = sss_reverse_replace_space(mem_ctx, input_str, '\0');
1f3127e88a87953f059c9a70d3582ae1719594b1Jakub Hrozek res = sss_reverse_replace_space(mem_ctx, input_str, '\0');
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik input_str = discard_const_p(char, data_set[i].input);
1f3127e88a87953f059c9a70d3582ae1719594b1Jakub Hrozek res = sss_reverse_replace_space(mem_ctx, input_str,
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik assert_string_equal(res, data_set[i].output);
022c6b90bb37851c0e8704c0e5388ebc113c6470Lukas Slebodnik assert_true(check_leaks_pop(mem_ctx) == true);
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose /* How to get test data:
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose * The objectGUID attribute contains a 16byte long binary value
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose * representing the GUID of the object. This data can be converted
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose * manually to the string representation but it might be easier to use
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose * LDAP_SERVER_EXTENDED_DN_OID as described in [MS-ADST] section
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose * 3.1.1.3.4.1.5. This is an LDAP extended control which adds the GUID and
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose * the SID to the DN of an object. This can be activate with the -E
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose * ldapsearch option like:
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose * ldapsearch -E 1.2.840.113556.1.4.529=::MAMCAQE= ....
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose * where 'MAMCAQE=' is the base64 encoded BER sequence with the integer
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose * value 1 (see [MS-ADTS] for details about possible values).
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose * Btw, if you want to use the string representation of a GUID to search
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose * for an object in AD you have to use the GUID as the search base in the
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose * following form:
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose * ldapsearch b '<GUID=fea80d8d-dbd5-4f84-8574-7db0477f962e>' ...
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose * (please note that the '<' and '>' are really needed).
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose {{0x8d, 0x0d, 0xa8, 0xfe, 0xd5, 0xdb, 0x84, 0x4f,
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose "fea80d8d-dbd5-4f84-8574-7db0477f962e"},
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose {{0x91, 0x7e, 0x2e, 0xf8, 0x4e, 0x44, 0xfa, 0x4e,
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose "f82e7e91-444e-4efa-b113-089863496cc6"},
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose ret = guid_blob_to_string_buf(NULL, str_buf, GUID_STR_BUF_SIZE);
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose ret = guid_blob_to_string_buf((const uint8_t *) "1234567812345678", NULL,
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose ret = guid_blob_to_string_buf((const uint8_t *) "1234567812345678", str_buf, 0);
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose for (c = 0; test_data[c].guid_str != NULL; c++) {
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose ret = guid_blob_to_string_buf(test_data[c].blob, str_buf,
1d93029624d708119bbf803e6647a2cbb271f001Sumit Bose assert_string_equal(test_data[c].guid_str, str_buf);
a99845006f96f9d1e7af871ec67c71cee8408a62Sumit Bose const char *s;
28f336bdb32db0b89cb98174a3f8e308e4e928dbSumit Bose res = concatenate_string_array(mem_ctx, NULL, 0, NULL, 0);
28f336bdb32db0b89cb98174a3f8e308e4e928dbSumit Bose for (c = 0; c < a1_len; c++) {
28f336bdb32db0b89cb98174a3f8e308e4e928dbSumit Bose for (c = 0; c < a2_len; c++) {
28f336bdb32db0b89cb98174a3f8e308e4e928dbSumit Bose res = concatenate_string_array(mem_ctx, a1, a1_len, a2, a2_len);
28f336bdb32db0b89cb98174a3f8e308e4e928dbSumit Bose assert_string_equal(res[c], talloc_asprintf(res, "%zu", c));
28f336bdb32db0b89cb98174a3f8e308e4e928dbSumit Bose /* Since concatenate_string_array() uses talloc_realloc on a1 it should
28f336bdb32db0b89cb98174a3f8e308e4e928dbSumit Bose * not be needed to free a1 explicitly. */