source: vendor/current/examples/libsmbclient/get_auth_data_fn.h

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 2.2 KB
Line 
1#include <stdlib.h>
2
3static void
4get_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 char *ret;
20
21 static int krb5_set = 1;
22
23 if (strcmp(server, pServer) == 0 &&
24 strcmp(share, pShare) == 0 &&
25 *workgroup != '\0' &&
26 *username != '\0')
27 {
28 strncpy(pWorkgroup, workgroup, maxLenWorkgroup - 1);
29 strncpy(pUsername, username, maxLenUsername - 1);
30 strncpy(pPassword, password, maxLenPassword - 1);
31 return;
32 }
33
34 if (krb5_set && getenv("KRB5CCNAME")) {
35 krb5_set = 0;
36 return;
37 }
38
39 fprintf(stdout, "Workgroup: [%s] ", pWorkgroup);
40 ret = fgets(temp, sizeof(temp), stdin);
41 if (ret == NULL) {
42 return;
43 }
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(pWorkgroup, temp, maxLenWorkgroup - 1);
53 }
54
55 fprintf(stdout, "Username: [%s] ", pUsername);
56 ret = fgets(temp, sizeof(temp), stdin);
57 if (ret == NULL) {
58 return;
59 }
60
61 if (temp[strlen(temp) - 1] == '\n') /* A new line? */
62 {
63 temp[strlen(temp) - 1] = '\0';
64 }
65
66 if (temp[0] != '\0')
67 {
68 strncpy(pUsername, temp, maxLenUsername - 1);
69 }
70
71 fprintf(stdout, "Password: ");
72 ret = fgets(temp, sizeof(temp), stdin);
73 if (ret == NULL) {
74 return;
75 }
76
77 if (temp[strlen(temp) - 1] == '\n') /* A new line? */
78 {
79 temp[strlen(temp) - 1] = '\0';
80 }
81
82 if (temp[0] != '\0')
83 {
84 strncpy(pPassword, temp, maxLenPassword - 1);
85 }
86
87 strncpy(workgroup, pWorkgroup, sizeof(workgroup) - 1);
88 strncpy(username, pUsername, sizeof(username) - 1);
89 strncpy(password, pPassword, sizeof(password) - 1);
90
91 krb5_set = 1;
92}
Note: See TracBrowser for help on using the repository browser.