svn commit: samba r9436 - in branches/SOC/SAMBA_3_0/source: include libmsrpc libmsrpc/test libmsrpc/test/sam

skel at samba.org skel at samba.org
Sat Aug 20 22:50:13 GMT 2005


Author: skel
Date: 2005-08-20 22:50:13 +0000 (Sat, 20 Aug 2005)
New Revision: 9436

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=9436

Log:
added cac_SamEnableUser() - needs to be fixed


Added:
   branches/SOC/SAMBA_3_0/source/libmsrpc/test/sam/enable.c
Modified:
   branches/SOC/SAMBA_3_0/source/include/libmsrpc.h
   branches/SOC/SAMBA_3_0/source/libmsrpc/cac_samr.c
   branches/SOC/SAMBA_3_0/source/libmsrpc/test/Makefile


Changeset:
Modified: branches/SOC/SAMBA_3_0/source/include/libmsrpc.h
===================================================================
--- branches/SOC/SAMBA_3_0/source/include/libmsrpc.h	2005-08-20 22:47:53 UTC (rev 9435)
+++ branches/SOC/SAMBA_3_0/source/include/libmsrpc.h	2005-08-20 22:50:13 UTC (rev 9436)
@@ -1570,6 +1570,24 @@
 int cac_SamSetAliasMembers(CacServerHandle *hnd, TALLOC_CTX *mem_ctx, struct SamSetAliasMembers *op);
 
 
+struct SamUserChangePasswd {
+   struct {
+      /**The username*/
+      char *username;
+
+      /**The current password*/
+      char *password;
+
+      /**The new password*/
+      char *new_password;
+   } in;
+};
+/**Used by a user to change their password*/
+int cac_SamUserChangePasswd(CacServerHandle *hnd, TALLOC_CTX *mem_ctx, struct SamUserChangePasswd *op);
+
+/*Enables a user*/
+int cac_SamEnableUser(CacServerHandle *hnd, TALLOC_CTX *mem_ctx, POLICY_HND *user_hnd);
+
 void cac_GetAuthDataFn(const char * pServer,
                  const char * pShare,
                  char * pWorkgroup,

Modified: branches/SOC/SAMBA_3_0/source/libmsrpc/cac_samr.c
===================================================================
--- branches/SOC/SAMBA_3_0/source/libmsrpc/cac_samr.c	2005-08-20 22:47:53 UTC (rev 9435)
+++ branches/SOC/SAMBA_3_0/source/libmsrpc/cac_samr.c	2005-08-20 22:50:13 UTC (rev 9436)
@@ -1451,3 +1451,103 @@
 
 }
 
+int cac_SamUserChangePasswd(CacServerHandle *hnd, TALLOC_CTX *mem_ctx, struct SamUserChangePasswd *op) {
+   SMBCSRV *srv = NULL;
+
+   if(!hnd) 
+      return CAC_FAILURE;
+
+   if(!hnd->_internal.ctx) {
+      hnd->status = NT_STATUS_INVALID_HANDLE;
+      return CAC_FAILURE;
+   }
+
+   if(!op || !op->in.username || !op->in.password || !op->in.new_password || !mem_ctx) {
+      hnd->status = NT_STATUS_INVALID_PARAMETER;
+      return CAC_FAILURE;
+   }
+
+   srv = cac_GetServer(hnd);
+   if(!srv) {
+      hnd->status = NT_STATUS_UNSUCCESSFUL;
+      return CAC_FAILURE;
+   }
+
+   /*open a session on SAMR if we don't have one*/
+   if(!hnd->_internal.pipes[PI_SAMR]) {
+      if(!cli_nt_session_open(&srv->cli, PI_SAMR)) {
+         hnd->status = NT_STATUS_UNSUCCESSFUL;
+         return CAC_FAILURE;
+      }
+
+      hnd->_internal.pipes[PI_SAMR] = True;
+   }
+
+   srv->cli.pipe_idx = PI_SAMR;
+
+   hnd->status = cli_samr_chgpasswd_user(&(srv->cli), mem_ctx, op->in.username, op->in.new_password, op->in.password);
+
+   if(!NT_STATUS_IS_OK(hnd->status))
+      return CAC_FAILURE;
+
+   return CAC_SUCCESS;
+}
+
+int cac_SamEnableUser(CacServerHandle *hnd, TALLOC_CTX *mem_ctx, POLICY_HND *user_hnd) {
+   SMBCSRV *srv = NULL;
+
+   SAM_USERINFO_CTR *get_ctr;
+   SAM_USERINFO_CTR set_ctr;
+   SAM_USER_INFO_10 info10;
+   uint32 acb_mask = 0;
+
+   if(!hnd) 
+      return CAC_FAILURE;
+
+   if(!hnd->_internal.ctx || !hnd->_internal.pipes[PI_SAMR]) {
+      hnd->status = NT_STATUS_INVALID_HANDLE;
+      return CAC_FAILURE;
+   }
+
+   if(!user_hnd || !mem_ctx) {
+      hnd->status = NT_STATUS_INVALID_PARAMETER;
+      return CAC_FAILURE;
+   }
+
+   srv = cac_GetServer(hnd);
+   if(!srv) {
+      hnd->status = NT_STATUS_UNSUCCESSFUL;
+      return CAC_FAILURE;
+   }
+
+   srv->cli.pipe_idx = PI_SAMR;
+
+   /*info_level = 21 is the only level that I have found to work reliably. It would be nice if user_level = 10 worked.*/
+   hnd->status = cli_samr_query_userinfo( &(srv->cli), mem_ctx, user_hnd, 21, &get_ctr);
+
+   if(!NT_STATUS_IS_OK(hnd->status))
+      return CAC_FAILURE;
+
+   /**check the ACB mask*/
+   if((get_ctr->info.id21->acb_info & ACB_DISABLED) == ACB_DISABLED) {
+      /*toggle the disabled bit*/
+      acb_mask = (get_ctr->info.id21->acb_info ^ ACB_DISABLED);
+   }
+   else {
+      /*the user is already enabled so just return success*/
+      return CAC_SUCCESS;
+   }
+
+   init_sam_user_info10(&info10, acb_mask);
+
+   set_ctr.switch_value = 10;
+   set_ctr.info.id10 = &info10;
+
+   /*now set the userinfo*/
+   hnd->status = cli_samr_set_userinfo( &(srv->cli), mem_ctx, user_hnd, 10, &(srv->cli.user_session_key), &set_ctr);
+
+   if(!NT_STATUS_IS_OK(hnd->status))
+      return CAC_FAILURE;
+
+   return CAC_SUCCESS;
+}

