GithubHelp home page GithubHelp logo

pyad's People

Contributors

a-r-d avatar bapthbrt avatar bardal avatar dhelonious avatar drryu avatar jhollowe avatar kavdev avatar lichray avatar livinthelookingglass avatar nocturem avatar stevenpitts avatar tcosprojects avatar tmunro55 avatar vince-ac avatar visch avatar zakird avatar zerok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyad's Issues

typo in adgroup.py

42 - pyADobj = ADObject(dn, options=self._make_options)
42 + pyADobj = ADObject(dn, options=self._make_options())

pip install pyad fails on Windows with UnicodeDecodeError

pip install fails with this message

>C:\Python35\Scripts\pip.exe install pyad
Collecting pyad
  Using cached pyad-0.5.14.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "C:\Users\yusafr\AppData\Local\Temp\1\pip-build-jno1fzq9\pyad\setup.py", line 26, in <module>
        long_description = read('README.rst'),
      File "C:\Users\yusafr\AppData\Local\Temp\1\pip-build-jno1fzq9\pyad\setup.py", line 7, in read
        return open(os.path.join(os.path.dirname(__file__), fname)).read()
      File "c:\python35\lib\encodings\cp1252.py", line 23, in decode
        return codecs.charmap_decode(input,self.errors,decoding_table)[0]
    UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 6116: character maps to <undefined>

    ----------------------------------------
←[31mCommand "python setup.py egg_info" failed with error code 1 in C:\Users\yusafr\AppData\Local\Temp\1\pip-build-jno1f
zq9\pyad←[0m

lastLogonTimestamp

So I was learning how to use pyad, and one of the things I was trying to accomplish was a simple script that prints the information in lastLogonTimestamp. However, when I print that attribute it comes out as

<COMObject <unknown>>

. I know that the time stored in that attribute is not in a normal date format, but now I'm left wondering if there is something else I'm missing.

About ACL set

pyad does not implement DACL、ACL part?
eg.
some user, open Properties-Advanced:
permissions\Auditing\Owner\Effective Permissions

If pyad not implement it, Could you give me some suggestion for implement them via python, thanks.

ADQuery does not support more than 1000 records

If a query executed via adquery.ADQuery() returns more than 1000 results, only the first 1000 results are shown. This is due to the following limitations (which are part of the Microsoft ADSI layer). See http://msdn.microsoft.com/en-us/library/windows/desktop/aa746459(v=vs.85).aspx and http://support.microsoft.com/kb/243281.

There is a (terrible) workaround if you are trying to iterate over just a contain orsimliar

ou = ADContainer.from_dn('ou=foo,dc=bar,dc=com')
for group in ou.get_children(recursive=True):
print group.dn

But ADQuery should be modified such that it makes the right calls through ADSI to be able to return a result set greater than 1000 records.

pyad.from_guid

Hi There in pyad.pyad.from_guid(cls, guid, options={}) does cls serve any purpose just looking at the function it is not immediately clear and when I send it a null value it still returns the group object is it essential?

Remove User from group

Does the ADUser.remove_from_group work? I run it and I do not get errors but I still see the user in the group. Same thing if I do ADgroup.remove_members()

adquery not imported by pyad

line

from . import aduser, adcomputer, addomain, addomain, adgroup, adobject, pyadconstants, adcontainer

in file pyad.py not contain "pyquery"
therefore code

q = pyad.adquery.ADQuery()

not work

Not all functions respect default options for ldap server ---- mostly looking at ADQuery interface

I had no problem with this snip
pyad.set_defaults(ldap_server=G_PYAD_CONFIG["ldap_server"], username=G_PYAD_CONFIG["username"], password=G_PYAD_CONFIG["password"])
ou = pyad.adcontainer.ADContainer.from_dn(TEST_OU)
testUser = pyad.aduser.ADUser.create(self.testUserName, ou)

but this snip throws because of no default domain.
pyad.set_defaults(ldap_server=G_PYAD_CONFIG["ldap_server"], username=G_PYAD_CONFIG["username"], password=G_PYAD_CONFIG["password"])
testUser = pyad.aduser.ADUser.from_cn(self.testUserName)

File "test_fs2405.py", line 134, in test_newUser_ADToDirectory
testUser = pyad.aduser.ADUser.from_cn(self.testUserName)
File "C:\Python27\lib\site-packages\pyad\adobject.py", line 132, in from_cn
return cls(adsearch.by_cn(cn, search_base, options), None, options)
File "C:\Python27\lib\site-packages\pyad\adsearch.py", line 9, in by_cn
raise Exception("Unable to detect default domain. Must specify search base.")
Exception: Unable to detect default domain. Must specify search base.

ERROR : u'Microsoft OLE DB Service Components', u'The parameter is incorrect.'

Hi, I am trying to pull the users from Active directory but when i am using adquery module gives me the following error
Traceback (most recent call last):
File "", line 1, in
File "", line 3, in Open
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 282, in ApplyTypes
result = self.oleobj.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Microsoft OLE DB Service Components', u'The parameter is incorrect.', None, 0, -21470
24809), None)

