blob: a947af787b19ca04e699b2da6893c0570fc843d3 (
plain) (
blame)
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
|
/*++
Copyright (c) 1991 Microsoft Corporation
Module Name:
getconfg.c
Abstract:
This is a Hacked up version of getconfg.c stolen from
c:\nt\private\net\netlib. We need to make an rtl routine out
of this - something that is more globally available.
-Danl 9-3-91
This module contains routines for manipulating configuration
information. The following functions available are:
NetpGetComputerName
Currently configuration information is kept in NT.CFG.
Later it will be kept by the configuration manager.
Author:
Dan Lafferty (danl) 09-Apr-1991
Environment:
User Mode -Win32 (also uses nt RTL routines)
Revision History:
09-Apr-1991 danl
created
--*/
//#include <stdlib.h> // atol
#include <nt.h> // DbgPrint prototype
#include <ntrtl.h> // DbgPrint prototype
#include <ntdef.h>
#include <ntstatus.h>
#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
//#include <ntlsa.h> //
#include <windef.h>
#include <winbase.h> // LocalAlloc
#include <lmcons.h>
#include <string.h>
#include <lmerr.h>
NTSTATUS
ElfpGetComputerName (
IN LPSTR *ComputerNamePtr)
/*++
Routine Description:
This routine obtains the computer name from a persistent database,
by calling the GetcomputerNameA Win32 Base API
This routine assumes the length of the computername is no greater
than MAX_COMPUTERNAME_LENGTH, space for which it allocates using
LocalAlloc. It is necessary for the user to free that space using
LocalFree when finished.
Arguments:
ComputerNamePtr - This is a pointer to the location where the pointer
to the computer name is to be placed.
Return Value:
NERR_Success - If the operation was successful.
It will return assorted Net or Win32 or NT error messages if not.
--*/
{
DWORD nSize = MAX_COMPUTERNAME_LENGTH + 1;
//
// Allocate a buffer to hold the largest possible computer name.
//
*ComputerNamePtr = LocalAlloc(LMEM_ZEROINIT, nSize);
if (*ComputerNamePtr == NULL) {
return (GetLastError());
}
//
// Get the computer name string into the locally allocated buffer
// by calling the Win32 GetComputerNameA API.
//
if (!GetComputerNameA(*ComputerNamePtr, &nSize)) {
LocalFree(*ComputerNamePtr);
*ComputerNamePtr = NULL;
return (GetLastError());
}
return (NERR_Success);
}
|