Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <helper/networkdomain.hxx>
30 : :
31 : : #ifdef WNT
32 : : //_________________________________________________________________________________________________________________
33 : : // Windows
34 : : //_________________________________________________________________________________________________________________
35 : :
36 : : #define UNICODE
37 : : #if defined _MSC_VER
38 : : #pragma warning(push, 1)
39 : : #endif
40 : : #include <windows.h>
41 : : #if defined _MSC_VER
42 : : #pragma warning(pop)
43 : : #endif
44 : :
45 : : static DWORD WINAPI GetUserDomainW_NT( LPWSTR lpBuffer, DWORD nSize )
46 : : {
47 : : return GetEnvironmentVariable( TEXT("USERDOMAIN"), lpBuffer, nSize );
48 : : }
49 : :
50 : : static rtl::OUString GetUserDomain()
51 : : {
52 : : sal_Unicode aBuffer[256];
53 : : DWORD nResult;
54 : :
55 : : nResult = GetUserDomainW_NT( reinterpret_cast<LPWSTR>(aBuffer), sizeof( aBuffer ) );
56 : :
57 : : if ( nResult > 0 )
58 : : return rtl::OUString( aBuffer );
59 : : else
60 : : return rtl::OUString();
61 : : }
62 : :
63 : : //_________________________________________________________________________________________________________________
64 : : // Windows
65 : : //_________________________________________________________________________________________________________________
66 : :
67 : : namespace framework
68 : : {
69 : :
70 : : rtl::OUString NetworkDomain::GetYPDomainName()
71 : : {
72 : : return ::rtl::OUString();
73 : : }
74 : :
75 : : rtl::OUString NetworkDomain::GetNTDomainName()
76 : : {
77 : : return GetUserDomain();
78 : : }
79 : :
80 : : }
81 : :
82 : : #elif defined( UNIX )
83 : :
84 : : #include <rtl/ustring.h>
85 : : #include <stdlib.h>
86 : : #include <errno.h>
87 : : #include <osl/thread.h>
88 : :
89 : : //_________________________________________________________________________________________________________________
90 : : // Unix
91 : : //_________________________________________________________________________________________________________________
92 : :
93 : : #if defined( SOLARIS )
94 : :
95 : : //_________________________________________________________________________________________________________________
96 : : // Solaris
97 : : //_________________________________________________________________________________________________________________
98 : :
99 : : #include <sys/systeminfo.h>
100 : : #include <sal/alloca.h>
101 : :
102 : : static rtl_uString *getDomainName()
103 : : {
104 : : /* Initialize and assume failure */
105 : : rtl_uString *ustrDomainName = NULL;
106 : :
107 : : char szBuffer[256];
108 : :
109 : : long nCopied = sizeof(szBuffer);
110 : : char *pBuffer = szBuffer;
111 : : long nBufSize;
112 : :
113 : : do
114 : : {
115 : : nBufSize = nCopied;
116 : : nCopied = sysinfo( SI_SRPC_DOMAIN, pBuffer, nBufSize );
117 : :
118 : : /* If nCopied is greater than buffersize we need to allocate
119 : : a buffer with suitable size */
120 : :
121 : : if ( nCopied > nBufSize )
122 : : pBuffer = (char *)alloca( nCopied );
123 : :
124 : : } while ( nCopied > nBufSize );
125 : :
126 : : if ( -1 != nCopied )
127 : : {
128 : : rtl_string2UString(
129 : : &ustrDomainName,
130 : : pBuffer,
131 : : nCopied - 1,
132 : : osl_getThreadTextEncoding(),
133 : : OSTRING_TO_OUSTRING_CVTFLAGS );
134 : : }
135 : :
136 : : return ustrDomainName;
137 : : }
138 : :
139 : : #elif defined( LINUX ) /* endif SOLARIS */
140 : :
141 : : //_________________________________________________________________________________________________________________
142 : : // Linux
143 : : //_________________________________________________________________________________________________________________
144 : :
145 : : #include <unistd.h>
146 : : #include <string.h>
147 : :
148 : 0 : static rtl_uString *getDomainName()
149 : : {
150 : : /* Initialize and assume failure */
151 : 0 : rtl_uString *ustrDomainName = NULL;
152 : :
153 : : char *pBuffer;
154 : : int result;
155 : 0 : size_t nBufSize = 0;
156 : :
157 [ # # ]: 0 : do
[ # # # # ]
158 : : {
159 : 0 : nBufSize += 256; /* Increase buffer size by steps of 256 bytes */
160 : 0 : pBuffer = (char *)alloca( nBufSize );
161 : 0 : result = getdomainname( pBuffer, nBufSize );
162 : : /* If buffersize in not large enough -1 is returned and errno
163 : : is set to EINVAL. This only applies to libc. With glibc the name
164 : : is truncated. */
165 : 0 : } while ( -1 == result && EINVAL == errno );
166 : :
167 [ # # ]: 0 : if ( 0 == result )
168 : : {
169 : : rtl_string2UString(
170 : : &ustrDomainName,
171 : : pBuffer,
172 : 0 : strlen( pBuffer ),
173 [ # # ]: 0 : osl_getThreadTextEncoding(),
174 : 0 : OSTRING_TO_OUSTRING_CVTFLAGS );
175 : : }
176 : :
177 : 0 : return ustrDomainName;
178 : : }
179 : :
180 : : #else /* LINUX */
181 : :
182 : : //_________________________________________________________________________________________________________________
183 : : // Other Unix
184 : : //_________________________________________________________________________________________________________________
185 : :
186 : : static rtl_uString *getDomainName()
187 : : {
188 : : return NULL;
189 : : }
190 : :
191 : : #endif
192 : :
193 : : //_________________________________________________________________________________________________________________
194 : : // Unix
195 : : //_________________________________________________________________________________________________________________
196 : :
197 : : namespace framework
198 : : {
199 : :
200 : 0 : rtl::OUString NetworkDomain::GetYPDomainName()
201 : : {
202 : 0 : rtl_uString* pResult = getDomainName();
203 [ # # ]: 0 : if ( pResult )
204 : 0 : return rtl::OUString( pResult );
205 : : else
206 : 0 : return rtl::OUString();
207 : : }
208 : :
209 : 0 : rtl::OUString NetworkDomain::GetNTDomainName()
210 : : {
211 : 0 : return ::rtl::OUString();
212 : : }
213 : :
214 : : }
215 : :
216 : : #else /* UNIX */
217 : :
218 : : //_________________________________________________________________________________________________________________
219 : : // Other operating systems (non-Windows and non-Unix)
220 : : //_________________________________________________________________________________________________________________
221 : :
222 : : namespace framework
223 : : {
224 : :
225 : : rtl::OUString NetworkDomain::GetYPDomainName()
226 : : {
227 : : return rtl::OUString();
228 : : }
229 : :
230 : : rtl::OUString NetworkDomain::GetNTDomainName()
231 : : {
232 : : return rtl::OUString();
233 : : }
234 : :
235 : : }
236 : :
237 : : #endif
238 : :
239 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|