Modified: branches/SOC/SAMBA_3_0/source/libmsrpc/test/Makefile
===================================================================
--- branches/SOC/SAMBA_3_0/source/libmsrpc/test/Makefile	2005-08-20 22:47:53 UTC (rev 9435)
+++ branches/SOC/SAMBA_3_0/source/libmsrpc/test/Makefile	2005-08-20 22:50:13 UTC (rev 9436)
@@ -82,5 +82,8 @@
 samalias: sam/samalias.o test_util.o
 	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< test_util.o $(LIBS)
 
+enable: sam/enable.o test_util.o
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< test_util.o $(LIBS)
+
 clean:
 	rm -f $(TESTS) *.o lsa/*.o reg/*.o sam/*.o

Added: branches/SOC/SAMBA_3_0/source/libmsrpc/test/sam/enable.c
===================================================================
--- branches/SOC/SAMBA_3_0/source/libmsrpc/test/sam/enable.c	2005-08-20 22:47:53 UTC (rev 9435)
+++ branches/SOC/SAMBA_3_0/source/libmsrpc/test/sam/enable.c	2005-08-20 22:50:13 UTC (rev 9436)
@@ -0,0 +1,63 @@
+
+#include "libmsrpc.h"
+#include "test_util.h"
+
+int main(int argc, char **argv) {
+   CacServerHandle *hnd = NULL;
+   TALLOC_CTX *mem_ctx = NULL;
+
+   struct SamOpenUser ou;
+
+   fstring tmp;
+
+   mem_ctx = talloc_init("cac_samgroup");
+
+   hnd = cac_NewServerHandle();
+
+   cac_SetAuthDataFn(hnd, cactest_GetAuthDataFn);
+
+   cac_parse_cmd_line(argc, argv, hnd);
+
+   if(!cac_Connect(hnd, NULL)) {
+      fprintf(stderr, "Could not connect to server %s. Error: %s\n", hnd->server, nt_errstr(hnd->status));
+      exit(-1);
+   }
+
+   struct SamOpenDomain sod;
+   ZERO_STRUCT(sod);
+
+   sod.in.access = MAXIMUM_ALLOWED_ACCESS; 
+
+   if(!cac_SamOpenDomain(hnd, mem_ctx, &sod)) {
+      fprintf(stderr, "Could not open domain. Error: %s\n", nt_errstr(hnd->status));
+      goto done;
+   }
+
+   ZERO_STRUCT(ou);
+   printf("Enter username: ");
+   cactest_readline(stdin, tmp);
+
+   ou.in.username = talloc_strdup(mem_ctx, tmp);
+   ou.in.access = MAXIMUM_ALLOWED_ACCESS;
+   ou.in.sam = sod.out.pol;
+
+   if(!cac_SamOpenUser(hnd, mem_ctx, &ou)) {
+      fprintf(stderr, "Could not open user. Error: %s\n", nt_errstr(hnd->status));
+      goto done;
+   }
+
+   /*enable the user*/
+   if(!cac_SamEnableUser(hnd, mem_ctx, ou.out.user)) {
+      fprintf(stderr, "Could not enable user: %s\n", nt_errstr(hnd->status));
+   }
+
+done:
+   cac_SamClose(hnd, mem_ctx, sod.out.pol);
+
+   cac_FreeHandle(hnd);
+
+   talloc_destroy(mem_ctx);
+   
+   return 0;
+}
+



More information about the samba-cvs mailing list