File: libauthSamba.c

package info (click to toggle)
libfilesys-smbclient-perl 3.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 392 kB
  • sloc: perl: 757; ansic: 84; makefile: 8
file content (102 lines) | stat: -rwxr-xr-x 2,677 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <stdio.h>
#include <string.h>
#include "libauthSamba.h"

char User[30];
char Password[30];
char Workgroup[30];

/*-----------------------------------------------------------------------------
 * set_fn
 *---------------------------------------------------------------------------*/
void set_fn(char *workgroup,
	    char *username,
	    char *password)
{  
#ifdef VERBOSE
  printf("set_fn\n");
#endif

  strcpy(User, username);
  strcpy(Password, password);
  /* set workgroup only when set */
  if (workgroup[0] && workgroup[0] != 0) {
#ifdef VERBOSE
    fprintf("Workgroup is set to %s", workgroup);
#endif
    strcpy(Workgroup, workgroup);
  }
}

/*-----------------------------------------------------------------------------
 * auth_fn
 *---------------------------------------------------------------------------*/
void auth_fn(const char *server, 
	     const char *share,
	     char *workgroup, int wgmaxlen,
	     char *username, int unmaxlen,
	     char *password, int pwmaxlen) {

#ifdef VERBOSE
  printf("auth_fn\n");
#endif

  /* set workgroup only when set */
  if (Workgroup[0] && Workgroup[0] != 0) {
#ifdef VERBOSE
    fprintf("Workgroup is set to %s", Workgroup);
#endif
    strcpy(workgroup, Workgroup);
    wgmaxlen = 30;
  }
  strcpy(username, User);
  unmaxlen = 30;
  strcpy(password, Password);
  pwmaxlen = 30;

#ifdef VERBOSE
  fprintf(stdout, "username: [%s]\n", username);
  fprintf(stdout, "password: [%s]\n", password);
  fprintf(stdout, "workgroup: [%s]\n", workgroup);
#endif


}

/*-----------------------------------------------------------------------------
 * ask_auth_fn
 *---------------------------------------------------------------------------*/
void ask_auth_fn(const char *server, 
	     const char *share,
	     char *workgroup, int wgmaxlen,
	     char *username, int unmaxlen,
	     char *password, int pwmaxlen)
{  
  char temp[128];

  fprintf(stdout, "Need password for //%s/%s\n", server, share);

  fprintf(stdout, "Enter workgroup: [%s] ", workgroup);
  fgets(temp, sizeof(temp), stdin);

  if (temp[strlen(temp) - 1] == 0x0a) /* A new line? */
    temp[strlen(temp) - 1] = 0x00;

  if (temp[0]) strncpy(workgroup, temp, wgmaxlen - 1);

  fprintf(stdout, "Enter username: [%s] ", username);
  fgets(temp, sizeof(temp), stdin);

  if (temp[strlen(temp) - 1] == 0x0a) /* A new line? */
    temp[strlen(temp) - 1] = 0x00;

  if (temp[0]) strncpy(username, temp, unmaxlen - 1);

  fprintf(stdout, "Enter password: [%s] ", password);
  fgets(temp, sizeof(temp), stdin);

  if (temp[strlen(temp) - 1] == 0x0a) /* A new line? */
    temp[strlen(temp) - 1] = 0x00;

  if (temp[0]) strncpy(password, temp, pwmaxlen - 1); 
}