examples: rework wscript to use a loop
[samba.git] / examples / libsmbclient / get_auth_data_fn.h
1 #include <stdlib.h>
2
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)
12 {
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
20     static int krb5_set = 1;
21
22     if (strcmp(server, pServer) == 0 &&
23         strcmp(share, pShare) == 0 &&
24         *workgroup != '\0' &&
25         *username != '\0')
26     {
27         strncpy(pWorkgroup, workgroup, maxLenWorkgroup - 1);
28         strncpy(pUsername, username, maxLenUsername - 1);
29         strncpy(pPassword, password, maxLenPassword - 1);
30         return;
31     }
32
33     if (krb5_set && getenv("KRB5CCNAME")) {
34       krb5_set = 0;
35       return;
36     }
37
38     fprintf(stdout, "Workgroup: [%s] ", pWorkgroup);
39     fgets(temp, sizeof(temp), stdin);
40     
41     if (temp[strlen(temp) - 1] == '\n') /* A new line? */
42     {
43         temp[strlen(temp) - 1] = '\0';
44     }
45     
46     if (temp[0] != '\0')
47     {
48         strncpy(pWorkgroup, temp, maxLenWorkgroup - 1);
49     }
50     
51     fprintf(stdout, "Username: [%s] ", pUsername);
52     fgets(temp, sizeof(temp), stdin);
53     
54     if (temp[strlen(temp) - 1] == '\n') /* A new line? */
55     {
56         temp[strlen(temp) - 1] = '\0';
57     }
58     
59     if (temp[0] != '\0')
60     {
61         strncpy(pUsername, temp, maxLenUsername - 1);
62     }
63     
64     fprintf(stdout, "Password: ");
65     fgets(temp, sizeof(temp), stdin);
66     
67     if (temp[strlen(temp) - 1] == '\n') /* A new line? */
68     {
69         temp[strlen(temp) - 1] = '\0';
70     }
71     
72     if (temp[0] != '\0')
73     {
74         strncpy(pPassword, temp, maxLenPassword - 1);
75     }
76
77     strncpy(workgroup, pWorkgroup, sizeof(workgroup) - 1);
78     strncpy(username, pUsername, sizeof(username) - 1);
79     strncpy(password, pPassword, sizeof(password) - 1);
80
81     krb5_set = 1;
82 }