Add a (very!) trivial cache to the example authentication callback.
[kai/samba.git] / examples / libsmbclient / get_auth_data_fn.h
1 static void
2 get_auth_data_fn(const char * pServer,
3                  const char * pShare,
4                  char * pWorkgroup,
5                  int maxLenWorkgroup,
6                  char * pUsername,
7                  int maxLenUsername,
8                  char * pPassword,
9                  int maxLenPassword)
10 {
11     char            temp[128];
12     char            server[256] = { '\0' };
13     char            share[256] = { '\0' };
14     char            workgroup[256] = { '\0' };
15     char            username[256] = { '\0' };
16     char            password[256] = { '\0' };
17
18     if (strcmp(server, pServer) == 0 &&
19         strcmp(share, pShare) == 0 &&
20         *workgroup != '\0' &&
21         *username != '\0')
22     {
23         strncpy(pWorkgroup, workgroup, maxLenWorkgroup - 1);
24         strncpy(pUsername, username, maxLenUsername - 1);
25         strncpy(pPassword, password, maxLenPassword - 1);
26         return;
27     }
28     
29     fprintf(stdout, "Workgroup: [%s] ", pWorkgroup);
30     fgets(temp, sizeof(temp), stdin);
31     
32     if (temp[strlen(temp) - 1] == '\n') /* A new line? */
33     {
34         temp[strlen(temp) - 1] = '\0';
35     }
36     
37     if (temp[0] != '\0')
38     {
39         strncpy(pWorkgroup, temp, maxLenWorkgroup - 1);
40     }
41     
42     fprintf(stdout, "Username: [%s] ", pUsername);
43     fgets(temp, sizeof(temp), stdin);
44     
45     if (temp[strlen(temp) - 1] == '\n') /* A new line? */
46     {
47         temp[strlen(temp) - 1] = '\0';
48     }
49     
50     if (temp[0] != '\0')
51     {
52         strncpy(pUsername, temp, maxLenUsername - 1);
53     }
54     
55     fprintf(stdout, "Password: ");
56     fgets(temp, sizeof(temp), stdin);
57     
58     if (temp[strlen(temp) - 1] == '\n') /* A new line? */
59     {
60         temp[strlen(temp) - 1] = '\0';
61     }
62     
63     if (temp[0] != '\0')
64     {
65         strncpy(pPassword, temp, maxLenPassword - 1);
66     }
67
68     strncpy(workgroup, pWorkgroup, sizeof(workgroup) - 1);
69     strncpy(username, pUsername, sizeof(username) - 1);
70     strncpy(password, pPassword, sizeof(password) - 1);
71 }