-
Notifications
You must be signed in to change notification settings - Fork 6
/
reaction-password-req.c
142 lines (120 loc) · 3.49 KB
/
reaction-password-req.c
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* smb2-handler - SMB2 file system client
*
* Copyright (C) 2022-2023 Fredrik Wikstrom <fredrik@a500.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (in the main directory of the smb2-handler
* distribution in the file COPYING); if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#define __USE_INLINE__
#include "smb2fs.h"
#include "smb2-handler_rev.h"
#include <proto/intuition.h>
#include <classes/requester.h>
#ifndef __amigaos4__
#include <proto/requester.h>
#include <clib/alib_protos.h>
#ifndef REQ_Image
#define REQ_Image (REQ_Dummy+7)
#endif
#ifndef REQIMAGE_QUESTION
#define REQIMAGE_QUESTION (4)
#endif
#ifndef REQS_ReturnEnds
#define REQS_ReturnEnds (REQS_Dummy+8)
#endif
#endif /* !__amigaos4__ */
#include <stdio.h>
#include <string.h>
char *request_password(const char *user, const char *server)
{
#ifdef __amigaos4__
struct IntuitionIFace *IIntuition;
#else
struct IntuitionBase *IntuitionBase;
#endif
char *password = NULL;
#ifdef __amigaos4__
IIntuition = (struct IntuitionIFace *)open_interface("intuition.library", 53);
if (IIntuition != NULL)
#else
IntuitionBase = (struct IntuitionBase *)OpenLibrary((STRPTR)"intuition.library", 39);
if (IntuitionBase != NULL)
#endif
{
struct Library *RequesterBase;
Class *RequesterClass;
#ifdef __amigaos4__
RequesterBase = (struct Library *)OpenClass("requester.class", 53, &RequesterClass);
#else
RequesterBase = OpenLibrary("requester.class", 42);
#endif
if (RequesterBase != NULL)
{
struct Screen *screen;
#ifndef __amigaos4__
RequesterClass = REQUESTER_GetClass();
#endif
screen = LockPubScreen(NULL);
if (screen != NULL)
{
TEXT bodytext[256];
TEXT buffer[256];
Object *reqobj;
buffer[0] = '\0';
snprintf(bodytext, sizeof(bodytext), "Enter password for %s@%s", user, server);
reqobj = NewObject(RequesterClass, NULL,
REQ_Type, REQTYPE_STRING,
REQ_Image, REQIMAGE_QUESTION,
REQ_TitleText, VERS,
REQ_BodyText, bodytext,
REQ_GadgetText, "_Ok|_Cancel",
REQS_AllowEmpty, FALSE,
REQS_Invisible, TRUE,
REQS_Buffer, buffer,
REQS_MaxChars, sizeof(buffer),
REQS_ReturnEnds, TRUE,
TAG_END);
if (reqobj != NULL)
{
struct orRequest reqmsg;
LONG result;
reqmsg.MethodID = RM_OPENREQ;
reqmsg.or_Attrs = NULL;
reqmsg.or_Window = NULL;
reqmsg.or_Screen = screen;
result = DoMethodA(reqobj, (Msg)&reqmsg);
if (result && buffer[0] != '\0')
{
password = strdup(buffer);
}
DisposeObject(reqobj);
}
UnlockPubScreen(NULL, screen);
}
#ifdef __amigaos4__
CloseClass((struct ClassLibrary *)RequesterBase);
#else
CloseLibrary(RequesterBase);
#endif
}
#ifdef __amigaos4__
close_interface((struct Interface *)IIntuition);
#else
CloseLibrary((struct Library *)IntuitionBase);
#endif
}
return password;
}