Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.package
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Xiaowu Zhang
slapos.package
Commits
8025dc7a
Commit
8025dc7a
authored
May 30, 2013
by
Jondy Zhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement function: netuse.mapDrive
parent
e14b3d1a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
122 additions
and
70 deletions
+122
-70
windows/netreport/src/netuse.c
windows/netreport/src/netuse.c
+118
-70
windows/netreport/src/tests.py
windows/netreport/src/tests.py
+4
-0
No files found.
windows/netreport/src/netuse.c
View file @
8025dc7a
...
@@ -131,10 +131,57 @@ netuse_user_info(PyObject *self, PyObject *args)
...
@@ -131,10 +131,57 @@ netuse_user_info(PyObject *self, PyObject *args)
return
NULL
;
return
NULL
;
}
}
static
char
get_free_drive_letter
()
{
DWORD
bitmasks
=
GetLogicalDrives
();
char
ch
=
'A'
;
while
(
bitmasks
)
{
if
((
bitmasks
&
1L
)
==
0
)
return
ch
;
++
ch
;
bitmasks
>>=
1
;
}
return
0
;
}
static
PyObject
*
static
PyObject
*
netuse_map_drive
(
PyObject
*
self
,
PyObject
*
args
)
netuse_map_drive
(
PyObject
*
self
,
PyObject
*
args
)
{
{
PyErr_SetString
(
PyExc_RuntimeError
,
"Not Implemented"
);
DWORD
dwRetVal
;
NETRESOURCE
nr
;
DWORD
dwFlags
;
char
*
remote
=
NULL
;
char
drive
[]
=
{
0
,
':'
,
0
};
char
*
user
=
NULL
;
char
*
password
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"s"
,
&
remote
))
{
return
NULL
;
}
drive
[
0
]
=
get_free_drive_letter
();
if
(
!
drive
[
0
])
{
PyErr_SetString
(
PyExc_RuntimeError
,
"Add net drive faild: no available drive letter."
);
return
NULL
;
}
memset
(
&
nr
,
0
,
sizeof
(
NETRESOURCE
));
nr
.
dwType
=
RESOURCETYPE_DISK
;
nr
.
lpLocalName
=
drive
;
nr
.
lpRemoteName
=
remote
;
nr
.
lpProvider
=
NULL
;
dwFlags
=
CONNECT_UPDATE_PROFILE
;
dwRetVal
=
WNetAddConnection2
(
&
nr
,
password
,
user
,
dwFlags
);
if
(
dwRetVal
==
NO_ERROR
)
return
PyString_FromString
(
drive
);
PyErr_Format
(
PyExc_RuntimeError
,
"WNetAddConnection2 failed with error: %lu
\n
"
,
dwRetVal
);
return
NULL
;
return
NULL
;
}
}
/*
/*
...
@@ -198,7 +245,7 @@ netuse_usage_report(PyObject *self, PyObject *args)
...
@@ -198,7 +245,7 @@ netuse_usage_report(PyObject *self, PyObject *args)
char
drivename
[]
=
{
'A'
,
':'
,
0
};
char
drivename
[]
=
{
'A'
,
':'
,
0
};
ULARGE_INTEGER
lFreeBytesAvailable
;
ULARGE_INTEGER
lFreeBytesAvailable
;
ULARGE_INTEGER
lTotalNumberOfBytes
;
ULARGE_INTEGER
lTotalNumberOfBytes
;
ULARGE_INTEGER
lTotalNumberOfFreeBytes
;
/* ULARGE_INTEGER lTotalNumberOfFreeBytes; */
char
szRemoteName
[
MAX_PATH
];
char
szRemoteName
[
MAX_PATH
];
DWORD
dwResult
,
cchBuff
=
MAX_PATH
;
DWORD
dwResult
,
cchBuff
=
MAX_PATH
;
...
@@ -331,8 +378,9 @@ static PyMethodDef NetUseMethods[] = {
...
@@ -331,8 +378,9 @@ static PyMethodDef NetUseMethods[] = {
netuse_map_drive
,
netuse_map_drive
,
METH_VARARGS
,
METH_VARARGS
,
(
(
"mapDrive()
\n\n
"
"mapDrive(sharefolder)
\n\n
"
"Create mapped drive from server shared folder
\n
"
"Create mapped drive from shared folder, it uses the default user
\n
"
"name. (provided by the user context for the process.)
\n
"
)
)
},
},
{
{
...
...
windows/netreport/src/tests.py
View file @
8025dc7a
...
@@ -22,6 +22,10 @@ class NetUseTests(unittest.TestCase):
...
@@ -22,6 +22,10 @@ class NetUseTests(unittest.TestCase):
self
.
assertEquals
(
len
(
r
),
3
)
self
.
assertEquals
(
len
(
r
),
3
)
self
.
assertEquals
(
r
,
(
'JONDY'
,
'JONDY'
,
'Administrator'
))
self
.
assertEquals
(
r
,
(
'JONDY'
,
'JONDY'
,
'Administrator'
))
def
test_map_drive
(
self
):
r
=
real_netuse
.
mapDrive
(
r'\\server\
p
ath'
)
self
.
assertEquals
(
r
,
'X:'
)
def
test_usage_report
(
self
):
def
test_usage_report
(
self
):
r
=
real_netuse
.
usageReport
()
r
=
real_netuse
.
usageReport
()
self
.
assertEquals
(
len
(
r
),
0
)
self
.
assertEquals
(
len
(
r
),
0
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment