forked from shaba/openuds
Uptated tag 1.1
This commit is contained in:
commit
eaf210a7bf
@ -93,11 +93,11 @@ class GroupsManager(object):
|
|||||||
lst += (g['group'].dbGroup().id,)
|
lst += (g['group'].dbGroup().id,)
|
||||||
yield g['group']
|
yield g['group']
|
||||||
# Now, get metagroups and also return them
|
# Now, get metagroups and also return them
|
||||||
for g in dbGroup.objects.filter(manager__id=self._dbAuthenticator.id, is_meta=False):
|
for g in dbGroup.objects.filter(manager__id=self._dbAuthenticator.id, is_meta=True):
|
||||||
gn = g.groups.filter(id__in=lst, state=State.ACTIVE).count()
|
gn = g.groups.filter(id__in=lst, state=State.ACTIVE).count()
|
||||||
if gn == g.groups.count(): # If a meta group is empty, all users belongs to it. we can use gn != 0 to check that if it is empty, is not valid
|
if gn == g.groups.count(): # If a meta group is empty, all users belongs to it. we can use gn != 0 to check that if it is empty, is not valid
|
||||||
# This group matches
|
# This group matches
|
||||||
yield g
|
yield Group(g)
|
||||||
|
|
||||||
|
|
||||||
def hasValidGroups(self):
|
def hasValidGroups(self):
|
||||||
|
@ -74,13 +74,14 @@ class User(object):
|
|||||||
if self._groups == None:
|
if self._groups == None:
|
||||||
if self._manager.isExternalSource == True:
|
if self._manager.isExternalSource == True:
|
||||||
self._manager.getGroups(self._dbUser.name, self._groupsManager())
|
self._manager.getGroups(self._dbUser.name, self._groupsManager())
|
||||||
self._groups = self._groupsManager().getValidGroups()
|
self._groups = list(self._groupsManager().getValidGroups())
|
||||||
|
logger.debug(self._groups)
|
||||||
# This is just for updating "cached" data of this user, we only get real groups at login and at modify user operation
|
# This is just for updating "cached" data of this user, we only get real groups at login and at modify user operation
|
||||||
usr = DbUser.objects.get(pk=self._dbUser.id)
|
usr = DbUser.objects.get(pk=self._dbUser.id)
|
||||||
lst = ()
|
lst = ()
|
||||||
for g in self._groups:
|
for g in self._groups:
|
||||||
if g.dbGroup().is_meta == False:
|
if g.dbGroup().is_meta == False:
|
||||||
lst += (g.id,)
|
lst += (g.dbGroup().id,)
|
||||||
usr.groups = lst
|
usr.groups = lst
|
||||||
else:
|
else:
|
||||||
# From db
|
# From db
|
||||||
|
@ -777,9 +777,8 @@ class UserInterface(object):
|
|||||||
# Set all values to defaults ones
|
# Set all values to defaults ones
|
||||||
for k in self._gui.iterkeys():
|
for k in self._gui.iterkeys():
|
||||||
if self._gui[k].isType(gui.InputField.HIDDEN_TYPE) and self._gui[k].isSerializable() is False:
|
if self._gui[k].isType(gui.InputField.HIDDEN_TYPE) and self._gui[k].isSerializable() is False:
|
||||||
logger.debug('Field {0} is not unserializable'.format(k))
|
#logger.debug('Field {0} is not unserializable'.format(k))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self._gui[k].value = self._gui[k].defValue
|
self._gui[k].value = self._gui[k].defValue
|
||||||
|
|
||||||
for txt in values.decode('zip').split('\002'):
|
for txt in values.decode('zip').split('\002'):
|
||||||
@ -793,7 +792,7 @@ class UserInterface(object):
|
|||||||
except:
|
except:
|
||||||
val = ''
|
val = ''
|
||||||
self._gui[k].value = val
|
self._gui[k].value = val
|
||||||
logger.debug('Value for {0}:{1}'.format(k, val))
|
#logger.debug('Value for {0}:{1}'.format(k, val))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def guiDescription(cls, obj = None):
|
def guiDescription(cls, obj = None):
|
||||||
|
@ -99,9 +99,11 @@ class WinDomainOsManager(WindowsOsManager):
|
|||||||
l.protocol_version = ldap.VERSION3
|
l.protocol_version = ldap.VERSION3
|
||||||
|
|
||||||
account = self._account
|
account = self._account
|
||||||
if account.find('@') is False:
|
if account.find('@') == -1:
|
||||||
account += '@' + self._domain
|
account += '@' + self._domain
|
||||||
|
|
||||||
|
logger.debug('Account data: {0}, {1}, {2}, {3}'.format(self._account, self._domain, account, self._password))
|
||||||
|
|
||||||
l.simple_bind_s(who = account, cred = self._password)
|
l.simple_bind_s(who = account, cred = self._password)
|
||||||
|
|
||||||
return l
|
return l
|
||||||
@ -123,6 +125,7 @@ class WinDomainOsManager(WindowsOsManager):
|
|||||||
logger.warn('Could not find _ldap._tcp.'+self._domain)
|
logger.warn('Could not find _ldap._tcp.'+self._domain)
|
||||||
log.doLog(service, log.WARN, "Could not remove machine from domain (_ldap._tcp.{0} not found)".format(self._domain), log.OSMANAGER);
|
log.doLog(service, log.WARN, "Could not remove machine from domain (_ldap._tcp.{0} not found)".format(self._domain), log.OSMANAGER);
|
||||||
except ldap.LDAPError as e:
|
except ldap.LDAPError as e:
|
||||||
|
logger.exception('Ldap Exception caught')
|
||||||
log.doLog(service, log.WARN, "Could not remove machine from domain (invalid credentials for {0})".format(self._account), log.OSMANAGER);
|
log.doLog(service, log.WARN, "Could not remove machine from domain (invalid credentials for {0})".format(self._account), log.OSMANAGER);
|
||||||
|
|
||||||
#_filter = '(&(objectClass=computer)(sAMAccountName=%s$))' % service.friendly_name
|
#_filter = '(&(objectClass=computer)(sAMAccountName=%s$))' % service.friendly_name
|
||||||
|
@ -152,7 +152,7 @@ def index(request):
|
|||||||
java = request.session['java']
|
java = request.session['java']
|
||||||
|
|
||||||
# We look for services for this authenticator groups. User is logged in in just 1 authenticator, so his groups must coincide with those assigned to ds
|
# We look for services for this authenticator groups. User is logged in in just 1 authenticator, so his groups must coincide with those assigned to ds
|
||||||
groups = request.user.getGroups()
|
groups = list(request.user.getGroups())
|
||||||
availServices = DeployedService.getDeployedServicesForGroups(groups)
|
availServices = DeployedService.getDeployedServicesForGroups(groups)
|
||||||
availUserServices = UserService.getUserAssignedServices(request.user)
|
availUserServices = UserService.getUserAssignedServices(request.user)
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ def createAuthenticator(credentials, type, data):
|
|||||||
auth = None
|
auth = None
|
||||||
try:
|
try:
|
||||||
auth = Authenticator.objects.create(name = dict_['name'], comments = dict_['comments'],
|
auth = Authenticator.objects.create(name = dict_['name'], comments = dict_['comments'],
|
||||||
data_type = type, priority=int(dict_['priority'], small_name=dict_['smallName']))
|
data_type = type, priority=int(dict_['priority']), small_name=dict_['smallName'])
|
||||||
auth.data = auth.getInstance(dict_).serialize()
|
auth.data = auth.getInstance(dict_).serialize()
|
||||||
auth.save()
|
auth.save()
|
||||||
except auths.Authenticator.ValidationException as e:
|
except auths.Authenticator.ValidationException as e:
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from uds.models import User as DbUser, Group as DbGroup, Authenticator as DbAuthenticator, State
|
from uds.models import User as DbUser, Group as DbGroup, Authenticator as DbAuthenticator, State
|
||||||
from uds.core.managers.CryptoManager import CryptoManager
|
from uds.core.managers.CryptoManager import CryptoManager
|
||||||
from ..util.Exceptions import DuplicateEntryException, InsertException
|
from ..util.Exceptions import DuplicateEntryException, InsertException, ParametersException
|
||||||
from uds.core.auths.Exceptions import AuthenticatorException, InvalidUserException
|
from uds.core.auths.Exceptions import AuthenticatorException, InvalidUserException
|
||||||
from AdminAuth import needs_credentials
|
from AdminAuth import needs_credentials
|
||||||
from Groups import dictFromGroup
|
from Groups import dictFromGroup
|
||||||
@ -72,13 +72,17 @@ def getUsers(credentials, idParent):
|
|||||||
def getUser(credentials, id):
|
def getUser(credentials, id):
|
||||||
'''
|
'''
|
||||||
'''
|
'''
|
||||||
|
try:
|
||||||
usr = User(DbUser.objects.get(pk=id))
|
usr = User(DbUser.objects.get(pk=id))
|
||||||
|
|
||||||
grps = []
|
grps = []
|
||||||
for g in usr.groups():
|
for g in usr.groups():
|
||||||
|
logger.debug(g)
|
||||||
grps.append(dictFromGroup(g.dbGroup()))
|
grps.append(dictFromGroup(g.dbGroup()))
|
||||||
logger.debug(grps)
|
logger.debug(grps)
|
||||||
return dictFromUser(usr.dbUser(), grps)
|
return dictFromUser(usr.dbUser(), grps)
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception('Unhandled exception')
|
||||||
|
raise ParametersException(str(e))
|
||||||
|
|
||||||
@needs_credentials
|
@needs_credentials
|
||||||
def createUser(credentials, usr):
|
def createUser(credentials, usr):
|
||||||
|
@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using log4net;
|
using log4net;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace uds
|
namespace uds
|
||||||
{
|
{
|
||||||
@ -22,6 +23,20 @@ namespace uds
|
|||||||
[DllImport("kernel32.dll", ExactSpelling = true)]
|
[DllImport("kernel32.dll", ExactSpelling = true)]
|
||||||
internal static extern IntPtr GetCurrentProcess();
|
internal static extern IntPtr GetCurrentProcess();
|
||||||
|
|
||||||
|
const uint FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
|
||||||
|
const uint FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200;
|
||||||
|
const uint FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000;
|
||||||
|
const uint FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000;
|
||||||
|
const uint FORMAT_MESSAGE_FROM_HMODULE = 0x00000800;
|
||||||
|
const uint FORMAT_MESSAGE_FROM_STRING = 0x00000400;
|
||||||
|
|
||||||
|
[DllImport("Kernel32.dll", SetLastError = true)]
|
||||||
|
static extern uint FormatMessage(uint dwFlags, IntPtr lpSource, uint dwMessageId, uint dwLanguageId, ref IntPtr lpBuffer,
|
||||||
|
uint nSize, IntPtr pArguments);
|
||||||
|
|
||||||
|
[DllImport("kernel32.dll", SetLastError = true)]
|
||||||
|
static extern IntPtr LocalFree(IntPtr hMem);
|
||||||
|
|
||||||
[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
|
[DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
|
||||||
internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);
|
internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);
|
||||||
|
|
||||||
@ -59,7 +74,7 @@ namespace uds
|
|||||||
NETSETUP_DEFER_SPN_SET = 0x10000000
|
NETSETUP_DEFER_SPN_SET = 0x10000000
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("netapi32.dll", CharSet = CharSet.Unicode)]
|
[DllImport("netapi32.dll", CharSet = CharSet.Unicode, SetLastError=true)]
|
||||||
static extern uint NetJoinDomain(string lpServer, string lpDomain, string lpAccountOU, string lpAccount, string lpPassword, JoinOptions NameType);
|
static extern uint NetJoinDomain(string lpServer, string lpDomain, string lpAccountOU, string lpAccount, string lpPassword, JoinOptions NameType);
|
||||||
|
|
||||||
enum COMPUTER_NAME_FORMAT
|
enum COMPUTER_NAME_FORMAT
|
||||||
@ -73,7 +88,7 @@ namespace uds
|
|||||||
ComputerNamePhysicalDnsDomain,
|
ComputerNamePhysicalDnsDomain,
|
||||||
ComputerNamePhysicalDnsFullyQualified,
|
ComputerNamePhysicalDnsFullyQualified,
|
||||||
}
|
}
|
||||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
|
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError=true)]
|
||||||
static extern bool SetComputerNameEx(COMPUTER_NAME_FORMAT NameType, string lpBuffer);
|
static extern bool SetComputerNameEx(COMPUTER_NAME_FORMAT NameType, string lpBuffer);
|
||||||
|
|
||||||
internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
|
internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
|
||||||
@ -92,7 +107,6 @@ namespace uds
|
|||||||
|
|
||||||
public static bool Reboot(int flg = EWX_FORCEIFHUNG|EWX_REBOOT)
|
public static bool Reboot(int flg = EWX_FORCEIFHUNG|EWX_REBOOT)
|
||||||
{
|
{
|
||||||
logger.Debug("Rebooting computer");
|
|
||||||
bool ok;
|
bool ok;
|
||||||
TokPriv1Luid tp;
|
TokPriv1Luid tp;
|
||||||
IntPtr hproc = GetCurrentProcess();
|
IntPtr hproc = GetCurrentProcess();
|
||||||
@ -105,12 +119,30 @@ namespace uds
|
|||||||
ok = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
|
ok = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
|
||||||
ok = ExitWindowsEx(flg, 0);
|
ok = ExitWindowsEx(flg, 0);
|
||||||
logger.Debug("Result: " + ok.ToString());
|
logger.Debug("Result: " + ok.ToString());
|
||||||
|
if (ok)
|
||||||
|
logger.Info("Rebooting computer");
|
||||||
|
else
|
||||||
|
logger.Error("Could not reboot machine. (Error " + ok.ToString() + ")");
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool waitAfterError(string op, bool useGetLastError, ManualResetEvent waitEvent, TimeSpan retryDelay)
|
||||||
|
{
|
||||||
|
if (useGetLastError)
|
||||||
|
logger.Error("Error at " + op + ": " + GetLastErrorStr() + ". Retrying in " + retryDelay.Seconds.ToString() + " secs");
|
||||||
|
else
|
||||||
|
logger.Error("Error at " + op + ". Retrying in " + retryDelay.Seconds.ToString() + " secs");
|
||||||
|
|
||||||
|
if (waitEvent.WaitOne(retryDelay))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool RenameComputer(string newName)
|
public static bool RenameComputer(string newName)
|
||||||
{
|
{
|
||||||
logger.Debug("Renaming computer to \"" + newName + "\"");
|
logger.Info("Renaming computer to \"" + newName + "\"");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return SetComputerNameEx(COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsHostname, newName);
|
return SetComputerNameEx(COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsHostname, newName);
|
||||||
@ -121,6 +153,16 @@ namespace uds
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool RenameComputer(string newName, ManualResetEvent waitEvent, TimeSpan retryDelay)
|
||||||
|
{
|
||||||
|
while (RenameComputer(newName) == false)
|
||||||
|
{
|
||||||
|
if (waitAfterError("Rename", true, waitEvent, retryDelay) == false)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool JoinDomain(string domain, string ou, string account, string password, bool oneStep = false)
|
public static bool JoinDomain(string domain, string ou, string account, string password, bool oneStep = false)
|
||||||
{
|
{
|
||||||
if (account.Contains('@') == false && account.Contains('\\') == false)
|
if (account.Contains('@') == false && account.Contains('\\') == false)
|
||||||
@ -130,7 +172,7 @@ namespace uds
|
|||||||
else
|
else
|
||||||
account = domain + "\\" + account;
|
account = domain + "\\" + account;
|
||||||
}
|
}
|
||||||
logger.Debug("Joining domain: \"" + domain + "\", \"" + ou + "\", \"" + account + "\", \"" + password + "\"" + ", oneStep = " + oneStep.ToString());
|
logger.Info("Joining domain: \"" + domain + "\", \"" + ou + "\", \"" + account + "\", \"" + "*****" + "\"" + ", oneStep = " + oneStep.ToString());
|
||||||
// Flag NETSETUP_JOIN_WITH_NEW_NAME not supported on win xp/2000
|
// Flag NETSETUP_JOIN_WITH_NEW_NAME not supported on win xp/2000
|
||||||
JoinOptions flags = JoinOptions.NETSETUP_ACCT_CREATE | JoinOptions.NETSETUP_DOMAIN_JOIN_IF_JOINED | JoinOptions.NETSETUP_JOIN_DOMAIN;
|
JoinOptions flags = JoinOptions.NETSETUP_ACCT_CREATE | JoinOptions.NETSETUP_DOMAIN_JOIN_IF_JOINED | JoinOptions.NETSETUP_JOIN_DOMAIN;
|
||||||
|
|
||||||
@ -142,6 +184,18 @@ namespace uds
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
uint res = NetJoinDomain(null, domain, ou, account, password, flags);
|
uint res = NetJoinDomain(null, domain, ou, account, password, flags);
|
||||||
|
if (res == 2224)
|
||||||
|
{
|
||||||
|
flags = JoinOptions.NETSETUP_DOMAIN_JOIN_IF_JOINED | JoinOptions.NETSETUP_JOIN_DOMAIN;
|
||||||
|
logger.Info("Existing account for machine found, reusing it");
|
||||||
|
res = NetJoinDomain(null, domain, null, account, password, flags);
|
||||||
|
}
|
||||||
|
if (res != 0)
|
||||||
|
{
|
||||||
|
logger.Error("Error joining domain:" + GetLastErrorStr((int)res));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
logger.Info("Successfully joined domain");
|
||||||
logger.Debug("Result of join: " + res);
|
logger.Debug("Result of join: " + res);
|
||||||
return res == 0;
|
return res == 0;
|
||||||
}
|
}
|
||||||
@ -153,6 +207,16 @@ namespace uds
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool JoinDomain(string domain, string ou, string account, string password, bool oneStep, ManualResetEvent waitEvent, TimeSpan retryDelay)
|
||||||
|
{
|
||||||
|
while (JoinDomain(domain, ou, account, password, oneStep) == false)
|
||||||
|
{
|
||||||
|
if (waitAfterError("Join domain", true, waitEvent, retryDelay) == false)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool ChangeUserPassword(string user, string oldPass, string newPass)
|
public static bool ChangeUserPassword(string user, string oldPass, string newPass)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@ -175,5 +239,33 @@ namespace uds
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetLastErrorStr(int nLastError=-1)
|
||||||
|
{
|
||||||
|
if(nLastError == -1)
|
||||||
|
nLastError = Marshal.GetLastWin32Error();
|
||||||
|
|
||||||
|
IntPtr lpMsgBuf = IntPtr.Zero;
|
||||||
|
|
||||||
|
uint dwChars = FormatMessage(
|
||||||
|
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
|
IntPtr.Zero,
|
||||||
|
(uint)nLastError,
|
||||||
|
0, // Default language
|
||||||
|
ref lpMsgBuf,
|
||||||
|
0,
|
||||||
|
IntPtr.Zero);
|
||||||
|
if (dwChars == 0)
|
||||||
|
{
|
||||||
|
return "(unknown)";
|
||||||
|
}
|
||||||
|
|
||||||
|
string sRet = Marshal.PtrToStringAnsi(lpMsgBuf);
|
||||||
|
|
||||||
|
// Free the buffer.
|
||||||
|
lpMsgBuf = LocalFree(lpMsgBuf);
|
||||||
|
return sRet;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ namespace uds
|
|||||||
bool ok = false;
|
bool ok = false;
|
||||||
if (rpc.Manager != null)
|
if (rpc.Manager != null)
|
||||||
{
|
{
|
||||||
logger.Debug("Informing broker of ready state");
|
logger.Info("Machine is Ready");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
List<Info.Computer.InterfaceInfo> interfaces = Info.Computer.GetInterfacesInfo();
|
List<Info.Computer.InterfaceInfo> interfaces = Info.Computer.GetInterfacesInfo();
|
||||||
@ -205,9 +205,21 @@ namespace uds
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void FlushLoggers()
|
||||||
|
{
|
||||||
|
log4net.Repository.ILoggerRepository rep = LogManager.GetRepository();
|
||||||
|
foreach (log4net.Appender.IAppender appender in rep.GetAppenders())
|
||||||
|
{
|
||||||
|
var buffered = appender as log4net.Appender.BufferingAppenderSkeleton;
|
||||||
|
if (buffered != null)
|
||||||
|
buffered.Flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void ResetId()
|
public static void ResetId()
|
||||||
{
|
{
|
||||||
logger.Debug("Reseting ID of rpc");
|
logger.Debug("Reseting ID of rpc");
|
||||||
|
FlushLoggers();
|
||||||
if (rpc.Manager != null)
|
if (rpc.Manager != null)
|
||||||
rpc.Manager._id = null;
|
rpc.Manager._id = null;
|
||||||
}
|
}
|
||||||
@ -215,6 +227,7 @@ namespace uds
|
|||||||
public static void ResetManager()
|
public static void ResetManager()
|
||||||
{
|
{
|
||||||
logger.Debug("Disabling rpc");
|
logger.Debug("Disabling rpc");
|
||||||
|
FlushLoggers();
|
||||||
rpc._manager = null;
|
rpc._manager = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
31
udsService/udsService/RPCAppender.cs
Normal file
31
udsService/udsService/RPCAppender.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using log4net;
|
||||||
|
|
||||||
|
namespace uds
|
||||||
|
{
|
||||||
|
|
||||||
|
public class RPCAppender : log4net.Appender.AppenderSkeleton
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sends the logging event to UDS
|
||||||
|
/// </summary>
|
||||||
|
override protected void Append(log4net.Core.LoggingEvent lEvent)
|
||||||
|
{
|
||||||
|
string message = RenderLoggingEvent(lEvent);
|
||||||
|
// Filters out messages that are FATAL or DEBUG
|
||||||
|
if (lEvent.Level == log4net.Core.Level.Critical || lEvent.Level == log4net.Core.Level.Fatal || lEvent.Level == log4net.Core.Level.Debug)
|
||||||
|
return;
|
||||||
|
|
||||||
|
rpc.Log(message, lEvent.Level.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This appender requires a <see cref="Layout"/> to be set.
|
||||||
|
/// </summary>
|
||||||
|
override protected bool RequiresLayout
|
||||||
|
{
|
||||||
|
get { return true; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,10 +13,12 @@ namespace uds.Services
|
|||||||
{
|
{
|
||||||
private static ILog logger = LogManager.GetLogger(typeof(Service));
|
private static ILog logger = LogManager.GetLogger(typeof(Service));
|
||||||
const int secsDelay = 5;
|
const int secsDelay = 5;
|
||||||
|
const int retrySecsDelay = 60;
|
||||||
|
|
||||||
private Thread _thread;
|
private Thread _thread;
|
||||||
private ManualResetEvent _stopEvent;
|
private ManualResetEvent _stopEvent;
|
||||||
private TimeSpan _delay;
|
private TimeSpan _delay;
|
||||||
|
private TimeSpan _retryDelay;
|
||||||
private bool _reboot;
|
private bool _reboot;
|
||||||
|
|
||||||
private static void SensLogon_Logon(string userName)
|
private static void SensLogon_Logon(string userName)
|
||||||
@ -71,6 +73,7 @@ namespace uds.Services
|
|||||||
_thread = null;
|
_thread = null;
|
||||||
_stopEvent = null;
|
_stopEvent = null;
|
||||||
_delay = new TimeSpan(0, 0, 0, secsDelay, 0);
|
_delay = new TimeSpan(0, 0, 0, secsDelay, 0);
|
||||||
|
_retryDelay = new TimeSpan(0, 0, 0, retrySecsDelay, 0);
|
||||||
_reboot = false;
|
_reboot = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,6 +116,10 @@ namespace uds.Services
|
|||||||
{
|
{
|
||||||
logger.Debug("Initiated Service main");
|
logger.Debug("Initiated Service main");
|
||||||
|
|
||||||
|
Dictionary<string, string> knownIps = new Dictionary<string, string>();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
// We have to wait till we have ip
|
// We have to wait till we have ip
|
||||||
List<Info.Computer.InterfaceInfo> interfaces = null;
|
List<Info.Computer.InterfaceInfo> interfaces = null;
|
||||||
while (interfaces == null)
|
while (interfaces == null)
|
||||||
@ -124,7 +131,7 @@ namespace uds.Services
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
logger.Error("Exception!!!",e);
|
logger.Error("Exception!!!", e);
|
||||||
}
|
}
|
||||||
if (interfaces == null)
|
if (interfaces == null)
|
||||||
{
|
{
|
||||||
@ -188,7 +195,7 @@ namespace uds.Services
|
|||||||
switch (data[0])
|
switch (data[0])
|
||||||
{
|
{
|
||||||
case "rename":
|
case "rename":
|
||||||
if (parms.Length == 1 )
|
if (parms.Length == 1)
|
||||||
// Do not have to change user password
|
// Do not have to change user password
|
||||||
Rename(parms[0], null, null, null);
|
Rename(parms[0], null, null, null);
|
||||||
else if (parms.Length == 4)
|
else if (parms.Length == 4)
|
||||||
@ -226,7 +233,6 @@ namespace uds.Services
|
|||||||
}
|
}
|
||||||
logger.Debug("Main loop waiting for ip change");
|
logger.Debug("Main loop waiting for ip change");
|
||||||
// Now, every secs delay, get if the interfaces ips changes and notify service
|
// Now, every secs delay, get if the interfaces ips changes and notify service
|
||||||
Dictionary<string, string> knownIps = new Dictionary<string, string>();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
foreach (Info.Computer.InterfaceInfo i in Info.Computer.GetInterfacesInfo())
|
foreach (Info.Computer.InterfaceInfo i in Info.Computer.GetInterfacesInfo())
|
||||||
@ -237,6 +243,11 @@ namespace uds.Services
|
|||||||
logger.Error("Could not accesss ip adresses!!", e);
|
logger.Error("Could not accesss ip adresses!!", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logger.Error(e);
|
||||||
|
}
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@ -273,13 +284,12 @@ namespace uds.Services
|
|||||||
|
|
||||||
private void Rename(string name, string user, string oldPass, string newPass)
|
private void Rename(string name, string user, string oldPass, string newPass)
|
||||||
{
|
{
|
||||||
logger.Info("Requested renaming of computer to \"" + name + "\"");
|
|
||||||
// name and newName can be different case, but still same
|
// name and newName can be different case, but still same
|
||||||
Info.DomainInfo info = Info.Computer.GetDomainInfo();
|
Info.DomainInfo info = Info.Computer.GetDomainInfo();
|
||||||
|
|
||||||
if ( string.Equals(info.ComputerName, name, StringComparison.CurrentCultureIgnoreCase))
|
if ( string.Equals(info.ComputerName, name, StringComparison.CurrentCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
logger.Info("Computer do not needs to be renamed");
|
logger.Info("Computer name is " + info.ComputerName);
|
||||||
rpc.SetReady();
|
rpc.SetReady();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -296,7 +306,7 @@ namespace uds.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Operation.RenameComputer(name) == false)
|
if (Operation.RenameComputer(name, _stopEvent, _retryDelay) == false)
|
||||||
{
|
{
|
||||||
logger.Error("Could not rename machine to \"" + name + "\"");
|
logger.Error("Could not rename machine to \"" + name + "\"");
|
||||||
rpc.ResetManager();
|
rpc.ResetManager();
|
||||||
@ -310,7 +320,6 @@ namespace uds.Services
|
|||||||
|
|
||||||
private void OneStepJoin(string name, string domain, string ou, string account, string pass)
|
private void OneStepJoin(string name, string domain, string ou, string account, string pass)
|
||||||
{
|
{
|
||||||
logger.Info("Requested one step join of computer to \"" + domain + "\" with name \"" + name + "\" under ou \"" + ou + "\"" );
|
|
||||||
// name and newName can be different case, but still same
|
// name and newName can be different case, but still same
|
||||||
Info.DomainInfo info = Info.Computer.GetDomainInfo();
|
Info.DomainInfo info = Info.Computer.GetDomainInfo();
|
||||||
if (string.Equals(info.ComputerName, name, StringComparison.CurrentCultureIgnoreCase))
|
if (string.Equals(info.ComputerName, name, StringComparison.CurrentCultureIgnoreCase))
|
||||||
@ -318,7 +327,7 @@ namespace uds.Services
|
|||||||
// We should be already in the domain, if not, will try second step of "multiStepJoin"
|
// We should be already in the domain, if not, will try second step of "multiStepJoin"
|
||||||
if(info.Status == Info.DomainInfo.NetJoinStatus.NetSetupDomainName ) // Already in domain
|
if(info.Status == Info.DomainInfo.NetJoinStatus.NetSetupDomainName ) // Already in domain
|
||||||
{
|
{
|
||||||
logger.Debug("Machine already in the domain");
|
logger.Info("Machine " + name + " in domain " + domain);
|
||||||
rpc.SetReady();
|
rpc.SetReady();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -327,14 +336,14 @@ namespace uds.Services
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Needs to rename + join
|
// Needs to rename + join
|
||||||
if (Operation.RenameComputer(name) == false)
|
if (Operation.RenameComputer(name, _stopEvent, _retryDelay) == false)
|
||||||
{
|
{
|
||||||
logger.Error("Could not rename machine to \"" + name + "\"");
|
logger.Error("Could not rename machine to \"" + name + "\"");
|
||||||
rpc.ResetManager();
|
rpc.ResetManager();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Now try to join domain
|
// Now try to join domain
|
||||||
if (Operation.JoinDomain(domain, ou, account, pass, true) == false)
|
if (Operation.JoinDomain(domain, ou, account, pass, true, _stopEvent, _retryDelay) == false)
|
||||||
{
|
{
|
||||||
logger.Error("Could not join domain \"" + domain + "\", ou \"" + ou + "\"");
|
logger.Error("Could not join domain \"" + domain + "\", ou \"" + ou + "\"");
|
||||||
rpc.ResetManager();
|
rpc.ResetManager();
|
||||||
@ -346,19 +355,18 @@ namespace uds.Services
|
|||||||
|
|
||||||
private void MultiStepJoin(string name, string domain, string ou, string account, string pass)
|
private void MultiStepJoin(string name, string domain, string ou, string account, string pass)
|
||||||
{
|
{
|
||||||
logger.Info("Requested two step join of computer to \"" + domain + "\" with name \"" + name + "\" under ou \"" + ou + "\"");
|
|
||||||
Info.DomainInfo info = Info.Computer.GetDomainInfo();
|
Info.DomainInfo info = Info.Computer.GetDomainInfo();
|
||||||
if (string.Equals(info.ComputerName, name, StringComparison.CurrentCultureIgnoreCase))
|
if (string.Equals(info.ComputerName, name, StringComparison.CurrentCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
// Name already, now see if already in domain
|
// Name already, now see if already in domain
|
||||||
if (info.Status == Info.DomainInfo.NetJoinStatus.NetSetupDomainName) // Already in domain
|
if (info.Status == Info.DomainInfo.NetJoinStatus.NetSetupDomainName) // Already in domain
|
||||||
{
|
{
|
||||||
logger.Debug("Machine already in the domain");
|
logger.Info("Machine " + name + " in domain " + domain);
|
||||||
rpc.SetReady();
|
rpc.SetReady();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Now try to join domain
|
// Now try to join domain
|
||||||
if (Operation.JoinDomain(domain, ou, account, pass, true) == false)
|
if (Operation.JoinDomain(domain, ou, account, pass, false, _stopEvent, _retryDelay) == false)
|
||||||
{
|
{
|
||||||
logger.Error("Could not join domain \"" + domain + "\", ou \"" + ou + "\"");
|
logger.Error("Could not join domain \"" + domain + "\", ou \"" + ou + "\"");
|
||||||
rpc.ResetManager();
|
rpc.ResetManager();
|
||||||
@ -368,7 +376,7 @@ namespace uds.Services
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Try to rename machine
|
// Try to rename machine
|
||||||
if (Operation.RenameComputer(name) == false)
|
if (Operation.RenameComputer(name, _stopEvent, _retryDelay) == false)
|
||||||
{
|
{
|
||||||
logger.Error("Could not rename machine to \"" + name + "\"");
|
logger.Error("Could not rename machine to \"" + name + "\"");
|
||||||
rpc.ResetManager();
|
rpc.ResetManager();
|
||||||
|
Loading…
Reference in New Issue
Block a user