### Enhanced Guide Example Source: https://github.com/samba-team/samba/blob/master/source4/ldap_server/devdocs/rfc4517.txt An example of an Enhanced Guide value, demonstrating the syntax for specifying search criteria and scope. ```ldap person#(sn$EQ)#oneLevel ``` -------------------------------- ### Install Make and Libtool (NetBSD) Source: https://github.com/samba-team/samba/blob/master/third_party/heimdal/lib/hcrypto/libtommath/doc/bn.tex On NetBSD, you may need to install 'gmake' and 'libtool' if they are not present. Use 'pkg_add' for installation. ```shell pkg_add gmake libtool ``` -------------------------------- ### Tevent Queue Example Source: https://github.com/samba-team/samba/blob/master/lib/tevent/doc/tevent_queue.dox This example demonstrates the setup and usage of a tevent queue in C. It includes functions for creating requests, handling timers, and processing queue items. The main function initializes the tevent context, creates a queue, adds requests to it, and then processes the queue until it is empty. ```c #include #include #include struct foo_state { int local_var; int x; }; struct juststruct { TALLOC_CTX * ctx; struct tevent_context *ev; int y; }; int created = 0; static void timer_handler(struct tevent_context *ev, struct tevent_timer *te, struct timeval current_time, void *private_data) { // time event which after all sets request as done. Following item from // the queue may be invoked. struct tevent_req *req = private_data; struct foo_state *stateX = tevent_req_data(req, struct foo_state); // processing some stuff printf("time_handler\n"); tevent_req_done(req); talloc_free(req); printf("Request #%d set as done.\n", stateX->x); } static void trigger(struct tevent_req *req, void *private_data) { struct juststruct *priv = tevent_req_callback_data (req, struct juststruct); struct foo_state *in = tevent_req_data(req, struct foo_state); struct timeval schedule; struct tevent_timer *tim; schedule = tevent_timeval_current_ofs(1, 0); printf("Processing request #%d\n", in->x); if (in->x % 3 == 0) { // just example; third request does not contain // any further operation and will be finished right // away. tim = NULL; } else { tim = tevent_add_timer(priv->ev, req, schedule, timer_handler, req); } if (tim == NULL) { tevent_req_done(req); talloc_free(req); printf("Request #%d set as done.\n", in->x); } } struct tevent_req *foo_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, const char *name, int num) { struct tevent_req *req; struct foo_state *state; struct foo_state *in; struct tevent_timer *tim; printf("foo_send\n"); req = tevent_req_create(mem_ctx, &state, struct foo_state); if (req == NULL) { // check for appropriate allocation tevent_req_error(req, 1); return NULL; } // exemplary filling of variables state->local_var = 1; state->x = num; return req; } static void foo_done(struct tevent_req *req) { enum tevent_req_state state; uint64_t err; if (tevent_req_is_error(req, &state, &err)) { printf("ERROR WAS SET %d\n", state); return; } else { // processing some stuff printf("Callback is done...\n"); } } int main (int argc, char **argv) { TALLOC_CTX *mem_ctx; struct tevent_req* req[6]; struct tevent_req* tmp; struct tevent_context *ev; struct tevent_queue *fronta = NULL; struct juststruct *data; int ret; int i = 0; const char * const names[] = { "first", "second", "third", "fourth", "fifth" }; printf("INIT\n"); mem_ctx = talloc_new(NULL); //parent talloc_parent(mem_ctx); ev = tevent_context_init(mem_ctx); if (ev == NULL) { fprintf(stderr, "MEMORY ERROR\n"); return EXIT_FAILURE; } // setting up queue fronta = tevent_queue_create(mem_ctx, "test_queue"); tevent_queue_stop(fronta); tevent_queue_start(fronta); if (tevent_queue_running(fronta)) { printf ("Queue is running (length: %d)\n", tevent_queue_length(fronta)); } else { printf ("Queue is not running\n"); } data = talloc(ev, struct juststruct); data->ctx = mem_ctx; data->ev = ev; // create 4 requests for (i = 1; i < 5; i++) { req[i] = foo_send(mem_ctx, ev, names[i], i); tmp = req[i]; if (req[i] == NULL) { fprintf(stderr, "Request error! %d \n", ret); break; } tevent_req_set_callback(req[i], foo_done, data); created++; } // add item to a queue tevent_queue_add(fronta, ev, req[1], trigger, data); tevent_queue_add(fronta, ev, req[2], trigger, data); tevent_queue_add(fronta, ev, req[3], trigger, data); tevent_queue_add(fronta, ev, req[4], trigger, data); printf("Queue length: %d\n", tevent_queue_length(fronta)); while(tevent_queue_length(fronta) > 0) { tevent_loop_once(ev); printf("Queue: %d items left\n", tevent_queue_length(fronta)); } talloc_free(mem_ctx); printf("FINISH\n"); return EXIT_SUCCESS; } ``` -------------------------------- ### Example Output Source: https://github.com/samba-team/samba/blob/master/lib/tevent/doc/tevent_data.dox This is the expected output when running the full tevent data access example. ```text a->x: 10 b->y: 9 c->y: 9 ``` -------------------------------- ### Client GET Request Example Source: https://github.com/samba-team/samba/blob/master/third_party/heimdal/doc/standardisation/draft-brezak-kerberos-http-00.txt An example of a client initiating a GET request for a document without an initial Authorization header. This is typically the first step in the authentication process. ```plaintext C: GET dir/index.html ``` -------------------------------- ### Full Example of Tevent Data Access Source: https://github.com/samba-team/samba/blob/master/lib/tevent/doc/tevent_data.dox This example demonstrates the usage of `tevent_req_data` for accessing request-bound data and `tevent_req_callback_data` (and `tevent_req_callback_data_void`) for accessing callback arguments. It includes setup, request creation, callback registration, and event loop execution. ```c #include #include #include struct foo_state { int x; }; struct testA { int y; }; static void foo_done(struct tevent_req *req) { // a->x contains 10 since it came from foo_send struct foo_state *a = tevent_req_data(req, struct foo_state); // b->y contains 9 since it came from run struct testA *b = tevent_req_callback_data(req, struct testA); // c->y contains 9 since it came from run we just used a different way // of getting it. struct testA *c = (struct testA *)tevent_req_callback_data_void(req); printf("a->x: %d\n", a->x); printf("b->y: %d\n", b->y); printf("c->y: %d\n", c->y); } struct tevent_req * foo_send(TALLOC_CTX *mem_ctx, struct tevent_context *event_ctx) { printf("_send\n"); struct tevent_req *req; struct foo_state *state; req = tevent_req_create(event_ctx, &state, struct foo_state); state->x = 10; return req; } static void run(struct tevent_context *ev, struct tevent_timer *te, struct timeval current_time, void *private_data) { struct tevent_req *req; struct testA *tmp = talloc(ev, struct testA); // Note that we did not use the private data passed in tmp->y = 9; req = foo_send(ev, ev); tevent_req_set_callback(req, foo_done, tmp); tevent_req_done(req); } int main (int argc, char **argv) { struct tevent_context *event_ctx; struct testA *data; TALLOC_CTX *mem_ctx; struct tevent_timer *time_event; mem_ctx = talloc_new(NULL); //parent if (mem_ctx == NULL) return EXIT_FAILURE; event_ctx = tevent_context_init(mem_ctx); if (event_ctx == NULL) return EXIT_FAILURE; data = talloc(mem_ctx, struct testA); data->y = 11; time_event = tevent_add_timer(event_ctx, mem_ctx, tevent_timeval_current(), run, data); if (time_event == NULL) { fprintf(stderr, " FAILED\n"); return EXIT_FAILURE; } tevent_loop_once(event_ctx); talloc_free(mem_ctx); printf("Quit\n"); return EXIT_SUCCESS; } ``` -------------------------------- ### C# GSSAPI Client Example Source: https://github.com/samba-team/samba/blob/master/third_party/heimdal/doc/standardisation/draft-morris-java-gssapi-update-for-csharp-00.txt A client-side example demonstrating the use of GSSAPI in C# for establishing a security context. ```C# using ietf.org.gss; class GssapiClient { private static TcpClient client; private static NetworkStream stream; static void Main(string[] args) { Connect("127.0.0.1", "message from client"); try { GSSManager manager = GSSManager.getInstance(); Oid krb5Mechanism = new Oid("1.2.840.113554.1.2.2"); Oid krb5PrincipalNameType = new Oid("1.2.840.113554.1.2.2.1"); // Optionally Identify who the client wishes to be // GSSName name = manager.createName("test@gsserver", GSSName.NT_USER_NAME); // Obtain default credential GSSCredential userCreds = manager.createCredential(GSSCredential.INITIATE_ONLY); GSSName name = userCreds.getName(krb5PrincipalNameType); Console.WriteLine("Just acquired credentials for " + name.toString()); int acceptLife = userCreds.getRemainingAcceptLifetime(new Oid("2.3.4")); int initLife = userCreds.getRemainingInitLifetime(new Oid("1..3.")); int remLife = userCreds.getRemainingLifetime(); int usage = userCreds.getUsage(); GSSName namea = userCreds.getName(); Oid[] oa = userCreds.getMechs(); // Instantiate and initialize a security context that will be // established with the server GSSContext context = manager.createContext(name, krb5Mechanism, userCreds, GSSContext.DEFAULT_LIFETIME); userCreds.dispose(); // Optionally Set Context Options, must be done before iniSecContext call context.requestMutualAuth(true); context.requestConf(true); context.requestInteg(true); context.requestSequenceDet(true); context.requestCredDeleg(true); MemoryStream ins = new MemoryStream(); MemoryStream outs = new MemoryStream(); ``` -------------------------------- ### Setup Test Environment Source: https://github.com/samba-team/samba/blob/master/source4/selftest/provisions/release-4-1-0rc3/steps-to-reproduce.txt Configures the test environment, ensuring MASTER_SRC points to the schema files. ```bash SELFTEST_TESTENV=promoted_dc:local make testenv ``` -------------------------------- ### Client Initial GET Request (No Authorization) Source: https://github.com/samba-team/samba/blob/master/third_party/heimdal/doc/standardisation/draft-brezak-spnego-http-02.txt Example of a client's initial GET request for a document when no Authorization header is sent, expecting a 401 Unauthorized response from the server. ```http C: GET dir/index.html ``` -------------------------------- ### LDAP URL Examples for SearchResultReference Source: https://github.com/samba-team/samba/blob/master/source4/ldap_server/devdocs/rfc4511.txt These examples illustrate the structure of LDAP URLs used in SearchResultReferences. They show how the DN, filter, and scope are specified to guide the client's next search request. ```text ldap://hostb/OU=People,DC=Example,DC=NET??sub ``` ```text ldap://hostc/OU=People,DC=Example,DC=NET??sub ``` ```text ldap://hostd/OU=Roles,DC=Example,DC=NET??sub ``` ```text ldap://hoste/OU=Managers,OU=People,DC=Example,DC=NET??sub ``` ```text ldap://hostf/OU=Consultants,OU=People,DC=Example,DC=NET??sub ``` ```text ldap://hostb/OU=People,DC=Example,DC=NET??base ``` ```text ldap://hostc/OU=People,DC=Example,DC=NET??base ``` ```text ldap://hostd/OU=Roles,DC=Example,DC=NET??base ``` -------------------------------- ### Sample 40-bit Key Derivation - Step 1 Source: https://github.com/samba-team/samba/blob/master/third_party/heimdal/doc/standardisation/rfc3079.txt Illustrates Step 1 of the 40-bit key derivation: calculating the PasswordHash from the Password. ```c Step 1: NtPasswordHash(Password, PasswordHash) PasswordHash = 44 EB BA 8D 53 12 B8 D6 11 47 44 11 F5 69 89 AE ``` -------------------------------- ### Set up Visual Studio Build Environment Source: https://github.com/samba-team/samba/blob/master/third_party/heimdal/windows/README.md Use vcvarsall.bat to set up a Visual Studio build environment for a specific architecture and Windows SDK version. The Debug/Release choice is made on the nmake command line. ```batch vcvarsall.bat x64 10.0.19041.0 -vcvars_ver=14.29 -vcvars_spectre_libs=spectre ``` -------------------------------- ### Expected Output for Initialization Example Source: https://github.com/samba-team/samba/blob/master/third_party/heimdal/lib/hcrypto/libtommath/doc/bn.tex This is the expected output when the provided C example program for mp_init_set and mp_init_l is executed successfully. ```text Number1, Number2 == 100, 1023 ``` -------------------------------- ### Install GNU Make and Libtool (OpenBSD) Source: https://github.com/samba-team/samba/blob/master/third_party/heimdal/lib/hcrypto/libtommath/doc/bn.tex On OpenBSD, you may need to install the GNU versions of 'make' and 'libtool' to successfully build shared libraries. This command installs them via pkg_add. ```shell $ sudo pkg_add gmake libtool ``` -------------------------------- ### Key Derivation Example Source: https://github.com/samba-team/samba/blob/master/third_party/heimdal/doc/standardisation/draft-ietf-krb-wg-crypto-03.txt Shows the derivation of a temporary key and the final key using helper functions. ```text tempkey = key_correction(add_parity_bits(tempstring)); ;; tempkey ;; `\xc1\x1f8h\x8a\xc8m\x2f' (length 8 bytes) ;; c1 1f 38 68 8a c8 6d 2f ;; 11000001 00011111 00111000 01101000 10001010 11001000 ;; 01101101 00101111 key = key_correction(DES-CBC-check(s,tempkey)); ;; key ;; `\xcb\xc2\x2f\xae\x23R\x98\xe3' (length 8 bytes) ;; cb c2 2f ae 23 52 98 e3 ;; 11001011 11000010 00101111 10101110 00100011 01010010 ;; 10011000 11100011 ;; string_to_key key: ;; `\xcb\xc2\x2f\xae\x23R\x98\xe3' (length 8 bytes) ;; cb c2 2f ae 23 52 98 e3 ``` -------------------------------- ### DES Key Generation Example 3 Source: https://github.com/samba-team/samba/blob/master/third_party/heimdal/doc/standardisation/rfc3961.txt Example with Unicode characters in salt and password. ```text salt: "ATHENA.MIT.EDUJuri" + s-caron(U+0161) + "i" + c-acute(U+0107) 415448454e412e4d49542e4544554a757269c5a169c487 password: eszett(U+00DF) c39f fan-fold result:b8f6c40e305afc9e intermediate key: b9f7c40e315bfd9e DES key: 62c81a5232b5e69d ``` -------------------------------- ### FTP OPTS MLST Command Example Source: https://github.com/samba-team/samba/blob/master/third_party/heimdal/doc/standardisation/draft-ietf-ftpext-mlst-08.txt Demonstrates the OPTS command to set MLST options, specifying which facts should be returned in subsequent MLST commands. The server confirms the selected options. ```ftp C> OPTS mlst unique;size; S> 201 MLST OPTS Size;Unique; ``` ```ftp C> OPTS mlst unique;type;modify; S> 201 MLST OPTS Type;Modify;Unique; ``` ```ftp C> OPTS mlst fish;cakes; S> 201 MLST OPTS ``` ```ftp C> opts MLst fish cakes; S> 501 Invalid MLST options ``` ```ftp C> OPTS MLst Modify;Unique; S> 201 MLST OPTS Modify;Unique; ``` -------------------------------- ### DES Key Generation Example 2 Source: https://github.com/samba-team/samba/blob/master/third_party/heimdal/doc/standardisation/rfc3961.txt Example with a password containing a Unicode character. ```text salt: "EXAMPLE.COMpianist" 4558414D504C452E434F4D7069616E697374 password: g-clef (U+1011E) f09d849e fan-fold result: 3c4a262c18fab090 intermediate key: 3d4a262c19fbb091 ``` -------------------------------- ### DES3 string_to_key Examples Source: https://github.com/samba-team/samba/blob/master/third_party/heimdal/doc/standardisation/draft-ietf-krb-wg-crypto-07.txt Demonstrates keys generated from input strings using the DES3 string-to-key derivation function. These examples show the resulting key for different salt and password combinations. ```text salt: "ATHENA.MIT.EDUraeburn" passwd: "password" key: 850bb51358548cd05e86768c313e3bfef7511937dcf72c3e ``` ```text salt: "WHITEHOUSE.GOVdanny" passwd: "potatoe" key: dfcd233dd0a43204ea6dc437fb15e061b02979c1f74f377a ``` ```text salt: "EXAMPLE.COMbuckaroo" passwd: "penny" key: 6d2fcdf2d6fbbc3ddcadb5da5710a23489b0d3b69d5d9d4a ``` ```text salt: "ATHENA.MIT.EDUJuri" + s-caron(U+0161) + "i" + c-acute(U+0107) passwd: eszett(U+00DF) key: 16d5a40e1ce3bacb61b9dce00470324c831973a7b952feb0 ``` ```text salt: "EXAMPLE.COMpianist" passwd: g-clef(U+1011E) key: 85763726585dbc1cce6ec43e1f751f07f1c4cbb098f40b19 ``` -------------------------------- ### SHISHI KDC-REQ Example Source: https://github.com/samba-team/samba/blob/master/third_party/heimdal/doc/standardisation/draft-josefsson-sasl-kerberos5-01.txt An example of a KDC-REQ packet encoded using the SHISHI format. ```base64 an4wfKEDAgEFogMCAQqkcDBuoAcDBQAAAAAAoRAwDqADAgEAoQcwBRsDamFzogsb CWxvY2FsaG9zdKMcMBqgAwIBAKETMBEbBGltYXAbCWxvY2FsaG9zdKURGA8yMDAz MDIwMjE2NDE0M1qnBgIEVAbYn6gLMAkCARECARACAQM= ``` -------------------------------- ### Numeric String Example Source: https://github.com/samba-team/samba/blob/master/source4/ldap_server/devdocs/rfc4517.txt An example of a Numeric String, which is a sequence of one or more numerals and spaces. ```text 15 079 672 281 ``` -------------------------------- ### Build Multi-Platform Installer Source: https://github.com/samba-team/samba/blob/master/third_party/heimdal/windows/README.md To build a multi-platform installer package, set MULTIPLATFORM_INSTALLER=1 and build for both X86 and AMD64 on the same machine. First build for X86, then for AMD64. ```makefile nmake /f NTMakefile MULTIPLATFORM_INSTALLER=1 ``` -------------------------------- ### Set up Windows SDK Build Environment Source: https://github.com/samba-team/samba/blob/master/third_party/heimdal/windows/README.md Use SetEnv.Cmd to configure the build environment for a specific Windows version and architecture. Specify Debug or Release binaries. ```batch SetEnv.Cmd /xp /x64 /Debug ``` ```batch SetEnv.Cmd /xp /x64 /Release ``` -------------------------------- ### ASN.1 Linked List Example Source: https://github.com/samba-team/samba/blob/master/third_party/heimdal/lib/asn1/MANUAL.md The equivalent of the XDR linked list example, written in ASN.1. ```ASN.1 Stringentry ::= SEQUENCE { item UTF8String, next Stringentry OPTIONAL } ```