libads/ldap_user.c

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    ads (active directory) utility library
00004    Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002
00005    
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015    
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 
00021 #include "includes.h"
00022 
00023 #ifdef HAVE_ADS
00024 
00025 /*
00026   find a user account
00027 */
00028  ADS_STATUS ads_find_user_acct(ADS_STRUCT *ads, LDAPMessage **res,
00029                                const char *user)
00030 {
00031         ADS_STATUS status;
00032         char *ldap_exp;
00033         const char *attrs[] = {"*", NULL};
00034         char *escaped_user = escape_ldap_string_alloc(user);
00035         if (!escaped_user) {
00036                 return ADS_ERROR(LDAP_NO_MEMORY);
00037         }
00038 
00039         asprintf(&ldap_exp, "(samAccountName=%s)", escaped_user);
00040         status = ads_search(ads, res, ldap_exp, attrs);
00041         SAFE_FREE(ldap_exp);
00042         SAFE_FREE(escaped_user);
00043         return status;
00044 }
00045 
00046 ADS_STATUS ads_add_user_acct(ADS_STRUCT *ads, const char *user, 
00047                              const char *container, const char *fullname)
00048 {
00049         TALLOC_CTX *ctx;
00050         ADS_MODLIST mods;
00051         ADS_STATUS status;
00052         const char *upn, *new_dn, *name, *controlstr;
00053         char *name_escaped = NULL;
00054         const char *objectClass[] = {"top", "person", "organizationalPerson",
00055                                      "user", NULL};
00056 
00057         if (fullname && *fullname) name = fullname;
00058         else name = user;
00059 
00060         if (!(ctx = talloc_init("ads_add_user_acct")))
00061                 return ADS_ERROR(LDAP_NO_MEMORY);
00062 
00063         status = ADS_ERROR(LDAP_NO_MEMORY);
00064 
00065         if (!(upn = talloc_asprintf(ctx, "%s@%s", user, ads->config.realm)))
00066                 goto done;
00067         if (!(name_escaped = escape_rdn_val_string_alloc(name)))
00068                 goto done;
00069         if (!(new_dn = talloc_asprintf(ctx, "cn=%s,%s,%s", name_escaped, container,
00070                                        ads->config.bind_path)))
00071                 goto done;
00072         if (!(controlstr = talloc_asprintf(ctx, "%u", (UF_NORMAL_ACCOUNT | UF_ACCOUNTDISABLE))))
00073                 goto done;
00074         if (!(mods = ads_init_mods(ctx)))
00075                 goto done;
00076 
00077         ads_mod_str(ctx, &mods, "cn", name);
00078         ads_mod_strlist(ctx, &mods, "objectClass", objectClass);
00079         ads_mod_str(ctx, &mods, "userPrincipalName", upn);
00080         ads_mod_str(ctx, &mods, "name", name);
00081         ads_mod_str(ctx, &mods, "displayName", name);
00082         ads_mod_str(ctx, &mods, "sAMAccountName", user);
00083         ads_mod_str(ctx, &mods, "userAccountControl", controlstr);
00084         status = ads_gen_add(ads, new_dn, mods);
00085 
00086  done:
00087         SAFE_FREE(name_escaped);
00088         talloc_destroy(ctx);
00089         return status;
00090 }
00091 
00092 ADS_STATUS ads_add_group_acct(ADS_STRUCT *ads, const char *group, 
00093                               const char *container, const char *comment)
00094 {
00095         TALLOC_CTX *ctx;
00096         ADS_MODLIST mods;
00097         ADS_STATUS status;
00098         char *new_dn;
00099         char *name_escaped = NULL;
00100         const char *objectClass[] = {"top", "group", NULL};
00101 
00102         if (!(ctx = talloc_init("ads_add_group_acct")))
00103                 return ADS_ERROR(LDAP_NO_MEMORY);
00104 
00105         status = ADS_ERROR(LDAP_NO_MEMORY);
00106 
00107         if (!(name_escaped = escape_rdn_val_string_alloc(group)))
00108                 goto done;
00109         if (!(new_dn = talloc_asprintf(ctx, "cn=%s,%s,%s", name_escaped, container,
00110                                        ads->config.bind_path)))
00111                 goto done;
00112         if (!(mods = ads_init_mods(ctx)))
00113                 goto done;
00114 
00115         ads_mod_str(ctx, &mods, "cn", group);
00116         ads_mod_strlist(ctx, &mods, "objectClass",objectClass);
00117         ads_mod_str(ctx, &mods, "name", group);
00118         if (comment && *comment) 
00119                 ads_mod_str(ctx, &mods, "description", comment);
00120         ads_mod_str(ctx, &mods, "sAMAccountName", group);
00121         status = ads_gen_add(ads, new_dn, mods);
00122 
00123  done:
00124         SAFE_FREE(name_escaped);
00125         talloc_destroy(ctx);
00126         return status;
00127 }
00128 #endif

Sambaに対してSat Aug 29 21:23:01 2009に生成されました。  doxygen 1.4.7