torture: Test tevent_req_profile
[Samba.git] / examples / libsmbclient / get_auth_data_fn.h
blob5f2be72a633603766b897630cce4075ac0e563fb
1 #include <stdlib.h>
3 static void
4 get_auth_data_fn(const char * pServer,
5 const char * pShare,
6 char * pWorkgroup,
7 int maxLenWorkgroup,
8 char * pUsername,
9 int maxLenUsername,
10 char * pPassword,
11 int maxLenPassword)
13 char temp[128];
14 char server[256] = { '\0' };
15 char share[256] = { '\0' };
16 char workgroup[256] = { '\0' };
17 char username[256] = { '\0' };
18 char password[256] = { '\0' };
19 char *ret;
21 static int krb5_set = 1;
23 if (strcmp(server, pServer) == 0 &&
24 strcmp(share, pShare) == 0 &&
25 *workgroup != '\0' &&
26 *username != '\0')
28 strncpy(pWorkgroup, workgroup, maxLenWorkgroup - 1);
29 strncpy(pUsername, username, maxLenUsername - 1);
30 strncpy(pPassword, password, maxLenPassword - 1);
31 return;
34 if (krb5_set && getenv("KRB5CCNAME")) {
35 krb5_set = 0;
36 return;
39 fprintf(stdout, "Workgroup: [%s] ", pWorkgroup);
40 ret = fgets(temp, sizeof(temp), stdin);
41 if (ret == NULL) {
42 return;
45 if (temp[strlen(temp) - 1] == '\n') /* A new line? */
47 temp[strlen(temp) - 1] = '\0';
50 if (temp[0] != '\0')
52 strncpy(pWorkgroup, temp, maxLenWorkgroup - 1);
55 fprintf(stdout, "Username: [%s] ", pUsername);
56 ret = fgets(temp, sizeof(temp), stdin);
57 if (ret == NULL) {
58 return;
61 if (temp[strlen(temp) - 1] == '\n') /* A new line? */
63 temp[strlen(temp) - 1] = '\0';
66 if (temp[0] != '\0')
68 strncpy(pUsername, temp, maxLenUsername - 1);
71 fprintf(stdout, "Password: ");
72 ret = fgets(temp, sizeof(temp), stdin);
73 if (ret == NULL) {
74 return;
77 if (temp[strlen(temp) - 1] == '\n') /* A new line? */
79 temp[strlen(temp) - 1] = '\0';
82 if (temp[0] != '\0')
84 strncpy(pPassword, temp, maxLenPassword - 1);
87 strncpy(workgroup, pWorkgroup, sizeof(workgroup) - 1);
88 strncpy(username, pUsername, sizeof(username) - 1);
89 strncpy(password, pPassword, sizeof(password) - 1);
91 krb5_set = 1;