17
17
/**
18
18
@file
19
19
20
- auth_pipd authentication plugin.
20
+ auth_pipe authentication plugin.
21
21
22
- Authentication is successful if the connection is done via a named pip and
23
- the owner of the client process matches the user name that was used when
24
- connecting to mysqld.
22
+ Authentication is successful if the connection is done via a named pipe
23
+ pipe peer name matches mysql user name
25
24
*/
26
25
27
-
28
26
#include <mysql/plugin_auth.h>
29
27
#include <string.h>
30
28
#include <lmcons.h>
31
29
32
30
33
-
34
-
35
-
36
31
/**
37
- perform the named pipe´based authentication
38
-
39
- This authentication callback performs a named pipe based authentication -
40
- it gets the uid of the client process and considers the user authenticated
41
- if it uses username of this uid. That is - if the user is already
42
- authenticated to the OS (if she is logged in) - she can use MySQL as herself
32
+ This authentication callback obtains user name using named pipe impersonation
43
33
*/
44
-
45
34
static int pipe_auth (MYSQL_PLUGIN_VIO * vio , MYSQL_SERVER_AUTH_INFO * info )
46
35
{
47
36
unsigned char * pkt ;
48
- PTOKEN_USER pTokenUser = NULL ;
49
- HANDLE hToken ;
50
37
MYSQL_PLUGIN_VIO_INFO vio_info ;
51
- DWORD dLength = 0 ;
52
- int Ret = CR_ERROR ;
53
- TCHAR username [UNLEN + 1 ];
54
- DWORD username_length = UNLEN + 1 ;
55
- char domainname [DNLEN + 1 ];
56
- DWORD domainsize = DNLEN + 1 ;
57
- SID_NAME_USE sidnameuse ;
38
+ char username [UNLEN + 1 ];
39
+ size_t username_length ;
40
+ int ret ;
58
41
59
42
/* no user name yet ? read the client handshake packet with the user name */
60
43
if (info -> user_name == 0 )
61
44
{
62
45
if (vio -> read_packet (vio , & pkt ) < 0 )
63
46
return CR_ERROR ;
64
47
}
65
-
66
48
info -> password_used = PASSWORD_USED_NO_MENTION ;
67
-
68
49
vio -> info (vio , & vio_info );
69
50
if (vio_info .protocol != MYSQL_VIO_PIPE )
70
51
return CR_ERROR ;
71
52
72
- /* get the UID of the client process */
53
+ /* Impersonate the named pipe peer, and retrieve the user name */
73
54
if (!ImpersonateNamedPipeClient (vio_info .handle ))
74
55
return CR_ERROR ;
75
-
76
- if (!OpenThreadToken (GetCurrentThread (), TOKEN_ALL_ACCESS , TRUE, & hToken ))
77
- goto end ;
78
-
79
- /* determine length of TokenUser */
80
- GetTokenInformation (hToken , TokenUser , NULL , 0 , & dLength );
81
- if (!dLength )
82
- goto end ;
83
-
84
- if (!(pTokenUser = (PTOKEN_USER )LocalAlloc (0 , dLength )))
85
- goto end ;
86
-
87
- if (!GetTokenInformation (hToken , TokenUser , (PVOID )pTokenUser , dLength , & dLength ))
88
- goto end ;
89
-
90
- if (!LookupAccountSid (NULL , pTokenUser -> User .Sid , username , & username_length , domainname , & domainsize , & sidnameuse ))
91
- goto end ;
92
56
93
- Ret = strcmp (username , info -> user_name ) ? CR_ERROR : CR_OK ;
94
- end :
95
- if (pTokenUser )
96
- LocalFree (pTokenUser );
57
+ username_length = sizeof (username ) - 1 ;
58
+ ret = CR_ERROR ;
59
+ if (GetUserName (username , & username_length ))
60
+ {
61
+ /* Always compare names case-insensitive on Windows.*/
62
+ if (_stricmp (username , info -> user_name ) == 0 )
63
+ ret = CR_OK ;
64
+ }
97
65
RevertToSelf ();
98
- /* now it's simple as that */
99
- return Ret ;
66
+
67
+ return ret ;
100
68
}
101
69
102
70
static struct st_mysql_auth pipe_auth_handler =
@@ -106,11 +74,11 @@ static struct st_mysql_auth pipe_auth_handler=
106
74
pipe_auth
107
75
};
108
76
109
- maria_declare_plugin (socket_auth )
77
+ maria_declare_plugin (auth_named_pipe )
110
78
{
111
79
MYSQL_AUTHENTICATION_PLUGIN ,
112
80
& pipe_auth_handler ,
113
- "windows_pipe " ,
81
+ "named_pipe " ,
114
82
"Vladislav Vaintroub, Georg Richter" ,
115
83
"Windows named pipe based authentication" ,
116
84
PLUGIN_LICENSE_GPL ,
0 commit comments