1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <helper/networkdomain.hxx>
28 #pragma warning(push, 1)
35 static DWORD WINAPI
GetUserDomainW_NT( LPWSTR lpBuffer
, DWORD nSize
)
37 return GetEnvironmentVariable( TEXT("USERDOMAIN"), lpBuffer
, nSize
);
40 static OUString
GetUserDomain()
42 sal_Unicode aBuffer
[256];
45 nResult
= GetUserDomainW_NT( reinterpret_cast<LPWSTR
>(aBuffer
), sizeof( aBuffer
) );
48 return OUString( aBuffer
);
58 OUString
NetworkDomain::GetYPDomainName()
63 OUString
NetworkDomain::GetNTDomainName()
65 return GetUserDomain();
72 #include <rtl/ustring.h>
75 #include <osl/thread.h>
79 #if defined( SOLARIS )
83 #include <sys/systeminfo.h>
84 #include <sal/alloca.h>
86 static rtl_uString
*getDomainName()
88 /* Initialize and assume failure */
89 rtl_uString
*ustrDomainName
= NULL
;
93 long nCopied
= sizeof(szBuffer
);
94 char *pBuffer
= szBuffer
;
100 nCopied
= sysinfo( SI_SRPC_DOMAIN
, pBuffer
, nBufSize
);
102 /* If nCopied is greater than buffersize we need to allocate
103 a buffer with suitable size */
105 if ( nCopied
> nBufSize
)
106 pBuffer
= (char *)alloca( nCopied
);
108 } while ( nCopied
> nBufSize
);
116 osl_getThreadTextEncoding(),
117 OSTRING_TO_OUSTRING_CVTFLAGS
);
120 return ustrDomainName
;
123 #elif defined( LINUX ) /* endif SOLARIS */
130 static rtl_uString
*getDomainName()
132 /* Initialize and assume failure */
133 rtl_uString
*ustrDomainName
= NULL
;
141 nBufSize
+= 256; /* Increase buffer size by steps of 256 bytes */
142 pBuffer
= static_cast<char *>(alloca( nBufSize
));
143 result
= getdomainname( pBuffer
, nBufSize
);
144 /* If buffersize in not large enough -1 is returned and errno
145 is set to EINVAL. This only applies to libc. With glibc the name
147 } while ( -1 == result
&& EINVAL
== errno
);
155 osl_getThreadTextEncoding(),
156 OSTRING_TO_OUSTRING_CVTFLAGS
);
159 return ustrDomainName
;
166 static rtl_uString
*getDomainName()
178 OUString
NetworkDomain::GetYPDomainName()
180 rtl_uString
* pResult
= getDomainName();
182 return OUString( pResult
);
187 OUString
NetworkDomain::GetNTDomainName()
196 // Other operating systems (non-Windows and non-Unix)
201 OUString
NetworkDomain::GetYPDomainName()
206 OUString
NetworkDomain::GetNTDomainName()
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */