Skip to content

Commit 66a53ed

Browse files
LyncConnector - code fixed for null conditions.
1 parent b7c759c commit 66a53ed

File tree

8 files changed

+128
-29
lines changed

8 files changed

+128
-29
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<#
2+
<copyright file="Register-EventSource.ps1" company="Microsoft">
3+
Copyright (c) Microsoft. All Rights Reserved.
4+
Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
5+
</copyright>
6+
<summary>
7+
The script to register event sources for the "ConnectorsLog" Event Log of the FIM PowerShell and all other new connectors.
8+
The script to needs to run with elevated privileges.
9+
Please create / edit <system.diagnostics> configuration element as directed in the app.config file.
10+
</summary>
11+
#>
12+
13+
$eventSources = @{
14+
"ConnectorsLog" = "ConnectorsLog"
15+
}
16+
17+
function TestIsAdministrator
18+
{
19+
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
20+
(New-Object Security.Principal.WindowsPrincipal $currentUser).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
21+
}
22+
23+
function RegisterEventSource()
24+
{
25+
foreach($source in $eventSources.Keys)
26+
{
27+
$logName = $eventSources[$source]
28+
29+
Write-Host "Creating event source $source in event log $logName"
30+
31+
if ([System.Diagnostics.EventLog]::SourceExists($source) -eq $false) {
32+
New-EventLog -Source $source -LogName $logName
33+
Write-Host -ForegroundColor green "Event source $source created in event log $logName"
34+
}
35+
else
36+
{
37+
$eventLog = Get-EventLog -List | Where-Object {$_.Log -eq $logName}
38+
39+
if ($eventLog -ne $null)
40+
{
41+
Write-Host -ForegroundColor yellow "Warning: Event source $source already exists in event log $logName"
42+
}
43+
else
44+
{
45+
Write-Host -ForegroundColor yellow "Warning: Event source $source already exists, but not in event log $logName. It will be deleted and recreated. You'll need to reboot the machine to see the events in the new event log."
46+
[System.Diagnostics.EventLog]::DeleteEventSource($source)
47+
New-EventLog -Source $source -LogName $logName
48+
}
49+
}
50+
51+
Limit-EventLog -LogName $logName -MaximumSize 20480KB
52+
53+
Write-Host -ForegroundColor green "Writing a test event in the event log '$logName'"
54+
55+
[System.Diagnostics.EventLog]::WriteEntry($logName, "Test Event")
56+
}
57+
}
58+
59+
if(!(TestIsAdministrator))
60+
{
61+
throw $("Admin rights are required for this script")
62+
}
63+
64+
RegisterEventSource
2.05 KB
Binary file not shown.

src/LyncConnector/LyncConnector.sln

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,25 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestData", "TestData", "{4E
3030
TestData\Lync-Export-Update-User.xml = TestData\Lync-Export-Update-User.xml
3131
EndProjectSection
3232
EndProject
33+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Template", "Template", "{4E91C37F-0DDB-4632-9A0A-1AA20AAFCC1D}"
34+
ProjectSection(SolutionItems) = preProject
35+
Template\LyncConnectorConfigExport.xml = Template\LyncConnectorConfigExport.xml
36+
EndProjectSection
37+
EndProject
38+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "EventLogConfig", "EventLogConfig", "{75CA84A7-AC63-4E99-A444-5AB1CD5B16E2}"
39+
ProjectSection(SolutionItems) = preProject
40+
EventLogConfig\app.config = EventLogConfig\app.config
41+
EventLogConfig\Register-EventSource.ps1 = EventLogConfig\Register-EventSource.ps1
42+
EndProjectSection
43+
EndProject
3344
Global
3445
GlobalSection(SolutionProperties) = preSolution
3546
HideSolutionNode = FALSE
3647
EndGlobalSection
3748
GlobalSection(NestedProjects) = preSolution
3849
{1552EB73-5E64-42C2-B06C-92A08A086D44} = {2C7507D1-98D0-4C94-A903-04930A0E1B19}
3950
{4E8C6369-9FD1-43F0-9878-27CC4DF24F83} = {2C7507D1-98D0-4C94-A903-04930A0E1B19}
51+
{4E91C37F-0DDB-4632-9A0A-1AA20AAFCC1D} = {2C7507D1-98D0-4C94-A903-04930A0E1B19}
52+
{75CA84A7-AC63-4E99-A444-5AB1CD5B16E2} = {2C7507D1-98D0-4C94-A903-04930A0E1B19}
4053
EndGlobalSection
4154
EndGlobal

src/LyncConnector/Scripts/1. Lync.Common.psm1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ function New-CSEntryChangeResult
924924

925925
if ($ExportAdd)
926926
{
927-
if ($NewArchorTable -eq $null -or !$NewAnchorTable.Keys.Count -eq 0)
927+
if ($NewAnchorTable -eq $null -or $NewAnchorTable.Keys.Count -eq 0)
928928
{
929929
throw "The NewAnchorTable parameter must not be null."
930930
}
@@ -977,6 +977,7 @@ function Select-PreferredDomainController
977977
{
978978
try
979979
{
980+
$preferredDC =$preferredDC.Trim()
980981
$conn = New-Object "Net.Sockets.TcpClient"
981982
$conn.Connect($preferredDC, 389)
982983
$selected = $true

src/LyncConnector/Scripts/6. Begin-ImportScript-Lync.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,6 @@ if (!$session)
148148

149149
Get-OpenImportConnectionResults
150150

151-
Exit-Script -ScriptType "Begin-Import" -ExceptionRaisedOnErrorCheck [Microsoft.MetadirectoryServices.ServerDownException]
151+
$exceptionRaisedOnErrorCheck = [Microsoft.MetadirectoryServices.ServerDownException]
152+
Exit-Script -ScriptType "Begin-Import" -ExceptionRaisedOnErrorCheck $exceptionRaisedOnErrorCheck
152153

src/LyncConnector/Scripts/7. ImportScript-Lync.ps1

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ function Get-PagingFilter
224224
throw ("Unexpected Page Index $pageIndex to import objectType {0}. Max Index: {1}" -f $ObjectType, $userPages.Length)
225225
}
226226

227-
$ldapFilter = "(&(objectCategory=person)(objectClass=user)(msRTCSIP-PrimaryUserAddress=sip:{0}*)" -f $userPages[$pageIndex] # no spaces in the LDAP query or it will fail.
227+
$ldapFilter = "(&(objectCategory=person)(objectClass=user)(msRTCSIP-PrimaryUserAddress=sip:{0}*)" -f $userPages[$pageIndex].Trim() # no spaces in the LDAP query or it will fail.
228228

229229
if (![string]::IsNullOrEmpty($LastRunDateTime))
230230
{
@@ -252,7 +252,7 @@ function Get-PagingFilter
252252
throw ("Unexpected Page Index $pageIndex to import objectType {0}. Max Index: {1}" -f $ObjectType, $ouPages.Length)
253253
}
254254

255-
$ldapFilter = "(name={0}*)" -f $ouPages[$pageIndex]
255+
$ldapFilter = "(name={0}*)" -f $ouPages[$pageIndex].Trim()
256256
if (![string]::IsNullOrEmpty($LastRunDateTime))
257257
{
258258
$ldapFilter += "(whenChanged>={0:yyyyMMddHHmmss}.0Z)" -f ([DateTime]$LastRunDateTime).AddMinutes(-1*[int]$lastRunDateTimeOffset) # The LastRunDateTime in watermark is already in UTC.
@@ -475,12 +475,16 @@ else
475475
$ouPages = $ouPages.Split(",")
476476
}
477477

478-
$lastRunDateTimeOffset = Get-ConfigParameter -ConfigParameters $ConfigParameters -ParameterName "LastRunDateTimeOffsetMinutes"
478+
$lastRunDateTimeOffset = Get-ConfigParameter -ConfigParameters $ConfigParameters -ParameterName "LastRunDateTimeOffsetMinutes"
479479

480-
if (![string]::IsNullOrEmpty($lastRunDateTimeOffset))
480+
if ([string]::IsNullOrEmpty($lastRunDateTimeOffset))
481481
{
482482
$lastRunDateTimeOffset = 30 # in minutes
483483
}
484+
else
485+
{
486+
$lastRunDateTimeOffset.Trim()
487+
}
484488

485489
$deltaImport = $openImportConnectionRunStep.ImportType -eq "Delta"
486490
$customData = [xml]$getImportEntriesRunStep.CustomData

src/LyncConnector/Scripts/9. Begin-ExportScript-Lync.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,5 @@ if (!$session)
6666
Write-Debug "Opened a new RPS Session."
6767
}
6868

69-
Exit-Script -ScriptType "Begin-Export" -ExceptionRaisedOnErrorCheck [Microsoft.MetadirectoryServices.ServerDownException]
69+
$exceptionRaisedOnErrorCheck = [Microsoft.MetadirectoryServices.ServerDownException]
70+
Exit-Script -ScriptType "Begin-Export" -ExceptionRaisedOnErrorCheck $exceptionRaisedOnErrorCheck

0 commit comments

Comments
 (0)