and this was causing because of the statement self.__adodb_conn.Open("Provider=ADSDSOObject") line no 38 file adquery.py(version pyad-master 0.5.15)

so, i tried by line by line code from the interpretor and replaced self.__adodb_conn.Open("ADSDSOObject") of line 38(above) then it is working fine but i havent seen this problem in pyad-0.5.14.tar.gz version , I am able to create object to the ADQuery class as shown below
**>>> from pyad import *

qobj = adquery.ADQuery()**

Doc: what attributes are available for person object?

This is probably a documentation issue, not a bug; with #34 solved I bump into my next question: What attributes are available for reporting from a person object?

from pyad import adgroup
group = adgroup.ADGroup.from_dn(group_name + org_unit + domain)
members = group.get_members()
peep = members[70]
print peep.displayname, peep.description

Successful result:

Perry.Smith Tiddlywinks Administrator

So have something that works for displaying the name and description for a single user but I want to display more information such as phone number, office location, etc. I don't know how to find out attributes are available for reporting. For example peep.displayname which clearly works is not in the list returned by dir(peep).

Special characters in OU are not supported

If I have special characters(e.g. #) in OU name and I try to get members of the group whose dn has # in it then adgroup.get_members fails with following exception.

"(-2147352567, 'Exception occurred.', (0, u'Active Directory', u'There is no such object on the server.\r\n', None, 0, -2147016656), None)"

Test Data:
groupdn is "CN=Test,OU=Test#,DC=child1,DC=cloudad,DC=pune,DC=xyz,DC=com" and its member user's dn is "CN=test123,OU=Test#,DC=child1,DC=cloudad,DC=pune,DC=xyz,DC=com"

Code I executed,
group = adgroup.ADGroup.from_dn(groupdn)
members = group.get_members(recursive)

This fails in the adgroup._get_members function.

Root cause:
When dn has special character then its escaped with \ by active directory. e.g. "CN=test123,OU=Test#,DC=child1,DC=cloudad,DC=pune,DC=xyz,DC=com" is returned as "CN=test123,OU=Test#,DC=child1,DC=cloudad,DC=pune,DC=xyz,DC=com" this causes with no such object exception.

Solution:
Replacing \ from the dn solves this issue.
added following line at adgroup.py line # 42,
dn = dn.replace('', '')

PIP Install fails due to outdated version on PyPI

PIP installation fails with 'pip install pyad' with the following result:

Collecting pyad
Downloading pyad-0.5.14.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\cgray\AppData\Local\Temp\1\pip-build-d7g42e5w\pyad\setup.py", line 26, in
long_description = read('README.rst'),
File "C:\Users\cgray\AppData\Local\Temp\1\pip-build-d7g42e5w\pyad\setup.py", line 7, in read
return open(os.path.join(os.path.dirname(file), fname)).read()
File "c:\users\cgray\python\venv\adobe\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 6116: character maps to

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in C:\Users\cgray\AppData\Local\Temp\1\pip-build-d7g42e5w\pyad\

This is resulting from the quotes in the last paragraph of the readme. This has been corrected in the source files in the repository, but the package on PyPI is outdated.

Will the package be updated on PyPI?

issue with ADquery with string containing single quote

Hi there

I'm working on a piece of software to take group data from a
propriatory system and syncronise that data in to AD groups.

It's all going well and pyad is working well, except where I'm dealing
with users that have apostrophies in their names:

For example Dave O'Connor

I've tried escaping the ' with a \ but it still seems to error.

Is there a different escape character I need to use?

It seems to error on query and create at least with a string with a ' in?

Many thanks

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

from pyad import pyad
from pyad import adquery
q = adquery.ADQuery()
query = "cn = 'O'Connell'"
q.execute_query(where_clause = query)
Traceback (most recent call last):
File "", line 1, in
File "c:\python27\lib\site-packages\pyad-0.4.10-py2.7.egg\pyad\adquery.py",
line 23, in execute_query
File "", line 3, in Execute
File "c:\python27\lib\site-packages\win32com\client\dynamic.py",
line 276, in ApplyTypes
result = self.oleobj.InvokeTypes((dispid, LCID, wFlags,
retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0,
u'Provider', u'One or more errors occurred during processing of
command.', None, 1240640, -2147217900), None)
query = "cn = O'Connell"
q.execute_query(where_clause = query)
Traceback (most recent call last):
File "", line 1, in
File "c:\python27\lib\site-packages\pyad-0.4.10-py2.7.egg\pyad\adquery.py",
line 23, in execute_query
File "", line 3, in Execute
File "c:\python27\lib\site-packages\win32com\client\dynamic.py",
line 276, in ApplyTypes
result = self.oleobj.InvokeTypes(
(dispid, LCID, wFlags,
retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0,
u'Provider', u'One or more errors occurred during processing of
command.', None, 1240640, -2147217900), None)

Possible to connect to alternate *domain*?

Hi,

I am trying to use pyad to automate some directory activities, but it seems no matter what I provide to pyad.set_defaults() I am always connected to the production domain. I operate alternative domains for testing environments and I am not sure what I can do to connect to those domains when testing my code.

I have tried passing the DNS name and the IP address of the development domain controller to set_defaults() as well as part of the options argument of specific calls but from what I can tell things are always resolved to the domain to which my user is currently attached.

pyad.pyadexceptions.win32Exception: 0x80070005: Access is denied.

When I create a new object, I have below error message always.

pyad.pyadexceptions.win32Exception: 0x80070005: Access is denied.

I would like to know if it is pyad error or my AD sever configuration error.

Thank you.

(Code:)
from pyad import *
pyad.set_defaults(ldap_server="IT-LHQ-DC1.LIFEALIKE.LAB", username="administrator", password="password")
ou = pyad.adcontainer.ADContainer.from_dn("ou=All_Users, dc=LIFEALIKE, dc=LAB")
new_user = pyad.aduser.ADUser.create("test.02", ou, password="password")

(Result:)
Traceback (most recent call last):
File "E:\WEB_WORK\Python\test2\list.py", line 6, in
new_user = pyad.aduser.ADUser.create("test.02", ou, password="password")
File "C:\Python27\lib\site-packages\pyad\aduser.py", line 16, in create
optional_attributes=optional_attributes
File "C:\Python27\lib\site-packages\pyad\adcontainer.py", line 47, in create_u
ser
pyadutils.pass_up_com_exception(e)
File "C:\Python27\lib\site-packages\pyad\pyadutils.py", line 58, in pass_up_co
m_exception
raise WIN32_ERRORS.get(info['error_num'], win32Exception)(error_info=info, a
dditional_info=additional_info)
pyad.pyadexceptions.win32Exception: 0x80070005: Access is denied.

ImportError: cannot import name pyad

hello,Zakir
I have install pywin32 and pyad ,but when I import pyad ,my Pycharm shows "ImportError: cannot import name pyad"
how about it !
Thank you for ur reply~

Unable to import any module

Hi Zakir

I've just started python, I'm installing the pyad module using setup.py -install method and it says installed successfully and .egg file is also copied to site-packages folder.

But when I run this "from pyad import aduser" it throws error :
Traceback (most recent call last):
File "pyad.py", line 1, in
from pyad import aduser
File "C:\Users\Paul\Documents\Python\pyad.py", line 1, in
from pyad import aduser
ImportError: cannot import name aduser

Can you help me out on this.

Thank You!

Python 3 Support

I just ran "futurize" on this package and after some very brief testing it appears to make everything both Python 2 and Python 3 compatible. Are you interested in Python 3 support for this package as well?

Unable to query the AD after setting set_defaults with valid credentials

Hi,

I have tried without setting set_defaults its working fine and able get the data but if I set the default credentials to valid one then it throws "server is not operational error".

a =ADQuery()
a.execute_query(where_clause="name='ou1'")
Traceback (most recent call last):
File "", line 1, in
File "pyad\adquery.py", line 78, in execute_query
self.__rs, self.__rc = command.Execute()
File "", line 3, in Execute
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 282, in
ApplyTypes
result = self.oleobj.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes
) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Active Director
y', u'The server is not operational.\r\n', None, 0, -2147217865), None)

recursive calls within group.get_members

I'v got a group object and I'm calling g.get_members(recursive=True,
ignoreGroups=True) and for some groups it works fine, but for others I
get the following output:

Traceback (most recent call last):
File "ManagedBy2Owners.py", line 84, in
mb2o.sync()
File "ManagedBy2Owners.py", line 72, in sync
members = o.get_members(recursive=True, ignoreGroups=True)
File "c:\Python27\lib\site-packages\pyad-0.4.17-py2.7.egg\pyad\adgroup.py",
line 29, in get_members
File "c:\Python27\lib\site-packages\pyad-0.4.17-py2.7.egg\pyad\adgroup.py",
line 42, in _get_members
File "c:\Python27\lib\site-packages\pyad-0.4.17-py2.7.egg\pyad\adobject.py",
line 114, in getattr
AttributeError: _get_members

Package on PyPI missing README.rst

attempting to install the package available on PyPI via pip or manually results in the following error log:

------------------------------------------------------------
C:\Python27\Scripts\pip-script.py run on 08/08/12 16:17:34
Downloading/unpacking pyad
  Running setup.py egg_info for package pyad
    Traceback (most recent call last):
      File "<string>", line 14, in <module>
      File "C:\Python27\Scripts\build\pyad\setup.py", line 23, in <module>
        long_description = read('README.rst'),
      File "C:\Python27\Scripts\build\pyad\setup.py", line 6, in read
        return open(os.path.join(os.path.dirname(__file__), fname)).read()
    IOError: [Errno 2] No such file or directory: 'C:\\Python27\\Scripts\\build\\pyad\\README.rst'
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 14, in <module>

  File "C:\Python27\Scripts\build\pyad\setup.py", line 23, in <module>

    long_description = read('README.rst'),

  File "C:\Python27\Scripts\build\pyad\setup.py", line 6, in read

    return open(os.path.join(os.path.dirname(__file__), fname)).read()

IOError: [Errno 2] No such file or directory: 'C:\\Python27\\Scripts\\build\\pyad\\README.rst'

----------------------------------------
Command python setup.py egg_info failed with error code 1
Exception information:
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\pip-1.0.2-py2.7.egg\pip\basecommand.py", line 126, in main
    self.run(options, args)
  File "C:\Python27\lib\site-packages\pip-1.0.2-py2.7.egg\pip\commands\install.py", line 223, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "C:\Python27\lib\site-packages\pip-1.0.2-py2.7.egg\pip\req.py", line 986, in prepare_files
    req_to_install.run_egg_info()
  File "C:\Python27\lib\site-packages\pip-1.0.2-py2.7.egg\pip\req.py", line 222, in run_egg_info
    command_desc='python setup.py egg_info')
  File "C:\Python27\lib\site-packages\pip-1.0.2-py2.7.egg\pip\__init__.py", line 255, in call_subprocess
    % (command_desc, proc.returncode))
InstallationError: Command python setup.py egg_info failed with error code 1

Unable to move/rename Users

So i've set the defaults to the remote server and with the administrator username and password.
pyad.set_defaults(ldap_server="[server_ip]", username="administrator", password="[admin_password")

then i query the user and the container i want to move the user to:
user = pyad.aduser.ADUser.from_dn("cn= Test Category2Renamed, ou=[censored], ou=[censored], ou=[censored], dc=[censored], dc=[censored]")
ou = pyad.adcontainer.ADContainer.from_dn("ou=[censored], ou=[censored], ou=[censored], dc=[censored], dc=[censored]")

these all worked perfectly, but the moment i run:
user.move(ou) or user.rename('renamed')

I always get this error:
error

Has no one ran into this issue?

unable to create user - character limit 20

Hello,

I try to create a user as following :

ou = pyad.adcontainer.ADContainer.from_dn("OU=Users, DC=company, DC=local")
new_user = pyad.adcontainer.ADUser.create("Anne XXXXXX XXX XXXXXXXX", ou, password="Passw0rd", upn_suffix="@company.local", optional_attributes = {"samaccountname":"htest","userPrincipalName":login + "@company.local","givenname":"Hugo","sn":"Test","displayName":"Hugo Test"})

I got an error :

c:\>C:\Users\hugo\Desktop\user_ad.py
Traceback (most recent call last):
  File "C:\Users\hugo\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyad\adcontainer.py", line 38, in create_user
    obj.SetInfo()
  File "<COMObject <unknown>>", line 2, in SetInfo
pywintypes.com_error: (-2147352567, 'Une exception s\u2019est produite.', (0, 'A
ctive Directory', 'Un périphérique attaché au système ne fonctionne pas correcte
ment.\r\n', None, 0, -2147024865), None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\hugo\Desktop\user_ad.py", line 13, in <module>
    new_user = pyad.adcontainer.ADUser.create("Anne XXXXXX XXX XXXXXXXX", ou, pa
ssword="Passw0rd", upn_suffix="@company.local", optional_attributes = {"samaccou
ntname":"htest","userPrincipalName":login + "@company.local","givenname":"Hugo",
"sn":"Test","displayName":"Hugo Test"})
  File "C:\Users\hugo\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyad\aduser.py", line 16, in create
    optional_attributes=optional_attributes
  File "C:\Users\hugo\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyad\adcontainer.py", line 47, in create_user
    pyadutils.pass_up_com_exception(e)
  File "C:\Users\hugo\AppData\Local\Programs\Python\Python35-32\lib\site-pack
ages\pyad\pyadutils.py", line 58, in pass_up_com_exception
    raise WIN32_ERRORS.get(info['error_num'], win32Exception)(error_info=info, a
dditional_info=additional_info)
pyad.pyadexceptions.win32Exception: 0x8007001f: Un périphérique attaché au systè
me ne fonctionne pas correctement.

After some test it appears that it works if name field is 20 character max.
Are you aware of this limitation ? from windows point of view it should be OK.

Regards,

How to retrieve members of a group?

I've been unable to deduce how to retrieve a list of group members. I don't know whether it's because I'm not very python savvy or I've stumbled over pyad bug. Here's my code:

from pyad import adgroup
group = adgroup.ADGroup.from_dn(unit + domain)
print(group)

for user in group.get_members():
    print(user.description)

and result:

<ADGroup 'CN=my-group,OU=OurDept,OU=Users and Groups,DC=example,DC=org'>
Traceback (most recent call last):
  File "C:\Python27\ArcGIS10.3\lib\bdb.py", line 400, in run
    exec cmd in globals, locals
  File "D:\code\ENV\list-ad-users.py", line 1, in <module>
    domain = "DC=example,DC=org"
  File "D:\code\ENV\list-ad-users.py", line 20, in two
    for user in group.get_members():
  File "C:\Python27\ArcGIS10.3\lib\site-packages\pyad\adgroup.py", line 32, in get_members
    return self._get_members(recursive, ignoreGroups, [])
  File "C:\Python27\ArcGIS10.3\lib\site-packages\pyad\adgroup.py", line 43, in _get_members
    pyADobj.adjust_pyad_type()
  File "C:\Python27\ArcGIS10.3\lib\site-packages\pyad\adobject.py", line 516, in adjust_pyad_type
    raise Exception("Unkown type. Adjustment not possible.")
Exception: Unkown type. Adjustment not possible.

Not able to fetch the objects from child domain

Hi,
I am getting a referer always when i am trying to connect child domain or the server is not operational, can you give some example to get the objects from child domain using pyad

One more observation is the users are getting pulled on port 636 but not working 389 can i know why this is happening like this

Cannot get users from 'Domain Users' group

Hello

I am trying to get all users from 'Domains Users' group:
import pyad.adgroup group = pyad.adgroup.ADGroup.from_guid("cd86aaa7-0d45-4a60-b6e5-5bd554735133") print group members = group.get_members() print members

But get only blank list []

Group detected correctly

<ADGroup 'CN=Users,CN=Builtin,DC=domain1,DC=tld,DC=biz'>

I also tried to use DN (pyad.adgroup.ADGroup.from_dn) but with the same result. If I use another DN/SID - all works correctly:

import pyad.adgroup group=pyad.adgroup.ADGroup.from_dn("CN=AllResellersGroup,OU=Services,OU=panel,DC=domainad1,DC=tld,DC=biz") print group

<ADGroup 'CN=AllResellersGroup,OU=Services,OU=cPanel,DC=domainad1,DC=tld,DC=biz'>
[<ADObject 'CN=ACTeamB,OU=ACTeamB,OU=Admin,OU=panel,DC=domainad1,DC=tld,DC=biz'>, <ADObject 'CN=I40135,OU=I40135,OU=infolin2,OU=Admin,OU=panel,DC=domainad1,DC=tld,DC=biz'>, ... , etc

Please help

from_cn returns multiple results

I have cross forest trust in place and am using from_cn to return a handle on an individual domains administrator.

The following line of code...

adhandle=aduser.ADUser.from_cn(user,options=dict(ldap_server=dns))

Gives an exception when the user var is set to administrator and states ...

Traceback (most recent call last):
File "", line 1001, in
File "", line 796, in connect
File "C:\nwscript\build\nwscipt\out00-PYZ.pyz\pyad.adobject", line 132, in fro
m_cn
File "C:\nwscript\build\nwscipt\out00-PYZ.pyz\pyad.adsearch", line 17, in by_c
n
File "C:\nwscript\build\nwscipt\out00-PYZ.pyz\pyad.adquery", line 73, in get_s
ingle_result
pyad.pyadexceptions.invalidResults: The specified query resturned 3 results. get
SingleResults only functions with a single result.

By default how can an AD query for CN return multiple results, and if it is due to the cross forest trust how can you scope the query ?

Any thoughts ?

Cannot modify Attributes

Every time I try to modify an attribute, this is what I get.

user.set_attribute("description","meh")
Traceback (most recent call last):
File "", line 1, in
File "c:\Python27\lib\site-packages\pyad\adobject.py", line 191, in getattr
raise AttributeError(attribute)
AttributeError: set_attribute

Any ideas on what I might be doing wrong?

adgroup.py - NameError: global name 'pyAD' is not defined

in adgroup.py line 39:
instead of
pyADobj = pyAD(dn)
should be
pyADobj = ADObject(dn)

Otherwise you get error:
File "C:\Python27\lib\site-packages\pyad-0.4.10-py2.7.egg\pyad\adgroup.py", line 39, in _get_members
pyADobj = pyAD(dn)
NameError: global name 'pyAD' is not defined

Want to manipulate windows AD remotely on linux

Hi,
Nice to find a python plugin which can manipulate the windows AD.
But I found it can't be installed on linux.

I also found an equivalent python-ldap on linux.
I can add user by some code similar with here: http://stackoverflow.com/questions/2273117/django-python-ldap-unwilling-to-perform-info-00002077-svcerr-dsid-031907b

However, I found it can only create a user without setting password.

Is there any way I can create a user in windows AD remotely from a linux server and set the user with the password I want?

Any suggestion will be appreciated!!
Thanks!

help needed to create python script with active directory

Hi,
I am currently doing a project to copy folders with users and groups from active directory in server 1 to server 2. I found that your code should be able to help me but since I'm unfamiliar with Python and Active Directory, I hope that you can guide me.
Here is what I want to do.

  • connect with AD
  • create AD object that holds the users and groups
  • the object will lop through the list of users and groups in AD
  • it will copy the users and groups permission.

I really hope you can guide me.

Thanks.

CN vs sAMAccountName in create_user

Currently adcontainer.create_user sets both the common name and the sAMAccountName to the same value. These fields have different length restrictions with the latter most often being limited to 20 chars. Would it make sense to add another optional argument to the create_user function that contains the value for sAMAccountName and uses the name if not provided?

We currently run into the issue that we use the CN for the complete name of a person, which quite often is not a viable option for the sAMAccountName. For this reason we currently provide a fitting login in the optional_attributes but the are only used after the first attempt has been made to save the user.

This results in errors like this:

   ...
    optional_attributes=add_attr)
  File "C:\srv\proj.env\lib\site-packages\pyad\adcontainer.py", line 46, in create_user
    pyadutils.pass_up_com_exception(e)
  File "C:\srv\proj.env\lib\site-packages\pyad\pyadutils.py", line 52, in pass_up_com_exception
    raise WIN32_ERRORS.get(info['error_num'], win32Exception)(error_info=info, additional_info=additional_info)
win32Exception: 0x8007001f: A device attached to the system is not functioning.

Not the most useful error message by the underlying system ;-)

Unable to authenticate

I've created a script to pull information out of my default AD with no problem. I've now pointed to a different AD using this code.

pyad.set_defaults(ldap_server=u'bar.example.com', username=u'username', password=u'password')

But I am getting this error when the script is run.

Traceback (most recent call last):
File "C:\path\to\file.py", line 168, in
main()
File "C:\path\to\file.py", line 25, in main
q = adquery.ADQuery()
File "build\bdist.win32\egg\pyad\adquery.py", line 32, in init
File "C:\Python27\lib\site-packages\win32com\client\dynamic.py", line 576, in setattr
raise AttributeError("Property '%s.%s' can not be set." % (self.username, attr))
AttributeError: Property '.value' can not be set.

I've tested using other tools and I do have access to that AD using the same server/login combo. Another thing I've tried is connecting to my default AD using credentials to see if I get the same error and I in fact do.

Is this a bug in setting defaults or am I using that line incorrectly?

problem with pyad installation

when i try to setup i got error message:
C:\Users\tzurielya\Desktop\pyad-master>setup.py install
Traceback (most recent call last):
File "C:\Users\tzurielya\Desktop\pyad-master\setup.py", line 26, in
long_description = read('README.rst'),
File "C:\Users\tzurielya\Desktop\pyad-master\setup.py", line 7, in read
return open(os.path.join(os.path.dirname(file), fname)).read()
File "C:\Python33\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 6116: cha
racter maps to

help please:)

NameError: name '_adsi_provider' is not defined

Hi!
Pyad was running nicely until your last update. It seems to fail at connecting to the domain, but I'm guessing is only because of an undefined variable...

WARN: unable to connect to default domain. Computer is likely not attached to an AD domain
File "D:\pyad\pyad__init__.py", line 1, in
from adbase import set_defaults as pyad_setdefaults
File "D:\pyad\pyad\adbase.py", line 39, in
class ADBase(object):
File "D:\pyad\pyad\adbase.py", line 65, in ADBase
adsi_provider = _adsi_provider
NameError: name '_adsi_provider' is not defined

Setting Primary Group

How might someone set the primary group for a user with pyad? Is that something that is implemented?

Querying Domain objects with a computer thats not joined to the domain

I'm trying to run the instructions from

https://pypi.python.org/pypi/pyad

which stipulates to use the below command to query another domain

from pyad import *
pyad.set_defaults(ldap_server="dc1.domain.com", username="service_account", password="mypassword")
user = pyad.aduser.ADUser.from_cn("myuser")

However when i do so, i get the following error

WARN: unable to connect to default domain. Computer is likely not attached to an AD domain
Traceback (most recent call last):
File "C:/Users//Documents/Projekt1/Demo.py", line 6, in
user = pyad.aduser.ADUser.from_cn("myuser")
File "C:\Python\lib\site-packages\pyad\adobject.py", line 135, in from_cn
return cls(adsearch.by_cn(cn, search_base, options), None, options)
File "C:\Python\lib\site-packages\pyad\adsearch.py", line 10, in by_cn
raise Exception("Unable to detect default domain. Must specify search base.")
Exception: Unable to detect default domain. Must specify search base.

Process finished with exit code 1

How do i fix this

adobject, __set_adsi_obj argument

Hi Zakir,

In adobject.py, _ _set_adsi_obj requires an argument 'distinguished_name' and _ init _ is calling it that way. However, move and rename don't supply any arguments so they raise an exception.

I believe 'distinguished_name' is not used in _ _set_adsi_obj. Can we remove it?

Bas

Question: ADQuery

When performing an ADQuery, is there a way to pull all attributes, or all attributes with a value? Or, do I need to explicitly add each attribute to the attributes parameter?

Could not rename a computer name

Code:
computer = adcomputer.ADComputer.from_cn('WS-490')

computer.rename('WS-4900')

Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\utility\test.py", line 25, in
computer.rename('WS-4900')
File "C:\Python27\lib\site-packages\pyad\adobject.py", line 419, in rename
parent = self.parent_container
File "C:\Python27\lib\site-packages\pyad\adobject.py", line 517, in __get_parent_container
q.adjust_pyad_type()
File "C:\Python27\lib\site-packages\pyad\adobject.py", line 512, in adjust_pyad_type
raise Exception("Unkown type. Adjustment not possible.")
Exception: Unkown type. Adjustment not possible.

Could not remove a contact account

when i created a contact, i can use the pyad to create a contact like followed:
def new_contact(contact_cn, container_cn):
"""Create a new contact object in the container"""
try:
mycont = adcontainer.ADContainer.from_cn(container_cn)
obj = mycont._ADContainer__create_object('contact', contact_cn)
obj.SetInfo()
return adobject.ADObject.from_com_object(obj)
except pywintypes.com_error, e:
pyadutils.pass_up_com_exception(e)
But when i want to remove the contact like followed, it failed.
def remove_obj(obj_dn):
obj = adcontainer.ADContainer.from_dn(obj_dn)# in the function, it convert the object type to 'user', I do not know why you changed it and how to define the type of a object.
obj.delete()

If you can solve the problem, i think it is better.

Setting ADS_SCOPE_SUBTREE = 2

How do I set the scope for ADQuery? My queries seem to be using a base scope rather than a subtree scope.

Thank you.

Create the same group on different container fail

Steps,

  1. Create group1 in Users container
  2. Create group1 in Computers container
    Error show:
    Traceback (most recent call last):
    File "C:\CA\Library\ad\group.py", line 124, in
    add_group_object('group1','Computers ')
    File "C:\CA\Library\ad\group.py", line 121, in add_group_object
    adgroup.ADGroup.create(group_cn,container)
    File "C:\Python27\lib\site-packages\pyad\adgroup.py", line 12, in create
    optional_attributes=optional_attributes)
    File "C:\Python27\lib\site-packages\pyad\adcontainer.py", line 62, in create_group
    pyadutils.pass_up_com_exception(e)
    File "C:\Python27\lib\site-packages\pyad\pyadutils.py", line 52, in pass_up_com_exception
    raise WIN32_ERRORS.get(info['error_num'], win32Exception)(error_info=info, additional_info=additional_info)
    pyad.pyadexceptions.win32Exception: 0x80071392: The object already exists.

Coding:
adgroup.ADGroup.create('group1','Users')
adgroup.ADGroup.create('group1','Computers')

pyad Import Fails Due to Inability to Access LDAP://rootDSE

When simply importing pyad from the Python interpreter, I get this output:

>>> import pyad
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\pyad-0.5.08-py2.7.egg\pyad\__init__.py", line 1, in <module>
    from adbase import set_defaults as pyad_setdefaults
  File "C:\Python27\lib\site-packages\pyad-0.5.08-py2.7.egg\pyad\adbase.py", line 26, in <module>
    __default_domain_obj = _adsi_provider.GetObject('', "LDAP://rootDSE")
  File "<COMObject ADsNameSpaces>", line 2, in GetObject
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, u'Active Directory', u'The specified domain either does not exist or could not be contacted.\r\n
, None, 0, -2147023541), None)

This is with ActivePython 2.7.

If I just wrap the lines which set the default objects to None on exception, I can import it, but there's probably a better solution:

# Discover default domain and forest information
try:
    __default_domain_obj = _adsi_provider.GetObject('', "LDAP://rootDSE")

# connecting to rootDSE will connect to the domain that the
# current logged-in user belongs to.. which is generally the
# domain under question and therefore becomes the default domain.
    _default_detected_forest = __default_domain_obj.Get("rootDomainNamingContext")
    _default_detected_domain = __default_domain_obj.Get("defaultNamingContext")
except:
    __default_domain_obj = None
    _default_detected_forest = None
    _default_detected_domain = None

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.