diff options
author | Luke Leighton <lkcl@samba.org> | 2000-03-15 23:28:14 +0000 |
---|---|---|
committer | Luke Leighton <lkcl@samba.org> | 2000-03-15 23:28:14 +0000 |
commit | bc8d4f6b6044a2179d5293a8fdfad6010fa82e94 (patch) | |
tree | 89fae25a1347a86918524522de719f9b7329877f | |
parent | 5bc05dd07c20c6b1f6d537c478d6b33bfae71ce7 (diff) | |
download | samba-bc8d4f6b6044a2179d5293a8fdfad6010fa82e94.tar.gz samba-bc8d4f6b6044a2179d5293a8fdfad6010fa82e94.tar.xz samba-bc8d4f6b6044a2179d5293a8fdfad6010fa82e94.zip |
gratuitous indent on files modified in the last two days.
-rw-r--r-- | source/include/rpc_misc.h | 221 | ||||
-rw-r--r-- | source/lib/unix_sec_ctxt.c | 304 | ||||
-rw-r--r-- | source/lib/util_sock.c | 1240 | ||||
-rw-r--r-- | source/lsarpcd/srv_lsa.c | 165 | ||||
-rw-r--r-- | source/lsarpcd/srv_lsa_samdb.c | 229 | ||||
-rw-r--r-- | source/msrpc/msrpcd_process.c | 14 | ||||
-rw-r--r-- | source/netlogond/srv_netlogon_nt.c | 15 | ||||
-rw-r--r-- | source/rpc_client/msrpc_lsarpc.c | 15 | ||||
-rw-r--r-- | source/rpc_parse/parse_samr.c | 93 | ||||
-rw-r--r-- | source/rpcclient/cmd_netlogon.c | 39 | ||||
-rw-r--r-- | source/rpcclient/cmd_samr.c | 1210 | ||||
-rw-r--r-- | source/samrd/srv_samr_passdb.c | 807 | ||||
-rw-r--r-- | source/winregd/srv_reg_nt.c | 13 |
13 files changed, 2165 insertions, 2200 deletions
diff --git a/source/include/rpc_misc.h b/source/include/rpc_misc.h index 93ce1ed4f63..799b00cee09 100644 --- a/source/include/rpc_misc.h +++ b/source/include/rpc_misc.h @@ -21,8 +21,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifndef _RPC_MISC_H /* _RPC_MISC_H */ -#define _RPC_MISC_H +#ifndef _RPC_MISC_H /* _RPC_MISC_H */ +#define _RPC_MISC_H /* * macros to wrap prs_xxxx routines. @@ -174,67 +174,75 @@ typedef struct bigint_info uint32 low; uint32 high; -} BIGINT; +} +BIGINT; /* ENUM_HND */ typedef struct enum_hnd_info { - uint32 ptr_hnd; /* pointer to enumeration handle */ - uint32 handle; /* enumeration handle */ + uint32 ptr_hnd; /* pointer to enumeration handle */ + uint32 handle; /* enumeration handle */ -} ENUM_HND; +} +ENUM_HND; /* LOOKUP_LEVEL - switch value */ typedef struct lookup_level_info { - uint16 value; + uint16 value; -} LOOKUP_LEVEL; +} +LOOKUP_LEVEL; /* DOM_SID2 - security id */ typedef struct sid_info_2 { - uint32 num_auths; /* length, bytes, including length of len :-) */ + uint32 num_auths; /* length, bytes, including length of len :-) */ DOM_SID sid; -} DOM_SID2; +} +DOM_SID2; /* STRHDR - string header */ typedef struct header_info { - uint16 str_str_len; - uint16 str_max_len; - uint32 buffer; /* non-zero */ + uint16 str_str_len; + uint16 str_max_len; + uint32 buffer; /* non-zero */ -} STRHDR; +} +STRHDR; /* STRHDR2 - string header, 32-bit lengths */ typedef struct header2_info { - uint32 str_str_len; - uint32 str_max_len; - uint32 buffer; + uint32 str_str_len; + uint32 str_max_len; + uint32 buffer; -} STRHDR2; +} +STRHDR2; /* UNIHDR - unicode string header */ typedef struct unihdr_info { - uint16 uni_str_len; - uint16 uni_max_len; - uint32 buffer; /* usually has a value of 4 */ + uint16 uni_str_len; + uint16 uni_max_len; + uint32 buffer; /* usually has a value of 4 */ -} UNIHDR; +} +UNIHDR; /* UNIHDR2 - unicode string header and undocumented buffer */ typedef struct unihdr2_info { - UNIHDR unihdr; - uint32 buffer; /* 32 bit buffer pointer */ + UNIHDR unihdr; + uint32 buffer; /* 32 bit buffer pointer */ -} UNIHDR2; +} +UNIHDR2; /* clueless as to what maximum length should be */ #define MAX_UNISTRLEN 256 @@ -244,82 +252,91 @@ typedef struct unihdr2_info /* UNISTR - unicode string size and buffer */ typedef struct unistr_info { - uint16 buffer[MAX_UNISTRLEN]; /* unicode characters. ***MUST*** be null-terminated */ + uint16 buffer[MAX_UNISTRLEN]; /* unicode characters. ***MUST*** be null-terminated */ -} UNISTR; +} +UNISTR; /* BUFHDR - buffer header */ typedef struct bufhdr_info { - uint32 buf_max_len; - uint32 buf_len; + uint32 buf_max_len; + uint32 buf_len; -} BUFHDR; +} +BUFHDR; /* BUFHDR2 - another buffer header, with info level */ typedef struct bufhdr2_info { - uint32 info_level; - uint32 length; /* uint8 chars */ - uint32 buffer; + uint32 info_level; + uint32 length; /* uint8 chars */ + uint32 buffer; -} BUFHDR2; +} +BUFHDR2; /* BUFFER2 - unicode string, size (in uint8 ascii chars) and buffer */ /* pathetic. some stupid team of \PIPE\winreg writers got the concept */ /* of a unicode string different from the other \PIPE\ writers */ typedef struct buffer2_info { - uint32 buf_max_len; - uint32 undoc; - uint32 buf_len; - uint8 buffer[MAX_UNISTRLEN]; + uint32 buf_max_len; + uint32 undoc; + uint32 buf_len; + uint8 buffer[MAX_UNISTRLEN]; -} BUFFER2; +} +BUFFER2; /* BUFFER3 */ typedef struct buffer3_info { - uint32 buf_max_len; - uint8 buffer[MAX_BUFFERLEN]; /* data */ - uint32 buf_len; + uint32 buf_max_len; + uint8 buffer[MAX_BUFFERLEN]; /* data */ + uint32 buf_len; -} BUFFER3; +} +BUFFER3; /* BUFFER4 - simple length and buffer */ typedef struct buffer4_info { - uint32 buf_len; - uint8 buffer[MAX_BUFFERLEN]; + uint32 buf_len; + uint8 buffer[MAX_BUFFERLEN]; -} BUFFER4; +} +BUFFER4; /* BUFFER5 */ typedef struct buffer5_info { - uint32 buf_len; - uint16 *buffer; /* data */ -} BUFFER5; + uint32 buf_len; + uint16 *buffer; /* data */ +} +BUFFER5; /* UNISTR2 - unicode string size (in uint16 unicode chars) and buffer */ typedef struct unistr2_info { - uint32 uni_max_len; - uint32 undoc; - uint32 uni_str_len; - uint16 buffer[MAX_UNISTRLEN]; /* unicode characters. **NOT** necessarily null-terminated */ + uint32 uni_max_len; + uint32 undoc; + uint32 uni_str_len; + uint16 buffer[MAX_UNISTRLEN]; /* unicode characters. **NOT** necessarily null-terminated */ -} UNISTR2; +} +UNISTR2; /* STRING2 - string size (in uint8 chars) and buffer */ typedef struct string2_info { - uint32 str_max_len; - uint32 undoc; - uint32 str_str_len; - uint8 buffer[MAX_STRINGLEN]; /* uint8 characters. **NOT** necessarily null-terminated */ + uint32 str_max_len; + uint32 undoc; + uint32 str_str_len; + uint8 buffer[MAX_STRINGLEN]; /* uint8 characters. **NOT** necessarily null-terminated */ -} STRING2; +} +STRING2; /* UNISTR3 - XXXX not sure about this structure */ typedef struct unistr3_info @@ -327,90 +344,100 @@ typedef struct unistr3_info uint32 uni_str_len; UNISTR str; -} UNISTR3; +} +UNISTR3; /* DOM_RID2 - domain RID structure for ntlsa pipe */ typedef struct domrid2_info { - uint16 type; /* value is SID_NAME_USE enum */ + uint16 type; /* value is SID_NAME_USE enum */ uint32 rid; - uint32 rid_idx; /* referenced domain index */ + uint32 rid_idx; /* referenced domain index */ -} DOM_RID2; +} +DOM_RID2; /* DOM_RID3 - domain RID structure for samr pipe */ typedef struct domrid3_info { - uint32 rid; /* domain-relative (to a SID) id */ - uint32 type1; /* value is 0x1 */ - uint32 ptr_type; /* undocumented pointer */ - uint32 type2; /* value is 0x1 */ - uint32 unk; /* value is 0x2 */ + uint32 rid; /* domain-relative (to a SID) id */ + uint32 type1; /* value is 0x1 */ + uint32 ptr_type; /* undocumented pointer */ + uint32 type2; /* value is 0x1 */ + uint32 unk; /* value is 0x2 */ -} DOM_RID3; +} +DOM_RID3; /* DOM_CLNT_SRV - client / server names */ typedef struct clnt_srv_info { - uint32 undoc_buffer; /* undocumented 32 bit buffer pointer */ - UNISTR2 uni_logon_srv; /* logon server name */ - uint32 undoc_buffer2; /* undocumented 32 bit buffer pointer */ - UNISTR2 uni_comp_name; /* client machine name */ + uint32 undoc_buffer; /* undocumented 32 bit buffer pointer */ + UNISTR2 uni_logon_srv; /* logon server name */ + uint32 undoc_buffer2; /* undocumented 32 bit buffer pointer */ + UNISTR2 uni_comp_name; /* client machine name */ -} DOM_CLNT_SRV; +} +DOM_CLNT_SRV; /* DOM_LOG_INFO - login info */ typedef struct log_info { - uint32 undoc_buffer; /* undocumented 32 bit buffer pointer */ - UNISTR2 uni_logon_srv; /* logon server name */ - UNISTR2 uni_acct_name; /* account name */ - uint16 sec_chan; /* secure channel type */ - UNISTR2 uni_comp_name; /* client machine name */ + uint32 undoc_buffer; /* undocumented 32 bit buffer pointer */ + UNISTR2 uni_logon_srv; /* logon server name */ + UNISTR2 uni_acct_name; /* account name */ + uint16 sec_chan; /* secure channel type */ + UNISTR2 uni_comp_name; /* client machine name */ -} DOM_LOG_INFO; +} +DOM_LOG_INFO; /* DOM_CLNT_INFO - client info */ typedef struct clnt_info { - DOM_LOG_INFO login; - DOM_CRED cred; + DOM_LOG_INFO login; + DOM_CRED cred; -} DOM_CLNT_INFO; +} +DOM_CLNT_INFO; /* DOM_CLNT_INFO2 - client info */ typedef struct clnt_info2 { - DOM_CLNT_SRV login; - uint32 ptr_cred; - DOM_CRED cred; + DOM_CLNT_SRV login; + uint32 ptr_cred; + DOM_CRED cred; -} DOM_CLNT_INFO2; +} +DOM_CLNT_INFO2; /* DOM_LOGON_ID - logon id */ typedef struct logon_info { - uint32 low; - uint32 high; + uint32 low; + uint32 high; -} DOM_LOGON_ID; +} +DOM_LOGON_ID; /* OWF INFO */ typedef struct owf_info { - uint8 data[16]; + uint8 data[16]; -} OWF_INFO; +} +OWF_INFO; /* DOM_GID - group id + user attributes */ typedef struct gid_info { - uint32 g_rid; /* a group RID */ - uint32 attr; + uint32 g_rid; /* a group RID */ + uint32 attr; -} DOM_GID; +} +DOM_GID; /* POLICY_HND */ typedef struct lsa_policy_info @@ -418,7 +445,7 @@ typedef struct lsa_policy_info uint32 ptr; RPC_UUID uuid; -} POLICY_HND; +} +POLICY_HND; #endif /* _RPC_MISC_H */ - diff --git a/source/lib/unix_sec_ctxt.c b/source/lib/unix_sec_ctxt.c index ead1f3c6d32..7111d255114 100644 --- a/source/lib/unix_sec_ctxt.c +++ b/source/lib/unix_sec_ctxt.c @@ -1,303 +1 @@ -/* - Unix SMB/Netbios implementation. - Version 1.9. - uid/user handling - Copyright (C) Andrew Tridgell 1992-1998 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include "includes.h" - -extern int DEBUGLEVEL; - -static uid_t initial_uid; -static gid_t initial_gid; - -/* what context is current */ -struct unix_sec_ctxt curr_ctxt; - -/**************************************************************************** -initialise the security context routines -****************************************************************************/ -void init_sec_ctxt(void) -{ - initial_uid = curr_ctxt.uid = geteuid(); - initial_gid = curr_ctxt.gid = getegid(); - - if (initial_gid != 0 && initial_uid == 0) { -#ifdef HAVE_SETRESUID - setresgid(0,0,0); -#else - setgid(0); - setegid(0); -#endif - } - - initial_uid = geteuid(); - initial_gid = getegid(); -} - - -/**************************************************************************** - become the specified uid -****************************************************************************/ -static BOOL become_uid(uid_t uid) -{ - if (initial_uid != 0) - { - return(True); - } - - if (uid == (uid_t)-1 || ((sizeof(uid_t) == 2) && (uid == (uid_t)65535))) - { - static int done; - if (!done) { - DEBUG(1,("WARNING: using uid %d is a security risk\n",(int)uid)); - done=1; - } - } - -#ifdef HAVE_TRAPDOOR_UID -#ifdef HAVE_SETUIDX - /* AIX3 has setuidx which is NOT a trapoor function (tridge) */ - if (setuidx(ID_EFFECTIVE, uid) != 0) { - if (seteuid(uid) != 0) { - DEBUG(1,("Can't set uid %d (setuidx)\n", (int)uid)); - return False; - } - } -#endif -#endif - -#ifdef HAVE_SETRESUID - if (setresuid(-1,uid,-1) != 0) -#else - if ((seteuid(uid) != 0) && - (setuid(uid) != 0)) -#endif - { - DEBUG(0,("Couldn't set uid %d currently set to (%d,%d)\n", - (int)uid,(int)getuid(), (int)geteuid())); - if (uid > (uid_t)32000) { - DEBUG(0,("Looks like your OS doesn't like high uid values - try using a different account\n")); - } - return(False); - } - - if (((uid == (uid_t)-1) || ((sizeof(uid_t) == 2) && (uid == 65535))) && (geteuid() != uid)) - { - DEBUG(0,("Invalid uid -1. perhaps you have a account with uid 65535?\n")); - return(False); - } - - curr_ctxt.uid = uid; - - return(True); -} - - -/**************************************************************************** - become the specified gid -****************************************************************************/ -static BOOL become_gid(gid_t gid) -{ - if (initial_uid != 0) - return(True); - - if (gid == (gid_t)-1 || ((sizeof(gid_t) == 2) && (gid == (gid_t)65535))) { - DEBUG(1,("WARNING: using gid %d is a security risk\n",(int)gid)); - } - -#ifdef HAVE_SETRESUID - if (setresgid(-1,gid,-1) != 0) -#else - if (setgid(gid) != 0) -#endif - { - DEBUG(0,("Couldn't set gid %d currently set to (%d,%d)\n", - (int)gid,(int)getgid(),(int)getegid())); - if (gid > 32000) { - DEBUG(0,("Looks like your OS doesn't like high gid values - try using a different account\n")); - } - return(False); - } - - curr_ctxt.gid = gid; - - return(True); -} - - -/**************************************************************************** - become the user of a connection number -****************************************************************************/ -BOOL become_unix_sec_ctxt(struct unix_sec_ctxt const *ctxt) -{ - if (curr_ctxt.uid == ctxt->uid) - { - DEBUG(4,("Skipping become_unix_sec_ctxt - already user\n")); - return(True); - } - - unbecome_unix_sec_ctxt(); - - curr_ctxt.ngroups = ctxt->ngroups; - curr_ctxt.groups = ctxt->groups; - curr_ctxt.name = ctxt->name; - - if (initial_uid == 0) - { - if (!become_uid(ctxt->uid)) return(False); -#ifdef HAVE_SETGROUPS - if (curr_ctxt.ngroups > 0) - { - if (setgroups(curr_ctxt.ngroups, - curr_ctxt.groups) < 0) - { - DEBUG(0,("setgroups call failed!\n")); - } - } -#endif - if (!become_gid(ctxt->gid)) return(False); - - } - - DEBUG(5,("become_unix_sec_ctxt uid=(%d,%d) gid=(%d,%d)\n", - (int)getuid(),(int)geteuid(),(int)getgid(),(int)getegid())); - - return(True); -} - -/**************************************************************************** - unbecome the user of a connection number -****************************************************************************/ -BOOL unbecome_unix_sec_ctxt(void) -{ - if (initial_uid == 0) - { -#ifdef HAVE_SETRESUID - setresuid(-1,getuid(),-1); - setresgid(-1,getgid(),-1); -#else - if (seteuid(initial_uid) != 0) - setuid(initial_uid); - setgid(initial_gid); -#endif - } - -#ifdef NO_EID - if (initial_uid == 0) - DEBUG(2,("Running with no EID\n")); - initial_uid = getuid(); - initial_gid = getgid(); -#else - if (geteuid() != initial_uid) { - DEBUG(0,("Warning: You appear to have a trapdoor uid system\n")); - initial_uid = geteuid(); - } - if (getegid() != initial_gid) { - DEBUG(0,("Warning: You appear to have a trapdoor gid system\n")); - initial_gid = getegid(); - } -#endif - - curr_ctxt.uid = initial_uid; - curr_ctxt.gid = initial_gid; - curr_ctxt.name = NULL; - - curr_ctxt.ngroups = 0; - curr_ctxt.groups = NULL; - - DEBUG(5,("unbecome_unix_sec_ctxt now uid=(%d,%d) gid=(%d,%d)\n", - (int)getuid(),(int)geteuid(),(int)getgid(),(int)getegid())); - - return(True); -} - -static struct unix_sec_ctxt curr_ctxt_saved; -static int become_root_depth; - -/**************************************************************************** -This is used when we need to do a privileged operation (such as mucking -with share mode files) and temporarily need root access to do it. This -call should always be paired with an unbecome_root() call immediately -after the operation - -Set save_dir if you also need to save/restore the CWD -****************************************************************************/ -void become_unix_root_sec_ctxt(void) -{ - if (become_root_depth) { - DEBUG(0,("ERROR: become root depth is non zero\n")); - } - - curr_ctxt_saved = curr_ctxt; - become_root_depth = 1; - - become_uid(0); - become_gid(0); -} - -/**************************************************************************** -When the privileged operation is over call this - -Set save_dir if you also need to save/restore the CWD -****************************************************************************/ -void unbecome_unix_root_sec_ctxt(void) -{ - if (become_root_depth != 1) - { - DEBUG(0,("ERROR: unbecome root depth is %d\n", - become_root_depth)); - } - - /* we might have done a become_user() while running as root, - if we have then become root again in order to become - non root! */ - if (curr_ctxt.uid != 0) - { - become_uid(0); - } - - /* restore our gid first */ - if (!become_gid(curr_ctxt_saved.gid)) - { - DEBUG(0,("ERROR: Failed to restore gid\n")); - exit(-1); - } - -#ifdef HAVE_SETGROUPS - if (curr_ctxt_saved.ngroups > 0) - { - if (setgroups(curr_ctxt_saved.ngroups, - curr_ctxt_saved.groups) < 0) - { - DEBUG(0,("setgroups call failed!\n")); - } - } -#endif - /* now restore our uid */ - if (!become_uid(curr_ctxt_saved.uid)) - { - DEBUG(0,("ERROR: Failed to restore uid\n")); - exit(-1); - } - - curr_ctxt = curr_ctxt_saved; - - become_root_depth = 0; -} - +/* retired */ diff --git a/source/lib/util_sock.c b/source/lib/util_sock.c index 681efa0277d..7776c434ecd 100644 --- a/source/lib/util_sock.c +++ b/source/lib/util_sock.c @@ -23,10 +23,10 @@ #ifdef WITH_SSL #include <ssl.h> -#undef Realloc /* SSLeay defines this and samba has a function of this name */ -extern SSL *ssl; -extern int sslFd; -#endif /* WITH_SSL */ +#undef Realloc /* SSLeay defines this and samba has a function of this name */ +extern SSL *ssl; +extern int sslFd; +#endif /* WITH_SSL */ extern int DEBUGLEVEL; @@ -42,7 +42,7 @@ int ClientPort = 0; struct in_addr lastip; /* the last port received from */ -int lastport=0; +int lastport = 0; int smb_read_error = 0; @@ -53,110 +53,149 @@ determine if a file descriptor is in fact a socket ****************************************************************************/ BOOL is_a_socket(int fd) { - int v,l; - l = sizeof(int); - return(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&v, &l) == 0); + int v, l; + l = sizeof(int); + return (getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&v, &l) == 0); } -enum SOCK_OPT_TYPES {OPT_BOOL,OPT_INT,OPT_ON}; +enum SOCK_OPT_TYPES +{ OPT_BOOL, OPT_INT, OPT_ON }; struct { - char *name; - int level; - int option; - int value; - int opttype; -} socket_options[] = { - {"SO_KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE, 0, OPT_BOOL}, - {"SO_REUSEADDR", SOL_SOCKET, SO_REUSEADDR, 0, OPT_BOOL}, - {"SO_BROADCAST", SOL_SOCKET, SO_BROADCAST, 0, OPT_BOOL}, + char *name; + int level; + int option; + int value; + int opttype; +} +socket_options[] = +{ + { + "SO_KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE, 0, OPT_BOOL} + , + { + "SO_REUSEADDR", SOL_SOCKET, SO_REUSEADDR, 0, OPT_BOOL} + , + { + "SO_BROADCAST", SOL_SOCKET, SO_BROADCAST, 0, OPT_BOOL} + , #ifdef TCP_NODELAY - {"TCP_NODELAY", IPPROTO_TCP, TCP_NODELAY, 0, OPT_BOOL}, + { + "TCP_NODELAY", IPPROTO_TCP, TCP_NODELAY, 0, OPT_BOOL} + , #endif #ifdef IPTOS_LOWDELAY - {"IPTOS_LOWDELAY", IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY, OPT_ON}, + { + "IPTOS_LOWDELAY", IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY, OPT_ON} + , #endif #ifdef IPTOS_THROUGHPUT - {"IPTOS_THROUGHPUT", IPPROTO_IP, IP_TOS, IPTOS_THROUGHPUT, OPT_ON}, + { + "IPTOS_THROUGHPUT", IPPROTO_IP, IP_TOS, IPTOS_THROUGHPUT, + OPT_ON} + , #endif #ifdef SO_SNDBUF - {"SO_SNDBUF", SOL_SOCKET, SO_SNDBUF, 0, OPT_INT}, + { + "SO_SNDBUF", SOL_SOCKET, SO_SNDBUF, 0, OPT_INT} + , #endif #ifdef SO_RCVBUF - {"SO_RCVBUF", SOL_SOCKET, SO_RCVBUF, 0, OPT_INT}, + { + "SO_RCVBUF", SOL_SOCKET, SO_RCVBUF, 0, OPT_INT} + , #endif #ifdef SO_SNDLOWAT - {"SO_SNDLOWAT", SOL_SOCKET, SO_SNDLOWAT, 0, OPT_INT}, + { + "SO_SNDLOWAT", SOL_SOCKET, SO_SNDLOWAT, 0, OPT_INT} + , #endif #ifdef SO_RCVLOWAT - {"SO_RCVLOWAT", SOL_SOCKET, SO_RCVLOWAT, 0, OPT_INT}, + { + "SO_RCVLOWAT", SOL_SOCKET, SO_RCVLOWAT, 0, OPT_INT} + , #endif #ifdef SO_SNDTIMEO - {"SO_SNDTIMEO", SOL_SOCKET, SO_SNDTIMEO, 0, OPT_INT}, + { + "SO_SNDTIMEO", SOL_SOCKET, SO_SNDTIMEO, 0, OPT_INT} + , #endif #ifdef SO_RCVTIMEO - {"SO_RCVTIMEO", SOL_SOCKET, SO_RCVTIMEO, 0, OPT_INT}, + { + "SO_RCVTIMEO", SOL_SOCKET, SO_RCVTIMEO, 0, OPT_INT} + , #endif - {NULL,0,0,0,0}}; + { + NULL, 0, 0, 0, 0} +}; + - /**************************************************************************** set user socket options ****************************************************************************/ void set_socket_options(int fd, char *options) { - fstring tok; - - while (next_token(&options,tok," \t,", sizeof(tok))) - { - int ret=0,i; - int value = 1; - char *p; - BOOL got_value = False; + fstring tok; - if ((p = strchr(tok,'='))) + while (next_token(&options, tok, " \t,", sizeof(tok))) { - *p = 0; - value = atoi(p+1); - got_value = True; - } - - for (i=0;socket_options[i].name;i++) - if (strequal(socket_options[i].name,tok)) - break; + int ret = 0, i; + int value = 1; + char *p; + BOOL got_value = False; + + if ((p = strchr(tok, '='))) + { + *p = 0; + value = atoi(p + 1); + got_value = True; + } - if (!socket_options[i].name) - { - DEBUG(0,("Unknown socket option %s\n",tok)); - continue; - } + for (i = 0; socket_options[i].name; i++) + if (strequal(socket_options[i].name, tok)) + break; - switch (socket_options[i].opttype) - { - case OPT_BOOL: - case OPT_INT: - ret = setsockopt(fd,socket_options[i].level, - socket_options[i].option,(char *)&value,sizeof(int)); - break; + if (!socket_options[i].name) + { + DEBUG(0, ("Unknown socket option %s\n", tok)); + continue; + } - case OPT_ON: - if (got_value) - DEBUG(0,("syntax error - %s does not take a value\n",tok)); + switch (socket_options[i].opttype) + { + case OPT_BOOL: + case OPT_INT: + ret = setsockopt(fd, socket_options[i].level, + socket_options[i].option, + (char *)&value, sizeof(int)); + break; + + case OPT_ON: + if (got_value) + DEBUG(0, + ("syntax error - %s does not take a value\n", + tok)); + + { + int on = socket_options[i].value; + ret = + setsockopt(fd, + socket_options[i]. + level, + socket_options[i]. + option, + (char *)&on, + sizeof(int)); + } + break; + } - { - int on = socket_options[i].value; - ret = setsockopt(fd,socket_options[i].level, - socket_options[i].option,(char *)&on,sizeof(int)); - } - break; + if (ret != 0) + DEBUG(0, ("Failed to set socket option %s\n", tok)); } - - if (ret != 0) - DEBUG(0,("Failed to set socket option %s\n",tok)); - } } @@ -164,14 +203,14 @@ void set_socket_options(int fd, char *options) /**************************************************************************** close the socket communication ****************************************************************************/ -void close_sockets(void ) +void close_sockets(void) { #ifdef WITH_SSL - sslutil_disconnect(Client); + sslutil_disconnect(Client); #endif /* WITH_SSL */ - close(Client); - Client = -1; + close(Client); + Client = -1; } @@ -179,48 +218,52 @@ void close_sockets(void ) /**************************************************************************** write to a socket ****************************************************************************/ -ssize_t write_socket(int fd,char *buf,size_t len) +ssize_t write_socket(int fd, char *buf, size_t len) { - ssize_t ret=0; - - if (passive) - return(len); - DEBUG(6,("write_socket(%d,%d)\n",fd,len)); - ret = write_data(fd,buf,len); - - DEBUG(6,("write_socket(%d,%d) wrote %d\n",fd,len,ret)); - if(ret <= 0) - DEBUG(0,("write_socket: Error writing %d bytes to socket %d: ERRNO = %s\n", - len, fd, strerror(errno) )); - - return(ret); + ssize_t ret = 0; + + if (passive) + return (len); + DEBUG(6, ("write_socket(%d,%d)\n", fd, len)); + ret = write_data(fd, buf, len); + + DEBUG(6, ("write_socket(%d,%d) wrote %d\n", fd, len, ret)); + if (ret <= 0) + DEBUG(0, + ("write_socket: Error writing %d bytes to socket %d: ERRNO = %s\n", + len, fd, strerror(errno))); + + return (ret); } /**************************************************************************** read from a socket ****************************************************************************/ -ssize_t read_udp_socket(int fd,char *buf,size_t len) +ssize_t read_udp_socket(int fd, char *buf, size_t len) { - ssize_t ret; - struct sockaddr_in sock; - int socklen; - - socklen = sizeof(sock); - bzero((char *)&sock,socklen); - bzero((char *)&lastip,sizeof(lastip)); - ret = (ssize_t)recvfrom(fd,buf,len,0,(struct sockaddr *)&sock,&socklen); - if (ret <= 0) { - DEBUG(2,("read socket failed. ERRNO=%s\n",strerror(errno))); - return(0); - } - - lastip = sock.sin_addr; - lastport = ntohs(sock.sin_port); - - DEBUG(10,("read_udp_socket: lastip %s lastport %d read: %d\n", - inet_ntoa(lastip), lastport, ret)); - - return(ret); + ssize_t ret; + struct sockaddr_in sock; + int socklen; + + socklen = sizeof(sock); + bzero((char *)&sock, socklen); + bzero((char *)&lastip, sizeof(lastip)); + ret = + (ssize_t) recvfrom(fd, buf, len, 0, (struct sockaddr *)&sock, + &socklen); + if (ret <= 0) + { + DEBUG(2, ("read socket failed. ERRNO=%s\n", strerror(errno))); + return (0); + } + + lastip = sock.sin_addr; + lastport = ntohs(sock.sin_port); + + DEBUG(10, ("read_udp_socket: lastip %s lastport %d read: %d\n", + inet_ntoa(lastip), lastport, ret)); + + return (ret); } /**************************************************************************** @@ -230,105 +273,125 @@ maxcount = number to be read. time_out = timeout in milliseconds ****************************************************************************/ -ssize_t read_with_timeout(int fd,char *buf,size_t mincnt,size_t maxcnt,unsigned int time_out) +ssize_t read_with_timeout(int fd, char *buf, size_t mincnt, size_t maxcnt, + unsigned int time_out) { - fd_set fds; - int selrtn; - ssize_t readret; - size_t nread = 0; - struct timeval timeout; + fd_set fds; + int selrtn; + ssize_t readret; + size_t nread = 0; + struct timeval timeout; - /* just checking .... */ - if (maxcnt <= 0) return(0); + /* just checking .... */ + if (maxcnt <= 0) + return (0); - smb_read_error = 0; + smb_read_error = 0; - /* Blocking read */ - if (time_out <= 0) { - if (mincnt == 0) mincnt = maxcnt; + /* Blocking read */ + if (time_out <= 0) + { + if (mincnt == 0) + mincnt = maxcnt; - while (nread < mincnt) { + while (nread < mincnt) + { #ifdef WITH_SSL - if(fd == sslFd){ - readret = SSL_read(ssl, buf + nread, maxcnt - nread); - }else{ - readret = read(fd, buf + nread, maxcnt - nread); - } + if (fd == sslFd) + { + readret = + SSL_read(ssl, buf + nread, + maxcnt - nread); + } + else + { + readret = + read(fd, buf + nread, maxcnt - nread); + } #else /* WITH_SSL */ - readret = read(fd, buf + nread, maxcnt - nread); + readret = read(fd, buf + nread, maxcnt - nread); #endif /* WITH_SSL */ - if (readret == 0) { - smb_read_error = READ_EOF; - return -1; - } - - if (readret == -1) { - smb_read_error = READ_ERROR; - return -1; - } - nread += readret; - } - return((ssize_t)nread); - } - - /* Most difficult - timeout read */ - /* If this is ever called on a disk file and - mincnt is greater then the filesize then - system performance will suffer severely as - select always returns true on disk files */ - - /* Set initial timeout */ - timeout.tv_sec = (time_t)(time_out / 1000); - timeout.tv_usec = (long)(1000 * (time_out % 1000)); - - for (nread=0; nread < mincnt; ) - { - FD_ZERO(&fds); - FD_SET(fd,&fds); - - selrtn = sys_select(fd+1,&fds,NULL, &timeout); - - /* Check if error */ - if(selrtn == -1) { - /* something is wrong. Maybe the socket is dead? */ - smb_read_error = READ_ERROR; - return -1; - } - - /* Did we timeout ? */ - if (selrtn == 0) { - smb_read_error = READ_TIMEOUT; - return -1; - } - + if (readret == 0) + { + smb_read_error = READ_EOF; + return -1; + } + + if (readret == -1) + { + smb_read_error = READ_ERROR; + return -1; + } + nread += readret; + } + return ((ssize_t) nread); + } + + /* Most difficult - timeout read */ + /* If this is ever called on a disk file and + mincnt is greater then the filesize then + system performance will suffer severely as + select always returns true on disk files */ + + /* Set initial timeout */ + timeout.tv_sec = (time_t) (time_out / 1000); + timeout.tv_usec = (long)(1000 * (time_out % 1000)); + + for (nread = 0; nread < mincnt;) + { + FD_ZERO(&fds); + FD_SET(fd, &fds); + + selrtn = sys_select(fd + 1, &fds, NULL, &timeout); + + /* Check if error */ + if (selrtn == -1) + { + /* something is wrong. Maybe the socket is dead? */ + smb_read_error = READ_ERROR; + return -1; + } + + /* Did we timeout ? */ + if (selrtn == 0) + { + smb_read_error = READ_TIMEOUT; + return -1; + } + #ifdef WITH_SSL - if(fd == sslFd){ - readret = SSL_read(ssl, buf + nread, maxcnt - nread); - }else{ - readret = read(fd, buf + nread, maxcnt - nread); - } + if (fd == sslFd) + { + readret = SSL_read(ssl, buf + nread, maxcnt - nread); + } + else + { + readret = read(fd, buf + nread, maxcnt - nread); + } #else /* WITH_SSL */ - readret = read(fd, buf+nread, maxcnt-nread); + readret = read(fd, buf + nread, maxcnt - nread); #endif /* WITH_SSL */ - if (readret == 0) { - /* we got EOF on the file descriptor */ - smb_read_error = READ_EOF; - return -1; - } - - if (readret == -1) { - /* the descriptor is probably dead */ - smb_read_error = READ_ERROR; - return -1; - } - - nread += readret; - } - - /* Return the number we got */ - return((ssize_t)nread); + if (readret == 0) + { + /* we got EOF on the file descriptor */ + smb_read_error = READ_EOF; + return -1; + } + + if (readret == -1) + { + /* the descriptor is probably dead */ + smb_read_error = READ_ERROR; + return -1; + } + + nread += readret; + } + + /* Return the number we got */ + return ((ssize_t) nread); } @@ -337,12 +400,12 @@ send a keepalive packet (rfc1002) ****************************************************************************/ BOOL send_keepalive(int client) { - unsigned char buf[4]; + unsigned char buf[4]; - buf[0] = 0x85; - buf[1] = buf[2] = buf[3] = 0; + buf[0] = 0x85; + buf[1] = buf[2] = buf[3] = 0; - return(write_data(client,(char *)buf,4) == 4); + return (write_data(client, (char *)buf, 4) == 4); } @@ -350,67 +413,75 @@ BOOL send_keepalive(int client) /**************************************************************************** read data from the client, reading exactly N bytes. ****************************************************************************/ -ssize_t read_data(int fd,char *buffer,size_t N) +ssize_t read_data(int fd, char *buffer, size_t N) { - ssize_t ret; - size_t total=0; - - smb_read_error = 0; + ssize_t ret; + size_t total = 0; + + smb_read_error = 0; - while (total < N) - { + while (total < N) + { #ifdef WITH_SSL - if(fd == sslFd){ - ret = SSL_read(ssl, buffer + total, N - total); - }else{ - ret = read(fd,buffer + total,N - total); - } + if (fd == sslFd) + { + ret = SSL_read(ssl, buffer + total, N - total); + } + else + { + ret = read(fd, buffer + total, N - total); + } #else /* WITH_SSL */ - ret = read(fd,buffer + total,N - total); + ret = read(fd, buffer + total, N - total); #endif /* WITH_SSL */ - if (ret == 0) - { - smb_read_error = READ_EOF; - return 0; - } - if (ret == -1) - { - smb_read_error = READ_ERROR; - return -1; - } - total += ret; - } - return (ssize_t)total; + if (ret == 0) + { + smb_read_error = READ_EOF; + return 0; + } + if (ret == -1) + { + smb_read_error = READ_ERROR; + return -1; + } + total += ret; + } + return (ssize_t) total; } /**************************************************************************** write data to a fd ****************************************************************************/ -ssize_t write_data(int fd,char *buffer,size_t N) +ssize_t write_data(int fd, char *buffer, size_t N) { - size_t total=0; - ssize_t ret; + size_t total = 0; + ssize_t ret; - while (total < N) - { + while (total < N) + { #ifdef WITH_SSL - if(fd == sslFd){ - ret = SSL_write(ssl,buffer + total,N - total); - }else{ - ret = write(fd,buffer + total,N - total); - } + if (fd == sslFd) + { + ret = SSL_write(ssl, buffer + total, N - total); + } + else + { + ret = write(fd, buffer + total, N - total); + } #else /* WITH_SSL */ - ret = write(fd,buffer + total,N - total); + ret = write(fd, buffer + total, N - total); #endif /* WITH_SSL */ - if (ret == -1) return -1; - if (ret == 0) return total; + if (ret == -1) + return -1; + if (ret == 0) + return total; - total += ret; - } - return (ssize_t)total; + total += ret; + } + return (ssize_t) total; } @@ -422,32 +493,35 @@ This version of the function will return a length of zero on receiving a keepalive packet. timeout is in milliseconds. ****************************************************************************/ -static ssize_t read_smb_length_return_keepalive(int fd,char *inbuf,unsigned int timeout) +static ssize_t read_smb_length_return_keepalive(int fd, char *inbuf, + unsigned int timeout) { - ssize_t len=0; - int msg_type; - BOOL ok = False; + ssize_t len = 0; + int msg_type; + BOOL ok = False; - while (!ok) - { - if (timeout > 0) - ok = (read_with_timeout(fd,inbuf,4,4,timeout) == 4); - else - ok = (read_data(fd,inbuf,4) == 4); + while (!ok) + { + if (timeout > 0) + ok = + (read_with_timeout(fd, inbuf, 4, 4, timeout) + == 4); + else + ok = (read_data(fd, inbuf, 4) == 4); - if (!ok) - return(-1); + if (!ok) + return (-1); - len = smb_len(inbuf); - msg_type = CVAL(inbuf,0); + len = smb_len(inbuf); + msg_type = CVAL(inbuf, 0); - if (msg_type == 0x85) - DEBUG(5,("Got keepalive packet\n")); - } + if (msg_type == 0x85) + DEBUG(5, ("Got keepalive packet\n")); + } - DEBUG(10,("got smb length of %d\n",len)); + DEBUG(10, ("got smb length of %d\n", len)); - return(len); + return (len); } /**************************************************************************** @@ -456,23 +530,23 @@ store the result in the buffer. This version of the function will never return a session keepalive (length of zero). timeout is in milliseconds. ****************************************************************************/ -ssize_t read_smb_length(int fd,char *inbuf,unsigned int timeout) +ssize_t read_smb_length(int fd, char *inbuf, unsigned int timeout) { - ssize_t len; + ssize_t len; - for(;;) - { - len = read_smb_length_return_keepalive(fd, inbuf, timeout); + for (;;) + { + len = read_smb_length_return_keepalive(fd, inbuf, timeout); - if(len < 0) - return len; + if (len < 0) + return len; - /* Ignore session keepalives. */ - if(CVAL(inbuf,0) != 0x85) - break; - } + /* Ignore session keepalives. */ + if (CVAL(inbuf, 0) != 0x85) + break; + } - return len; + return len; } /**************************************************************************** @@ -482,37 +556,40 @@ ssize_t read_smb_length(int fd,char *inbuf,unsigned int timeout) This function will return on a receipt of a session keepalive packet. ****************************************************************************/ -BOOL receive_smb(int fd,char *buffer, unsigned int timeout) +BOOL receive_smb(int fd, char *buffer, unsigned int timeout) { - ssize_t len,ret; - - smb_read_error = 0; - - bzero(buffer,smb_size + 100); - - len = read_smb_length_return_keepalive(fd,buffer,timeout); - if (len < 0) - { - DEBUG(10,("receive_smb: length < 0!\n")); - return(False); - } - - if (len > BUFFER_SIZE) { - DEBUG(0,("Invalid packet length! (%d bytes).\n",len)); - if (len > BUFFER_SIZE + (SAFETY_MARGIN/2)) - { - exit(1); - } - } - - if(len > 0) { - ret = read_data(fd,buffer+4,len); - if (ret != len) { - smb_read_error = READ_ERROR; - return False; - } - } - return(True); + ssize_t len, ret; + + smb_read_error = 0; + + bzero(buffer, smb_size + 100); + + len = read_smb_length_return_keepalive(fd, buffer, timeout); + if (len < 0) + { + DEBUG(10, ("receive_smb: length < 0!\n")); + return (False); + } + + if (len > BUFFER_SIZE) + { + DEBUG(0, ("Invalid packet length! (%d bytes).\n", len)); + if (len > BUFFER_SIZE + (SAFETY_MARGIN / 2)) + { + exit(1); + } + } + + if (len > 0) + { + ret = read_data(fd, buffer + 4, len); + if (ret != len) + { + smb_read_error = READ_ERROR; + return False; + } + } + return (True); } /**************************************************************************** @@ -526,27 +603,27 @@ BOOL receive_smb(int fd,char *buffer, unsigned int timeout) should never go into a blocking read. ****************************************************************************/ -BOOL client_receive_smb(int fd,char *buffer, unsigned int timeout) +BOOL client_receive_smb(int fd, char *buffer, unsigned int timeout) { - BOOL ret; - uint8 msg_type; - - for(;;) - { - ret = receive_smb(fd, buffer, timeout); - - if (!ret) - { - DEBUG(10,("client_receive_smb failed\n")); - show_msg(buffer); - return ret; - } - - /* Ignore session keepalive packets. */ - msg_type = CVAL(buffer,0); - if (msg_type != 0x85) - break; - } + BOOL ret; + uint8 msg_type; + + for (;;) + { + ret = receive_smb(fd, buffer, timeout); + + if (!ret) + { + DEBUG(10, ("client_receive_smb failed\n")); + show_msg(buffer); + return ret; + } + + /* Ignore session keepalive packets. */ + msg_type = CVAL(buffer, 0); + if (msg_type != 0x85) + break; + } if (msg_type == 0) { show_msg(buffer); @@ -555,33 +632,35 @@ BOOL client_receive_smb(int fd,char *buffer, unsigned int timeout) { dump_data(10, buffer, smb_len(buffer) + 4); } - show_msg(buffer); - return ret; + show_msg(buffer); + return ret; } /**************************************************************************** send an smb to a fd ****************************************************************************/ -BOOL send_smb(int fd,char *buffer) +BOOL send_smb(int fd, char *buffer) { - size_t len; - size_t nwritten=0; - ssize_t ret; - len = smb_len(buffer) + 4; - - while (nwritten < len) - { - ret = write_socket(fd,buffer+nwritten,len - nwritten); - if (ret <= 0) - { - DEBUG(0,("Error writing %d bytes to client. %d. Exiting\n",len,ret)); - close_sockets(); - exit(1); - } - nwritten += ret; - } - - return True; + size_t len; + size_t nwritten = 0; + ssize_t ret; + len = smb_len(buffer) + 4; + + while (nwritten < len) + { + ret = write_socket(fd, buffer + nwritten, len - nwritten); + if (ret <= 0) + { + DEBUG(0, + ("Error writing %d bytes to client. %d. Exiting\n", + len, ret)); + close_sockets(); + exit(1); + } + nwritten += ret; + } + + return True; } @@ -589,177 +668,205 @@ BOOL send_smb(int fd,char *buffer) /**************************************************************************** send a single packet to a port on another machine ****************************************************************************/ -BOOL send_one_packet(char *buf,int len,struct in_addr ip,int port,int type) +BOOL send_one_packet(char *buf, int len, struct in_addr ip, int port, + int type) { - BOOL ret; - int out_fd; - struct sockaddr_in sock_out; - - if (passive) - return(True); - - /* create a socket to write to */ - out_fd = socket(AF_INET, type, 0); - if (out_fd == -1) - { - DEBUG(0,("socket failed")); - return False; - } - - /* set the address and port */ - bzero((char *)&sock_out,sizeof(sock_out)); - putip((char *)&sock_out.sin_addr,(char *)&ip); - sock_out.sin_port = htons( port ); - sock_out.sin_family = AF_INET; - - if (DEBUGLEVEL > 0) - DEBUG(3,("sending a packet of len %d to (%s) on port %d of type %s\n", - len,inet_ntoa(ip),port,type==SOCK_DGRAM?"DGRAM":"STREAM")); - - /* send it */ - ret = (sendto(out_fd,buf,len,0,(struct sockaddr *)&sock_out,sizeof(sock_out)) >= 0); - - if (!ret) - DEBUG(0,("Packet send to %s(%d) failed ERRNO=%s\n", - inet_ntoa(ip),port,strerror(errno))); - - close(out_fd); - return(ret); + BOOL ret; + int out_fd; + struct sockaddr_in sock_out; + + if (passive) + return (True); + + /* create a socket to write to */ + out_fd = socket(AF_INET, type, 0); + if (out_fd == -1) + { + DEBUG(0, ("socket failed")); + return False; + } + + /* set the address and port */ + bzero((char *)&sock_out, sizeof(sock_out)); + putip((char *)&sock_out.sin_addr, (char *)&ip); + sock_out.sin_port = htons(port); + sock_out.sin_family = AF_INET; + + if (DEBUGLEVEL > 0) + DEBUG(3, + ("sending a packet of len %d to (%s) on port %d of type %s\n", + len, inet_ntoa(ip), port, + type == SOCK_DGRAM ? "DGRAM" : "STREAM")); + + /* send it */ + ret = + (sendto + (out_fd, buf, len, 0, (struct sockaddr *)&sock_out, + sizeof(sock_out)) >= 0); + + if (!ret) + DEBUG(0, ("Packet send to %s(%d) failed ERRNO=%s\n", + inet_ntoa(ip), port, strerror(errno))); + + close(out_fd); + return (ret); } /**************************************************************************** open a socket of the specified type, port and address for incoming data ****************************************************************************/ -int open_socket_in(int type, int port, int dlevel,uint32 socket_addr, - BOOL rebind) +int open_socket_in(int type, int port, int dlevel, uint32 socket_addr, + BOOL rebind) { - struct hostent *hp; - struct sockaddr_in sock; - pstring host_name; - int res; - - /* get my host name */ - if (gethostname(host_name, MAXHOSTNAMELEN) == -1) - { DEBUG(0,("gethostname failed\n")); return -1; } - - /* get host info */ - if ((hp = Get_Hostbyname(host_name)) == 0) - { - DEBUG(0,( "Get_Hostbyname: Unknown host %s\n",host_name)); - return -1; - } - - bzero((char *)&sock,sizeof(sock)); - memcpy((char *)&sock.sin_addr,(char *)hp->h_addr, hp->h_length); + struct hostent *hp; + struct sockaddr_in sock; + pstring host_name; + int res; + + /* get my host name */ + if (gethostname(host_name, MAXHOSTNAMELEN) == -1) + { + DEBUG(0, ("gethostname failed\n")); + return -1; + } + + /* get host info */ + if ((hp = Get_Hostbyname(host_name)) == 0) + { + DEBUG(0, ("Get_Hostbyname: Unknown host %s\n", host_name)); + return -1; + } + + bzero((char *)&sock, sizeof(sock)); + memcpy((char *)&sock.sin_addr, (char *)hp->h_addr, hp->h_length); #ifdef HAVE_SOCK_SIN_LEN - sock.sin_len = sizeof(sock); + sock.sin_len = sizeof(sock); #endif - sock.sin_port = htons( port ); - sock.sin_family = hp->h_addrtype; - sock.sin_addr.s_addr = socket_addr; - res = socket(hp->h_addrtype, type, 0); - if (res == -1) - { DEBUG(0,("socket failed\n")); return -1; } - - { - int val=1; - if(rebind) - val=1; - else - val=0; - setsockopt(res,SOL_SOCKET,SO_REUSEADDR,(char *)&val,sizeof(val)); - } - - /* now we've got a socket - we need to bind it */ - if (bind(res, (struct sockaddr * ) &sock,sizeof(sock)) < 0) - { - if (port) { - if (port == SMB_PORT || port == NMB_PORT) - DEBUG(dlevel,("bind failed on port %d socket_addr=%s (%s)\n", - port,inet_ntoa(sock.sin_addr),strerror(errno))); - close(res); - - if (dlevel > 0 && port < 1000) - port = 7999; - - if (port >= 1000 && port < 9000) - return(open_socket_in(type,port+1,dlevel,socket_addr,rebind)); - } - - return(-1); - } - DEBUG(3,("bind succeeded on port %d\n",port)); - - return res; + sock.sin_port = htons(port); + sock.sin_family = hp->h_addrtype; + sock.sin_addr.s_addr = socket_addr; + res = socket(hp->h_addrtype, type, 0); + if (res == -1) + { + DEBUG(0, ("socket failed\n")); + return -1; + } + + { + int val = 1; + if (rebind) + val = 1; + else + val = 0; + setsockopt(res, SOL_SOCKET, SO_REUSEADDR, (char *)&val, + sizeof(val)); + } + + /* now we've got a socket - we need to bind it */ + if (bind(res, (struct sockaddr *)&sock, sizeof(sock)) < 0) + { + if (port) + { + if (port == SMB_PORT || port == NMB_PORT) + DEBUG(dlevel, + ("bind failed on port %d socket_addr=%s (%s)\n", + port, inet_ntoa(sock.sin_addr), + strerror(errno))); + close(res); + + if (dlevel > 0 && port < 1000) + port = 7999; + + if (port >= 1000 && port < 9000) + return (open_socket_in + (type, port + 1, dlevel, socket_addr, + rebind)); + } + + return (-1); + } + DEBUG(3, ("bind succeeded on port %d\n", port)); + + return res; } /**************************************************************************** create an outgoing socket **************************************************************************/ -int open_socket_out(int type, struct in_addr *addr, int port ,int timeout) +int open_socket_out(int type, struct in_addr *addr, int port, int timeout) { - struct sockaddr_in sock_out; - int res,ret; - int connect_loop = 250; /* 250 milliseconds */ - int loops = (timeout * 1000) / connect_loop; - - /* create a socket to write to */ - res = socket(PF_INET, type, 0); - if (res == -1) - { DEBUG(0,("socket error\n")); return -1; } - - if (type != SOCK_STREAM) return(res); - - bzero((char *)&sock_out,sizeof(sock_out)); - putip((char *)&sock_out.sin_addr,(char *)addr); - - sock_out.sin_port = htons( port ); - sock_out.sin_family = PF_INET; - - /* set it non-blocking */ - set_blocking(res,False); - - DEBUG(3,("Connecting to %s at port %d\n",inet_ntoa(*addr),port)); - - /* and connect it to the destination */ -connect_again: - ret = connect(res,(struct sockaddr *)&sock_out,sizeof(sock_out)); - - /* Some systems return EAGAIN when they mean EINPROGRESS */ - if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY || - errno == EAGAIN) && loops--) { - msleep(connect_loop); - goto connect_again; - } - - if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY || - errno == EAGAIN)) { - DEBUG(1,("timeout connecting to %s:%d\n",inet_ntoa(*addr),port)); - close(res); - return -1; - } + struct sockaddr_in sock_out; + int res, ret; + int connect_loop = 250; /* 250 milliseconds */ + int loops = (timeout * 1000) / connect_loop; + + /* create a socket to write to */ + res = socket(PF_INET, type, 0); + if (res == -1) + { + DEBUG(0, ("socket error\n")); + return -1; + } + + if (type != SOCK_STREAM) + return (res); + + bzero((char *)&sock_out, sizeof(sock_out)); + putip((char *)&sock_out.sin_addr, (char *)addr); + + sock_out.sin_port = htons(port); + sock_out.sin_family = PF_INET; + + /* set it non-blocking */ + set_blocking(res, False); + + DEBUG(3, ("Connecting to %s at port %d\n", inet_ntoa(*addr), port)); + + /* and connect it to the destination */ + connect_again: + ret = connect(res, (struct sockaddr *)&sock_out, sizeof(sock_out)); + + /* Some systems return EAGAIN when they mean EINPROGRESS */ + if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY || + errno == EAGAIN) && loops--) + { + msleep(connect_loop); + goto connect_again; + } + + if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY || + errno == EAGAIN)) + { + DEBUG(1, + ("timeout connecting to %s:%d\n", inet_ntoa(*addr), + port)); + close(res); + return -1; + } #ifdef EISCONN - if (ret < 0 && errno == EISCONN) { - errno = 0; - ret = 0; - } + if (ret < 0 && errno == EISCONN) + { + errno = 0; + ret = 0; + } #endif - if (ret < 0) { - DEBUG(1,("error connecting to %s:%d (%s)\n", - inet_ntoa(*addr),port,strerror(errno))); - close(res); - return -1; - } + if (ret < 0) + { + DEBUG(1, ("error connecting to %s:%d (%s)\n", + inet_ntoa(*addr), port, strerror(errno))); + close(res); + return -1; + } - /* set it blocking again */ - set_blocking(res,True); + /* set it blocking again */ + set_blocking(res, True); - return res; + return res; } @@ -773,16 +880,16 @@ static BOOL global_client_name_done = False; static BOOL global_client_addr_done = False; static pstring client_name_buf; static fstring client_addr_buf; -static int last_fd=-1; +static int last_fd = -1; -void set_client_connection_name(const char* name, int fd) +void set_client_connection_name(const char *name, int fd) { global_client_name_done = True; pstrcpy(client_name_buf, name); last_fd = fd; } -void set_client_connection_addr(const char* addr, int fd) +void set_client_connection_addr(const char *addr, int fd) { global_client_addr_done = True; pstrcpy(client_addr_buf, addr); @@ -809,58 +916,69 @@ char *client_connection_addr(void) void reset_globals_after_fork(void) { - global_client_name_done = False; - global_client_addr_done = False; - - /* - * Re-seed the random crypto generator, so all smbd's - * started from the same parent won't generate the same - * sequence. - */ - { - unsigned char dummy; - generate_random_buffer( &dummy, 1, True); - } + global_client_name_done = False; + global_client_addr_done = False; + + /* + * Re-seed the random crypto generator, so all smbd's + * started from the same parent won't generate the same + * sequence. + */ + { + unsigned char dummy; + generate_random_buffer(&dummy, 1, True); + } } - + /******************************************************************* return the DNS name of the client ******************************************************************/ char *client_name(int fd) { struct sockaddr sa; - struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa); - int length = sizeof(sa); + struct sockaddr_in *sockin = (struct sockaddr_in *)(&sa); + int length = sizeof(sa); struct hostent *hp; - - if (global_client_name_done && last_fd == fd) + + if (global_client_name_done && last_fd == fd) return client_name_buf; - + last_fd = fd; global_client_name_done = False; - - pstrcpy(client_name_buf,"UNKNOWN"); - - if (fd == -1) { + + pstrcpy(client_name_buf, "UNKNOWN"); + + if (fd == -1) + { return client_name_buf; } - - if (getpeername(fd, &sa, &length) < 0) { - DEBUG(0,("getpeername failed. Error was %s\n", strerror(errno) )); + + if (getpeername(fd, &sa, &length) < 0) + { + DEBUG(0, + ("getpeername failed. Error was %s\n", + strerror(errno))); return client_name_buf; } - + /* Look up the remote host name. */ - if ((hp = gethostbyaddr((char *) &sockin->sin_addr, - sizeof(sockin->sin_addr), - AF_INET)) == 0) { - DEBUG(1,("Gethostbyaddr failed for %s\n",client_addr(fd))); - StrnCpy(client_name_buf,client_addr(fd),sizeof(client_name_buf) - 1); - } else { - StrnCpy(client_name_buf,(char *)hp->h_name,sizeof(client_name_buf) - 1); - if (!matchname(client_name_buf, sockin->sin_addr)) { - DEBUG(0,("Matchname failed on %s %s\n",client_name_buf,client_addr(fd))); - pstrcpy(client_name_buf,"UNKNOWN"); + if ((hp = gethostbyaddr((char *)&sockin->sin_addr, + sizeof(sockin->sin_addr), AF_INET)) == 0) + { + DEBUG(1, ("Gethostbyaddr failed for %s\n", client_addr(fd))); + StrnCpy(client_name_buf, client_addr(fd), + sizeof(client_name_buf) - 1); + } + else + { + StrnCpy(client_name_buf, (char *)hp->h_name, + sizeof(client_name_buf) - 1); + if (!matchname(client_name_buf, sockin->sin_addr)) + { + DEBUG(0, + ("Matchname failed on %s %s\n", client_name_buf, + client_addr(fd))); + pstrcpy(client_name_buf, "UNKNOWN"); } } global_client_name_done = True; @@ -873,28 +991,32 @@ char *client_name(int fd) char *client_addr(int fd) { struct sockaddr sa; - struct sockaddr_in *sockin = (struct sockaddr_in *) (&sa); - int length = sizeof(sa); + struct sockaddr_in *sockin = (struct sockaddr_in *)(&sa); + int length = sizeof(sa); - if (global_client_addr_done && fd == last_fd) + if (global_client_addr_done && fd == last_fd) return client_addr_buf; last_fd = fd; global_client_addr_done = False; - fstrcpy(client_addr_buf,"0.0.0.0"); + fstrcpy(client_addr_buf, "0.0.0.0"); - if (fd == -1) { + if (fd == -1) + { return client_addr_buf; } - - if (getpeername(fd, &sa, &length) < 0) { - DEBUG(0,("getpeername failed. Error was %s\n", strerror(errno) )); + + if (getpeername(fd, &sa, &length) < 0) + { + DEBUG(0, + ("getpeername failed. Error was %s\n", + strerror(errno))); return client_addr_buf; } - - fstrcpy(client_addr_buf,(char *)inet_ntoa(sockin->sin_addr)); - + + fstrcpy(client_addr_buf, (char *)inet_ntoa(sockin->sin_addr)); + global_client_addr_done = True; return client_addr_buf; } @@ -917,14 +1039,14 @@ int open_pipe_sock(char *path) ZERO_STRUCT(sa); sa.sun_family = AF_UNIX; - safe_strcpy(sa.sun_path, path, sizeof(sa.sun_path)-1); + safe_strcpy(sa.sun_path, path, sizeof(sa.sun_path) - 1); DEBUG(10, ("socket open succeeded. file name: %s\n", sa.sun_path)); - if (connect(sock, (struct sockaddr*) &sa, sizeof(sa)) < 0) + if (connect(sock, (struct sockaddr *)&sa, sizeof(sa)) < 0) { - DEBUG(1,("socket connect to %s failed: %s\n", - sa.sun_path,strerror(errno))); + DEBUG(1, ("socket connect to %s failed: %s\n", + sa.sun_path, strerror(errno))); close(sock); return -1; } @@ -932,19 +1054,19 @@ int open_pipe_sock(char *path) return sock; } -int create_pipe_socket(char *dir, int dir_perms, - char *path, int path_perms) +int create_pipe_socket(char *dir, int dir_perms, char *path, int path_perms) { int s; struct sockaddr_un sa; - DEBUG(0,("create_pipe_socket: %s perms=%d %s perms=%d\n", - dir, dir_perms, path, path_perms)); + DEBUG(0, ("create_pipe_socket: %s perms=%d %s perms=%d\n", + dir, dir_perms, path, path_perms)); - DEBUG(0,("*** Please someone examine create_pipe_socket and fix it ***\n")); - DEBUG(0,("*** if used other than for exclusive root access ***\n")); - DEBUG(0,("*** (see perms, which should be 0700 and 0600) ***\n")); - DEBUG(0,("*** there is a race condition to be exploited. ***\n")); + DEBUG(0, + ("*** Please someone examine create_pipe_socket and fix it ***\n")); + DEBUG(0, ("*** if used other than for exclusive root access ***\n")); + DEBUG(0, ("*** (see perms, which should be 0700 and 0600) ***\n")); + DEBUG(0, ("*** there is a race condition to be exploited. ***\n")); mkdir(dir, dir_perms); @@ -958,7 +1080,7 @@ int create_pipe_socket(char *dir, int dir_perms, { DEBUG(0, ("remove on %s failed\n", path)); } - + /* start listening on unix socket */ s = socket(AF_UNIX, SOCK_STREAM, 0); @@ -970,9 +1092,9 @@ int create_pipe_socket(char *dir, int dir_perms, ZERO_STRUCT(sa); sa.sun_family = AF_UNIX; - safe_strcpy(sa.sun_path, path, sizeof(sa.sun_path)-1); + safe_strcpy(sa.sun_path, path, sizeof(sa.sun_path) - 1); - if (bind(s, (struct sockaddr*) &sa, sizeof(sa)) < 0) + if (bind(s, (struct sockaddr *)&sa, sizeof(sa)) < 0) { DEBUG(0, ("socket bind to %s failed\n", sa.sun_path)); close(s); @@ -982,7 +1104,7 @@ int create_pipe_socket(char *dir, int dir_perms, if (s == -1) { - DEBUG(0,("bind failed\n")); + DEBUG(0, ("bind failed\n")); remove(path); return -1; } @@ -994,11 +1116,11 @@ int create_pipe_socket(char *dir, int dir_perms, if (listen(s, 5) == -1) { - DEBUG(0,("listen failed\n")); + DEBUG(0, ("listen failed\n")); return -1; } - DEBUG(5,("unix socket opened: %s\n", path)); + DEBUG(5, ("unix socket opened: %s\n", path)); return s; } diff --git a/source/lsarpcd/srv_lsa.c b/source/lsarpcd/srv_lsa.c index 707d13d99b4..d92aca30c4f 100644 --- a/source/lsarpcd/srv_lsa.c +++ b/source/lsarpcd/srv_lsa.c @@ -35,16 +35,16 @@ extern fstring global_myworkgroup; /*************************************************************************** make_dom_query ***************************************************************************/ -static void make_dom_query(DOM_QUERY *d_q, char *dom_name, DOM_SID *dom_sid) +static void make_dom_query(DOM_QUERY * d_q, char *dom_name, DOM_SID * dom_sid) { fstring sid_str; int domlen = strlen(dom_name); - d_q->uni_dom_str_len = (domlen+1) * 2; + d_q->uni_dom_str_len = (domlen + 1) * 2; d_q->uni_dom_max_len = domlen * 2; - d_q->buffer_dom_name = domlen != 0 ? 1 : 0; /* domain buffer pointer */ - d_q->buffer_dom_sid = dom_sid != NULL ? 1 : 0; /* domain sid pointer */ + d_q->buffer_dom_name = domlen != 0 ? 1 : 0; /* domain buffer pointer */ + d_q->buffer_dom_sid = dom_sid != NULL ? 1 : 0; /* domain sid pointer */ /* this string is supposed to be character short */ make_unistr2(&(d_q->uni_domain_name), dom_name, domlen); @@ -58,20 +58,21 @@ static void make_dom_query(DOM_QUERY *d_q, char *dom_name, DOM_SID *dom_sid) /*************************************************************************** make_reply_lookup_names ***************************************************************************/ -static void make_reply_lookup_names(LSA_R_LOOKUP_NAMES *r_l, - DOM_R_REF *ref, uint32 num_entries, - DOM_RID2 *rid2, uint32 mapped_count, +static void make_reply_lookup_names(LSA_R_LOOKUP_NAMES * r_l, + DOM_R_REF * ref, uint32 num_entries, + DOM_RID2 * rid2, uint32 mapped_count, uint32 status) { - r_l->ptr_dom_ref = (ref != NULL ? 1 : 0); - r_l->dom_ref = ref; + r_l->ptr_dom_ref = (ref != NULL ? 1 : 0); + r_l->dom_ref = ref; - if (rid2 == NULL) num_entries = 0; + if (rid2 == NULL) + num_entries = 0; - r_l->num_entries = num_entries; - r_l->ptr_entries = (rid2 != NULL ? 1 : 0); + r_l->num_entries = num_entries; + r_l->ptr_entries = (rid2 != NULL ? 1 : 0); r_l->num_entries2 = num_entries; - r_l->dom_rid = rid2; + r_l->dom_rid = rid2; r_l->mapped_count = mapped_count; @@ -81,21 +82,22 @@ static void make_reply_lookup_names(LSA_R_LOOKUP_NAMES *r_l, /*************************************************************************** make_reply_lookup_sids ***************************************************************************/ -static void make_reply_lookup_sids(LSA_R_LOOKUP_SIDS *r_l, - DOM_R_REF *ref, LSA_TRANS_NAME_ENUM *names, - uint32 mapped_count, uint32 status) +static void make_reply_lookup_sids(LSA_R_LOOKUP_SIDS * r_l, + DOM_R_REF * ref, + LSA_TRANS_NAME_ENUM * names, + uint32 mapped_count, uint32 status) { - r_l->ptr_dom_ref = 1; - r_l->dom_ref = ref; - r_l->names = names; + r_l->ptr_dom_ref = 1; + r_l->dom_ref = ref; + r_l->names = names; r_l->mapped_count = mapped_count; - r_l->status = status; + r_l->status = status; } /*************************************************************************** lsa_reply_lookup_sids ***************************************************************************/ -static BOOL lsa_reply_lookup_sids(LSA_Q_LOOKUP_SIDS *q_l, prs_struct *rdata) +static BOOL lsa_reply_lookup_sids(LSA_Q_LOOKUP_SIDS * q_l, prs_struct * rdata) { LSA_R_LOOKUP_SIDS r_l; DOM_R_REF ref; @@ -123,8 +125,8 @@ static BOOL lsa_reply_lookup_sids(LSA_Q_LOOKUP_SIDS *q_l, prs_struct *rdata) /*************************************************************************** api_lsa_open_policy ***************************************************************************/ -static BOOL api_lsa_open_policy2( rpcsrv_struct *p, prs_struct *data, - prs_struct *rdata ) +static BOOL api_lsa_open_policy2(rpcsrv_struct * p, prs_struct * data, + prs_struct * rdata) { LSA_Q_OPEN_POL2 q_o; LSA_R_OPEN_POL2 r_o; @@ -138,16 +140,15 @@ static BOOL api_lsa_open_policy2( rpcsrv_struct *p, prs_struct *data, } r_o.status = _lsa_open_policy2(&q_o.uni_server_name, &r_o.pol, - &q_o.attr, - q_o.des_access); + &q_o.attr, q_o.des_access); return lsa_io_r_open_pol2("", &r_o, rdata, 0); } /*************************************************************************** api_lsa_open_policy ***************************************************************************/ -static BOOL api_lsa_open_policy( rpcsrv_struct *p, prs_struct *data, - prs_struct *rdata ) +static BOOL api_lsa_open_policy(rpcsrv_struct * p, prs_struct * data, + prs_struct * rdata) { LSA_Q_OPEN_POL q_o; LSA_R_OPEN_POL r_o; @@ -161,15 +162,15 @@ static BOOL api_lsa_open_policy( rpcsrv_struct *p, prs_struct *data, } r_o.status = _lsa_open_policy(NULL, &r_o.pol, - &q_o.attr, q_o.des_access); + &q_o.attr, q_o.des_access); return lsa_io_r_open_pol("", &r_o, rdata, 0); } /*************************************************************************** api_lsa_enum_trust_dom ***************************************************************************/ -static BOOL api_lsa_enum_trust_dom( rpcsrv_struct *p, prs_struct *data, - prs_struct *rdata ) +static BOOL api_lsa_enum_trust_dom(rpcsrv_struct * p, prs_struct * data, + prs_struct * rdata) { uint32 status; uint32 enum_context; @@ -195,8 +196,7 @@ static BOOL api_lsa_enum_trust_dom( rpcsrv_struct *p, prs_struct *data, &uni_names, &sids); make_r_enum_trust_dom(&r_e, enum_context, - num_doms, uni_names, sids, - status); + num_doms, uni_names, sids, status); /* store the response in the SMB stream */ ret = lsa_io_r_enum_trust_dom("", &r_e, rdata, 0); @@ -211,8 +211,8 @@ static BOOL api_lsa_enum_trust_dom( rpcsrv_struct *p, prs_struct *data, /*************************************************************************** api_lsa_query_info ***************************************************************************/ -static BOOL api_lsa_query_info( rpcsrv_struct *p, prs_struct *data, - prs_struct *rdata ) +static BOOL api_lsa_query_info(rpcsrv_struct * p, prs_struct * data, + prs_struct * rdata) { LSA_Q_QUERY_INFO q_i; LSA_R_QUERY_INFO r_i; @@ -237,7 +237,7 @@ static BOOL api_lsa_query_info( rpcsrv_struct *p, prs_struct *data, { /* set up the LSA QUERY INFO response */ - r_i.undoc_buffer = 0x1; + r_i.undoc_buffer = 0x1; r_i.info_class = q_i.info_class; make_dom_query(&r_i.dom.id5, name, &sid); @@ -250,8 +250,8 @@ static BOOL api_lsa_query_info( rpcsrv_struct *p, prs_struct *data, /*************************************************************************** api_lsa_lookup_sids ***************************************************************************/ -static BOOL api_lsa_lookup_sids( rpcsrv_struct *p, prs_struct *data, - prs_struct *rdata ) +static BOOL api_lsa_lookup_sids(rpcsrv_struct * p, prs_struct * data, + prs_struct * rdata) { LSA_Q_LOOKUP_SIDS q_l; ZERO_STRUCT(q_l); @@ -269,8 +269,8 @@ static BOOL api_lsa_lookup_sids( rpcsrv_struct *p, prs_struct *data, /*************************************************************************** api_lsa_lookup_names ***************************************************************************/ -static BOOL api_lsa_lookup_names( rpcsrv_struct *p, prs_struct *data, - prs_struct *rdata ) +static BOOL api_lsa_lookup_names(rpcsrv_struct * p, prs_struct * data, + prs_struct * rdata) { LSA_Q_LOOKUP_NAMES q_l; LSA_R_LOOKUP_NAMES r_l; @@ -311,8 +311,8 @@ static BOOL api_lsa_lookup_names( rpcsrv_struct *p, prs_struct *data, /*************************************************************************** api_lsa_close ***************************************************************************/ -static BOOL api_lsa_close( rpcsrv_struct *p, prs_struct *data, - prs_struct *rdata) +static BOOL api_lsa_close(rpcsrv_struct * p, prs_struct * data, + prs_struct * rdata) { LSA_R_CLOSE r_c; LSA_Q_CLOSE q_c; @@ -325,7 +325,7 @@ static BOOL api_lsa_close( rpcsrv_struct *p, prs_struct *data, return False; } - r_c.pol = q_c.pol; /* in/out */ + r_c.pol = q_c.pol; /* in/out */ r_c.status = _lsa_close(&r_c.pol); return lsa_io_r_close("", &r_c, rdata, 0); } @@ -333,8 +333,8 @@ static BOOL api_lsa_close( rpcsrv_struct *p, prs_struct *data, /*************************************************************************** api_lsa_create_secret ***************************************************************************/ -static BOOL api_lsa_create_secret( rpcsrv_struct *p, prs_struct *data, - prs_struct *rdata) +static BOOL api_lsa_create_secret(rpcsrv_struct * p, prs_struct * data, + prs_struct * rdata) { LSA_R_CREATE_SECRET r_o; LSA_Q_CREATE_SECRET q_o; @@ -348,16 +348,16 @@ static BOOL api_lsa_create_secret( rpcsrv_struct *p, prs_struct *data, } r_o.status = _lsa_create_secret(&q_o.pol, - &q_o.uni_secret, q_o.des_access, - &r_o.pol); + &q_o.uni_secret, q_o.des_access, + &r_o.pol); return lsa_io_r_create_secret("", &r_o, rdata, 0); } /*************************************************************************** api_lsa_set_secret. AGH! HACK! :) ***************************************************************************/ -static BOOL api_lsa_set_secret( rpcsrv_struct *p, prs_struct *data, - prs_struct *rdata) +static BOOL api_lsa_set_secret(rpcsrv_struct * p, prs_struct * data, + prs_struct * rdata) { LSA_Q_SET_SECRET q_o; LSA_R_SET_SECRET r_o; @@ -371,7 +371,8 @@ static BOOL api_lsa_set_secret( rpcsrv_struct *p, prs_struct *data, return False; } - if (q_o.value.ptr_secret) val = &q_o.value.enc_secret; + if (q_o.value.ptr_secret) + val = &q_o.value.enc_secret; r_o.status = _lsa_set_secret(&q_o.pol, val, q_o.unknown); @@ -381,8 +382,8 @@ static BOOL api_lsa_set_secret( rpcsrv_struct *p, prs_struct *data, /*************************************************************************** api_lsa_query_secret. AGH! HACK! :) ***************************************************************************/ -static BOOL api_lsa_query_secret( rpcsrv_struct *p, prs_struct *data, - prs_struct *rdata) +static BOOL api_lsa_query_secret(rpcsrv_struct * p, prs_struct * data, + prs_struct * rdata) { LSA_R_QUERY_SECRET r_o; LSA_Q_QUERY_SECRET q_o; @@ -400,29 +401,32 @@ static BOOL api_lsa_query_secret( rpcsrv_struct *p, prs_struct *data, } /* HACK! */ - if (q_o.sec.curinfo.ptr_value != 0) curval = &q_o.sec.curinfo.value.enc_secret; - if (q_o.sec.curinfo.ptr_update != 0) curtim = &q_o.sec.curinfo.last_update; - if (q_o.sec.oldinfo.ptr_value != 0) oldval = &q_o.sec.oldinfo.value.enc_secret; - if (q_o.sec.oldinfo.ptr_update != 0) oldtim = &q_o.sec.oldinfo.last_update; + if (q_o.sec.curinfo.ptr_value != 0) + curval = &q_o.sec.curinfo.value.enc_secret; + if (q_o.sec.curinfo.ptr_update != 0) + curtim = &q_o.sec.curinfo.last_update; + if (q_o.sec.oldinfo.ptr_value != 0) + oldval = &q_o.sec.oldinfo.value.enc_secret; + if (q_o.sec.oldinfo.ptr_update != 0) + oldtim = &q_o.sec.oldinfo.last_update; r_o.status = _lsa_query_secret(&q_o.pol, - curval, curtim, - oldval, oldtim); + curval, curtim, oldval, oldtim); - memcpy(&r_o.sec, &q_o.sec, sizeof(r_o.sec)); /* urgh! HACK! */ - if (r_o.sec.curinfo.ptr_value != 0) /* MORE HACK! */ + memcpy(&r_o.sec, &q_o.sec, sizeof(r_o.sec)); /* urgh! HACK! */ + if (r_o.sec.curinfo.ptr_value != 0) /* MORE HACK! */ { r_o.sec.curinfo.value.ptr_secret = 1; make_strhdr2(&r_o.sec.curinfo.value.hdr_secret, - r_o.sec.curinfo.value.enc_secret.str_str_len, - r_o.sec.curinfo.value.enc_secret.str_max_len, 1); + r_o.sec.curinfo.value.enc_secret.str_str_len, + r_o.sec.curinfo.value.enc_secret.str_max_len, 1); } - if (r_o.sec.oldinfo.ptr_value != 0) /* MORE HACK! */ + if (r_o.sec.oldinfo.ptr_value != 0) /* MORE HACK! */ { r_o.sec.curinfo.value.ptr_secret = 1; make_strhdr2(&r_o.sec.oldinfo.value.hdr_secret, - r_o.sec.oldinfo.value.enc_secret.str_str_len, - r_o.sec.oldinfo.value.enc_secret.str_max_len, 1); + r_o.sec.oldinfo.value.enc_secret.str_str_len, + r_o.sec.oldinfo.value.enc_secret.str_max_len, 1); } return lsa_io_r_query_secret("", &r_o, rdata, 0); @@ -431,8 +435,8 @@ static BOOL api_lsa_query_secret( rpcsrv_struct *p, prs_struct *data, /*************************************************************************** api_lsa_create_secret ***************************************************************************/ -static BOOL api_lsa_open_secret( rpcsrv_struct *p, prs_struct *data, - prs_struct *rdata) +static BOOL api_lsa_open_secret(rpcsrv_struct * p, prs_struct * data, + prs_struct * rdata) { LSA_R_OPEN_SECRET r_o; LSA_Q_OPEN_SECRET q_o; @@ -454,26 +458,25 @@ static BOOL api_lsa_open_secret( rpcsrv_struct *p, prs_struct *data, /*************************************************************************** \PIPE\ntlsa commands ***************************************************************************/ -static const struct api_struct api_lsa_cmds[] = -{ - { "LSA_OPENPOLICY2" , LSA_OPENPOLICY2 , api_lsa_open_policy2 }, - { "LSA_OPENPOLICY" , LSA_OPENPOLICY , api_lsa_open_policy }, - { "LSA_QUERYINFOPOLICY", LSA_QUERYINFOPOLICY, api_lsa_query_info }, - { "LSA_ENUMTRUSTDOM" , LSA_ENUMTRUSTDOM , api_lsa_enum_trust_dom }, - { "LSA_CLOSE" , LSA_CLOSE , api_lsa_close }, - { "LSA_OPENSECRET" , LSA_OPENSECRET , api_lsa_open_secret }, - { "LSA_CREATESECRET" , LSA_CREATESECRET , api_lsa_create_secret }, - { "LSA_QUERYSECRET" , LSA_QUERYSECRET , api_lsa_query_secret }, - { "LSA_SETSECRET" , LSA_SETSECRET , api_lsa_set_secret }, - { "LSA_LOOKUPSIDS" , LSA_LOOKUPSIDS , api_lsa_lookup_sids }, - { "LSA_LOOKUPNAMES" , LSA_LOOKUPNAMES , api_lsa_lookup_names }, - { NULL , 0 , NULL } +static const struct api_struct api_lsa_cmds[] = { + {"LSA_OPENPOLICY2", LSA_OPENPOLICY2, api_lsa_open_policy2}, + {"LSA_OPENPOLICY", LSA_OPENPOLICY, api_lsa_open_policy}, + {"LSA_QUERYINFOPOLICY", LSA_QUERYINFOPOLICY, api_lsa_query_info}, + {"LSA_ENUMTRUSTDOM", LSA_ENUMTRUSTDOM, api_lsa_enum_trust_dom}, + {"LSA_CLOSE", LSA_CLOSE, api_lsa_close}, + {"LSA_OPENSECRET", LSA_OPENSECRET, api_lsa_open_secret}, + {"LSA_CREATESECRET", LSA_CREATESECRET, api_lsa_create_secret}, + {"LSA_QUERYSECRET", LSA_QUERYSECRET, api_lsa_query_secret}, + {"LSA_SETSECRET", LSA_SETSECRET, api_lsa_set_secret}, + {"LSA_LOOKUPSIDS", LSA_LOOKUPSIDS, api_lsa_lookup_sids}, + {"LSA_LOOKUPNAMES", LSA_LOOKUPNAMES, api_lsa_lookup_names}, + {NULL, 0, NULL} }; /*************************************************************************** api_ntLsarpcTNP ***************************************************************************/ -BOOL api_ntlsa_rpc(rpcsrv_struct *p) +BOOL api_ntlsa_rpc(rpcsrv_struct * p) { return api_rpcTNP(p, "api_ntlsa_rpc", api_lsa_cmds); } diff --git a/source/lsarpcd/srv_lsa_samdb.c b/source/lsarpcd/srv_lsa_samdb.c index e8e081ee5bc..d281e91292f 100644 --- a/source/lsarpcd/srv_lsa_samdb.c +++ b/source/lsarpcd/srv_lsa_samdb.c @@ -34,29 +34,29 @@ extern int DEBUGLEVEL; /**************************************************************************** set secret tdb database ****************************************************************************/ -static BOOL set_tdbsecdb(struct policy_cache *cache, POLICY_HND *hnd, - TDB_CONTEXT *tdb) +static BOOL set_tdbsecdb(struct policy_cache *cache, POLICY_HND * hnd, + TDB_CONTEXT * tdb) { if (tdb != NULL) { - if (set_policy_state(cache, hnd, tdb_close, (void*)tdb)) + if (set_policy_state(cache, hnd, tdb_close, (void *)tdb)) { return True; } tdb_close(tdb); return False; } - DEBUG(3,("Error setting policy secret database\n")); + DEBUG(3, ("Error setting policy secret database\n")); return False; } /**************************************************************************** get tdb database handle ****************************************************************************/ -static BOOL get_tdbsecdb(struct policy_cache *cache, const POLICY_HND *hnd, - TDB_CONTEXT **tdb) +static BOOL get_tdbsecdb(struct policy_cache *cache, const POLICY_HND * hnd, + TDB_CONTEXT ** tdb) { - (*tdb) = (TDB_CONTEXT*)get_policy_state_info(cache, hnd); + (*tdb) = (TDB_CONTEXT *) get_policy_state_info(cache, hnd); return True; } @@ -66,11 +66,12 @@ typedef struct tdb_sec_info UNISTR2 name; TDB_CONTEXT *tdb; -} TDB_SEC_INFO; +} +TDB_SEC_INFO; -static void secnamefree(void*inf) +static void secnamefree(void *inf) { - TDB_SEC_INFO *dev = (TDB_SEC_INFO*)inf; + TDB_SEC_INFO *dev = (TDB_SEC_INFO *) inf; if (dev != NULL) { tdb_close(dev->tdb); @@ -81,9 +82,8 @@ static void secnamefree(void*inf) /**************************************************************************** set tdb secret name ****************************************************************************/ -static BOOL set_tdbsecname(struct policy_cache *cache, POLICY_HND *hnd, - TDB_CONTEXT *tdb, - const UNISTR2 *name) +static BOOL set_tdbsecname(struct policy_cache *cache, POLICY_HND * hnd, + TDB_CONTEXT * tdb, const UNISTR2 * name) { TDB_SEC_INFO *dev = malloc(sizeof(*dev)); @@ -91,31 +91,32 @@ static BOOL set_tdbsecname(struct policy_cache *cache, POLICY_HND *hnd, { copy_unistr2(&dev->name, name); dev->tdb = tdb; - if (set_policy_state(cache, hnd, secnamefree, (void*)dev)) + if (set_policy_state(cache, hnd, secnamefree, (void *)dev)) { if (DEBUGLVL(3)) { fstring tmp; - unistr2_to_ascii(tmp, name, sizeof(tmp)-1); - DEBUG(3,("setting tdb secret name=%s\n", tmp)); + unistr2_to_ascii(tmp, name, sizeof(tmp) - 1); + DEBUG(3, + ("setting tdb secret name=%s\n", tmp)); } return True; } free(dev); return False; } - DEBUG(3,("Error setting tdb secret name\n")); + DEBUG(3, ("Error setting tdb secret name\n")); return False; } /**************************************************************************** get tdb secret name ****************************************************************************/ -static BOOL get_tdbsecname(struct policy_cache *cache, const POLICY_HND *hnd, - TDB_CONTEXT **tdb, - UNISTR2 *name) +static BOOL get_tdbsecname(struct policy_cache *cache, const POLICY_HND * hnd, + TDB_CONTEXT ** tdb, UNISTR2 * name) { - TDB_SEC_INFO *dev = (TDB_SEC_INFO*)get_policy_state_info(cache, hnd); + TDB_SEC_INFO *dev = + (TDB_SEC_INFO *) get_policy_state_info(cache, hnd); if (dev != NULL) { @@ -130,15 +131,15 @@ static BOOL get_tdbsecname(struct policy_cache *cache, const POLICY_HND *hnd, return True; } - DEBUG(3,("Error getting policy rid\n")); + DEBUG(3, ("Error getting policy rid\n")); return False; } + /*************************************************************************** lsa_reply_open_policy2 ***************************************************************************/ -uint32 _lsa_open_policy2(const UNISTR2 *server_name, POLICY_HND *hnd, - const LSA_OBJ_ATTR *attr, - uint32 des_access) +uint32 _lsa_open_policy2(const UNISTR2 * server_name, POLICY_HND * hnd, + const LSA_OBJ_ATTR * attr, uint32 des_access) { if (hnd == NULL) { @@ -147,13 +148,12 @@ uint32 _lsa_open_policy2(const UNISTR2 *server_name, POLICY_HND *hnd, /* get a (unique) handle. open a policy on it. */ if (!open_policy_hnd(get_global_hnd_cache(), - get_sec_ctx(), hnd, des_access)) + get_sec_ctx(), hnd, des_access)) { return NT_STATUS_ACCESS_DENIED; } - policy_hnd_set_name(get_global_hnd_cache(), - hnd, "open_policy2"); + policy_hnd_set_name(get_global_hnd_cache(), hnd, "open_policy2"); return NT_STATUS_NOPROBLEMO; } @@ -161,9 +161,8 @@ uint32 _lsa_open_policy2(const UNISTR2 *server_name, POLICY_HND *hnd, /*************************************************************************** lsa_reply_open_policy ***************************************************************************/ -uint32 _lsa_open_policy(const UNISTR2 *server_name, POLICY_HND *hnd, - const LSA_OBJ_ATTR *attr, - uint32 des_access) +uint32 _lsa_open_policy(const UNISTR2 * server_name, POLICY_HND * hnd, + const LSA_OBJ_ATTR * attr, uint32 des_access) { if (hnd == NULL) { @@ -172,13 +171,12 @@ uint32 _lsa_open_policy(const UNISTR2 *server_name, POLICY_HND *hnd, /* get a (unique) handle. open a policy on it. */ if (!open_policy_hnd(get_global_hnd_cache(), - get_sec_ctx(), hnd, des_access)) + get_sec_ctx(), hnd, des_access)) { return NT_STATUS_ACCESS_DENIED; } - policy_hnd_set_name(get_global_hnd_cache(), - hnd, "open_policy"); + policy_hnd_set_name(get_global_hnd_cache(), hnd, "open_policy"); return NT_STATUS_NOPROBLEMO; } @@ -186,12 +184,12 @@ uint32 _lsa_open_policy(const UNISTR2 *server_name, POLICY_HND *hnd, /*************************************************************************** _lsa_enum_trust_dom ***************************************************************************/ -uint32 _lsa_enum_trust_dom(POLICY_HND *hnd, uint32 *enum_ctx, - uint32 *num_doms, UNISTR2 **uni_names, - DOM_SID ***sids) +uint32 _lsa_enum_trust_dom(POLICY_HND * hnd, uint32 * enum_ctx, + uint32 * num_doms, UNISTR2 ** uni_names, + DOM_SID *** sids) { /* Should send on something good */ - + *enum_ctx = 0; *num_doms = 0; *uni_names = NULL; @@ -204,16 +202,16 @@ uint32 _lsa_enum_trust_dom(POLICY_HND *hnd, uint32 *enum_ctx, _lsa_lookup_names ***************************************************************************/ static uint32 get_remote_sid(const char *dom_name, char *find_name, - DOM_SID *sid, uint32 *rid, uint32 *sid_name_use) + DOM_SID * sid, uint32 * rid, + uint32 * sid_name_use) { fstring srv_name; fstring dummy; uint32 status; - DEBUG(10, ("lookup remote name: %s %s\n", - dom_name, find_name)); + DEBUG(10, ("lookup remote name: %s %s\n", dom_name, find_name)); - if (! get_any_dc_name(dom_name, srv_name)) + if (!get_any_dc_name(dom_name, srv_name)) { return NT_STATUS_NONE_MAPPED; } @@ -223,22 +221,20 @@ static uint32 get_remote_sid(const char *dom_name, char *find_name, return NT_STATUS_NONE_MAPPED; } - status = lookup_lsa_name(dom_name, find_name, - sid, sid_name_use); + status = lookup_lsa_name(dom_name, find_name, sid, sid_name_use); if (status == NT_STATUS_NOPROBLEMO && - (!sid_split_rid(sid, rid) || - !map_domain_sid_to_name(sid, dummy))) + (!sid_split_rid(sid, rid) || !map_domain_sid_to_name(sid, dummy))) { status = NT_STATUS_NONE_MAPPED; } return status; } -uint32 _lsa_lookup_names(const POLICY_HND *pol, - uint32 num_entries, const UNISTR2 *name, - DOM_R_REF *ref, DOM_RID2 **ret_rid2, - uint32 *mapped_count) +uint32 _lsa_lookup_names(const POLICY_HND * pol, + uint32 num_entries, const UNISTR2 * name, + DOM_R_REF * ref, DOM_RID2 ** ret_rid2, + uint32 * mapped_count) { int i; int total = 0; @@ -261,7 +257,7 @@ uint32 _lsa_lookup_names(const POLICY_HND *pol, fstring full_name; uint32 sid_name_use = SID_NAME_UNKNOWN; - unistr2_to_ascii(full_name, &name[i], sizeof(full_name)-1); + unistr2_to_ascii(full_name, &name[i], sizeof(full_name) - 1); find_name = strdup(full_name); if (!split_domain_name(full_name, dom_name, find_name)) @@ -286,19 +282,20 @@ uint32 _lsa_lookup_names(const POLICY_HND *pol, { pstring tmp; sid_to_string(tmp, &find_sid); - DEBUG(10,("lookup sam name: %s %s\n", - tmp, find_name)); + DEBUG(10, ("lookup sam name: %s %s\n", + tmp, find_name)); status1 = lookup_sam_name(NULL, - &find_sid, - find_name, - &rid, &sid_name_use); + &find_sid, + find_name, + &rid, + &sid_name_use); sid_copy(&sid, &find_sid); } else { status1 = get_remote_sid(dom_name, find_name, - &sid, &rid, - &sid_name_use); + &sid, &rid, + &sid_name_use); } } @@ -340,12 +337,11 @@ uint32 _lsa_lookup_names(const POLICY_HND *pol, /*************************************************************************** _lsa_lookup_sids ***************************************************************************/ -uint32 _lsa_lookup_sids(const POLICY_HND *hnd, - uint32 num_entries, DOM_SID2 *sid, - const LOOKUP_LEVEL *level, - DOM_R_REF *ref, - LSA_TRANS_NAME_ENUM *trn, - uint32 *mapped_count) +uint32 _lsa_lookup_sids(const POLICY_HND * hnd, + uint32 num_entries, DOM_SID2 * sid, + const LOOKUP_LEVEL * level, + DOM_R_REF * ref, + LSA_TRANS_NAME_ENUM * trn, uint32 * mapped_count) { int i; int total = 0; @@ -364,36 +360,36 @@ uint32 _lsa_lookup_sids(const POLICY_HND *hnd, { uint32 status1 = NT_STATUS_NOPROBLEMO; DOM_SID find_sid = sid[i].sid; - DOM_SID tmp_sid = sid[i].sid; + DOM_SID tmp_sid = sid[i].sid; uint32 rid = 0xffffffff; int dom_idx = -1; fstring name; fstring dom_name; uint32 sid_name_use = 0; - + memset(dom_name, 0, sizeof(dom_name)); - memset(name , 0, sizeof(name )); + memset(name, 0, sizeof(name)); if (map_domain_sid_to_name(&find_sid, dom_name)) { sid_name_use = SID_NAME_DOMAIN; name[0] = 0; } - else if (sid_split_rid (&find_sid, &rid) && + else if (sid_split_rid(&find_sid, &rid) && map_domain_sid_to_name(&find_sid, dom_name)) { if (sid_equal(&find_sid, &global_sam_sid) || sid_equal(&find_sid, global_sid_builtin)) { status1 = lookup_sam_rid(dom_name, - &find_sid, rid, - name, &sid_name_use); + &find_sid, rid, + name, &sid_name_use); } else { status1 = lookup_lsa_sid(dom_name, - &tmp_sid, - name, &sid_name_use); + &tmp_sid, + name, &sid_name_use); } } else @@ -412,9 +408,9 @@ uint32 _lsa_lookup_sids(const POLICY_HND *hnd, snprintf(name, sizeof(name), "%08x", rid); sid_name_use = SID_NAME_UNKNOWN; } - make_lsa_trans_name(&(trn->name [total]), - &(trn->uni_name[total]), - sid_name_use, name, dom_idx); + make_lsa_trans_name(&(trn->name[total]), + &(trn->uni_name[total]), + sid_name_use, name, dom_idx); total++; } @@ -433,8 +429,8 @@ uint32 _lsa_lookup_sids(const POLICY_HND *hnd, /*************************************************************************** _lsa_query_info ***************************************************************************/ -uint32 _lsa_query_info_pol(POLICY_HND *hnd, uint16 info_class, - fstring domain_name, DOM_SID *domain_sid) +uint32 _lsa_query_info_pol(POLICY_HND * hnd, uint16 info_class, + fstring domain_name, DOM_SID * domain_sid) { fstring name; uint32 status = NT_STATUS_NOPROBLEMO; @@ -465,7 +461,7 @@ uint32 _lsa_query_info_pol(POLICY_HND *hnd, uint16 info_class, default: { DEBUG(3, ("unknown info level in Lsa Query: %d\n", - info_class)); + info_class)); status = NT_STATUS_INVALID_INFO_CLASS; } } @@ -484,7 +480,7 @@ uint32 _lsa_query_info_pol(POLICY_HND *hnd, uint16 info_class, /*************************************************************************** _lsa_close ***************************************************************************/ -uint32 _lsa_close(POLICY_HND *hnd) +uint32 _lsa_close(POLICY_HND * hnd) { if (!close_policy_hnd(get_global_hnd_cache(), hnd)) { @@ -496,9 +492,8 @@ uint32 _lsa_close(POLICY_HND *hnd) /*************************************************************************** _lsa_set_secret ***************************************************************************/ -uint32 _lsa_set_secret(const POLICY_HND *hnd_secret, - const STRING2 *val, - uint32 unknown) +uint32 _lsa_set_secret(const POLICY_HND * hnd_secret, + const STRING2 * val, uint32 unknown) { TDB_CONTEXT *tdb = NULL; UNISTR2 secret_name; @@ -507,7 +502,7 @@ uint32 _lsa_set_secret(const POLICY_HND *hnd_secret, NTTIME ntt; if (!pol_get_usr_sesskey(get_global_hnd_cache(), hnd_secret, - user_sess_key)) + user_sess_key)) { return NT_STATUS_INVALID_HANDLE; } @@ -518,17 +513,17 @@ uint32 _lsa_set_secret(const POLICY_HND *hnd_secret, ZERO_STRUCT(secret_name); if (!get_tdbsecname(get_global_hnd_cache(), hnd_secret, &tdb, - &secret_name)) + &secret_name)) { return NT_STATUS_ACCESS_DENIED; } if (tdb_writelock(tdb) != 0) { - DEBUG(10,("_lsa_set_secret: write lock denied\n")); + DEBUG(10, ("_lsa_set_secret: write lock denied\n")); return NT_STATUS_ACCESS_DENIED; } - + if (!tdb_lookup_secret(tdb, &secret_name, &sec)) { return NT_STATUS_ACCESS_DENIED; @@ -538,13 +533,13 @@ uint32 _lsa_set_secret(const POLICY_HND *hnd_secret, { return NT_STATUS_ACCESS_DENIED; } - + /* store old info */ memcpy(&sec->oldinfo, &sec->curinfo, sizeof(sec->oldinfo)); /* decode and store new value, update time */ if (!nt_decrypt_string2(&sec->curinfo.value.enc_secret, val, - user_sess_key)) + user_sess_key)) { safe_free(sec); return NT_STATUS_INVALID_PARAMETER; @@ -553,8 +548,8 @@ uint32 _lsa_set_secret(const POLICY_HND *hnd_secret, { sec->curinfo.ptr_value = 1; make_strhdr2(&sec->curinfo.value.hdr_secret, - sec->curinfo.value.enc_secret.str_max_len, - sec->curinfo.value.enc_secret.str_str_len, 1); + sec->curinfo.value.enc_secret.str_max_len, + sec->curinfo.value.enc_secret.str_str_len, 1); sec->curinfo.value.ptr_secret = 1; } @@ -570,7 +565,7 @@ uint32 _lsa_set_secret(const POLICY_HND *hnd_secret, } tdb_writeunlock(tdb); - + safe_free(sec); return NT_STATUS_NOPROBLEMO; } @@ -578,9 +573,9 @@ uint32 _lsa_set_secret(const POLICY_HND *hnd_secret, /*************************************************************************** _lsa_query_secret ***************************************************************************/ -uint32 _lsa_query_secret(const POLICY_HND *hnd_secret, - STRING2 *curval, NTTIME *curtime, - STRING2 *oldval, NTTIME *oldtime) +uint32 _lsa_query_secret(const POLICY_HND * hnd_secret, + STRING2 * curval, NTTIME * curtime, + STRING2 * oldval, NTTIME * oldtime) { TDB_CONTEXT *tdb = NULL; UNISTR2 secret_name; @@ -588,7 +583,7 @@ uint32 _lsa_query_secret(const POLICY_HND *hnd_secret, uchar user_sess_key[16]; if (!pol_get_usr_sesskey(get_global_hnd_cache(), hnd_secret, - user_sess_key)) + user_sess_key)) { return NT_STATUS_INVALID_HANDLE; } @@ -599,7 +594,7 @@ uint32 _lsa_query_secret(const POLICY_HND *hnd_secret, ZERO_STRUCT(secret_name); if (!get_tdbsecname(get_global_hnd_cache(), hnd_secret, &tdb, - &secret_name)) + &secret_name)) { return NT_STATUS_ACCESS_DENIED; } @@ -613,7 +608,7 @@ uint32 _lsa_query_secret(const POLICY_HND *hnd_secret, { return NT_STATUS_ACCESS_DENIED; } - + if (curtime != NULL) { (*curtime) = sec->curinfo.last_update; @@ -624,8 +619,8 @@ uint32 _lsa_query_secret(const POLICY_HND *hnd_secret, } if (curval != NULL) { - if (!nt_encrypt_string2(curval, &sec->curinfo.value.enc_secret, - user_sess_key)) + if (!nt_encrypt_string2 + (curval, &sec->curinfo.value.enc_secret, user_sess_key)) { safe_free(sec); return NT_STATUS_INVALID_PARAMETER; @@ -633,8 +628,8 @@ uint32 _lsa_query_secret(const POLICY_HND *hnd_secret, } if (oldval != NULL) { - if (!nt_encrypt_string2(oldval, &sec->oldinfo.value.enc_secret, - user_sess_key)) + if (!nt_encrypt_string2 + (oldval, &sec->oldinfo.value.enc_secret, user_sess_key)) { safe_free(sec); return NT_STATUS_INVALID_PARAMETER; @@ -647,9 +642,9 @@ uint32 _lsa_query_secret(const POLICY_HND *hnd_secret, /*************************************************************************** _lsa_create_secret ***************************************************************************/ -uint32 _lsa_create_secret(const POLICY_HND *hnd, - const UNISTR2 *secret_name, uint32 des_access, - POLICY_HND *hnd_secret) +uint32 _lsa_create_secret(const POLICY_HND * hnd, + const UNISTR2 * secret_name, uint32 des_access, + POLICY_HND * hnd_secret) { TDB_CONTEXT *tdb; LSA_SECRET sec; @@ -665,14 +660,14 @@ uint32 _lsa_create_secret(const POLICY_HND *hnd, if (tdb_lookup_secret(tdb, secret_name, NULL)) { - DEBUG(10,("_lsa_create_secret: secret exists\n")); + DEBUG(10, ("_lsa_create_secret: secret exists\n")); /* XXX - shouldn't tdb be closed here? (Elrond) */ return NT_STATUS_ACCESS_DENIED; } /* get a (unique) handle. open a policy on it. */ if (!open_policy_hnd_link(get_global_hnd_cache(), - hnd, hnd_secret, des_access)) + hnd, hnd_secret, des_access)) { tdb_close(tdb); return NT_STATUS_ACCESS_DENIED; @@ -681,7 +676,8 @@ uint32 _lsa_create_secret(const POLICY_HND *hnd, policy_hnd_set_name(get_global_hnd_cache(), hnd_secret, "secret (create)"); - if (!set_tdbsecname(get_global_hnd_cache(), hnd_secret, tdb, secret_name)) + if (!set_tdbsecname + (get_global_hnd_cache(), hnd_secret, tdb, secret_name)) { close_policy_hnd(get_global_hnd_cache(), hnd_secret); return NT_STATUS_ACCESS_DENIED; @@ -707,18 +703,20 @@ uint32 _lsa_create_secret(const POLICY_HND *hnd, /*************************************************************************** _lsa_open_secret ***************************************************************************/ -uint32 _lsa_open_secret(const POLICY_HND *hnd, - const UNISTR2 *secret_name, uint32 des_access, - POLICY_HND *hnd_secret) +uint32 _lsa_open_secret(const POLICY_HND * hnd, + const UNISTR2 * secret_name, uint32 des_access, + POLICY_HND * hnd_secret) { TDB_CONTEXT *tdb; tdb = open_secret_db(O_RDWR); if (tdb == NULL) { - DEBUG(0, ("_lsa_open_secret: couldn't open secret_db. Possible attack?")); - DEBUG(0, ("\nuid=%d, gid=%d, euid=%d, egid=%d\n", - getuid(), getgid(), geteuid(), getegid())); + DEBUG(0, + ("_lsa_open_secret: couldn't open secret_db. Possible attack?")); + DEBUG(0, + ("\nuid=%d, gid=%d, euid=%d, egid=%d\n", getuid(), + getgid(), geteuid(), getegid())); return NT_STATUS_ACCESS_DENIED; } @@ -730,7 +728,7 @@ uint32 _lsa_open_secret(const POLICY_HND *hnd, /* get a (unique) handle. open a policy on it. */ if (!open_policy_hnd_link(get_global_hnd_cache(), - hnd, hnd_secret, des_access)) + hnd, hnd_secret, des_access)) { tdb_close(tdb); return NT_STATUS_ACCESS_DENIED; @@ -739,7 +737,8 @@ uint32 _lsa_open_secret(const POLICY_HND *hnd, policy_hnd_set_name(get_global_hnd_cache(), hnd_secret, "secret (open)"); - if (!set_tdbsecname(get_global_hnd_cache(), hnd_secret, tdb, secret_name)) + if (!set_tdbsecname + (get_global_hnd_cache(), hnd_secret, tdb, secret_name)) { close_policy_hnd(get_global_hnd_cache(), hnd_secret); return NT_STATUS_ACCESS_DENIED; diff --git a/source/msrpc/msrpcd_process.c b/source/msrpc/msrpcd_process.c index c7edf8e3ccf..e31a3cb5c13 100644 --- a/source/msrpc/msrpcd_process.c +++ b/source/msrpc/msrpcd_process.c @@ -73,7 +73,8 @@ static BOOL receive_message_or_msrpc(int c, prs_struct * ps, struct timeval to; int maxfd; - DEBUG(10,("receive_message_or_msrpc: timeout %d fd %d\n", timeout, c)); + DEBUG(10, + ("receive_message_or_msrpc: timeout %d fd %d\n", timeout, c)); smb_read_error = 0; @@ -104,7 +105,7 @@ static BOOL receive_message_or_msrpc(int c, prs_struct * ps, { /* something is wrong. Maybe the socket is dead? */ smb_read_error = READ_ERROR; - DEBUG(2,("read error on loop-back socket\n")); + DEBUG(2, ("read error on loop-back socket\n")); return False; } @@ -112,7 +113,7 @@ static BOOL receive_message_or_msrpc(int c, prs_struct * ps, if (selrtn == 0) { smb_read_error = READ_TIMEOUT; - DEBUG(2,("timeout on loop-back socket\n")); + DEBUG(2, ("timeout on loop-back socket\n")); return False; } @@ -238,7 +239,7 @@ BOOL get_user_creds(int c, vuser_key * uk) DEBUG(10, ("get_user_creds: first request\n")); - rl = read_data(c, (char*)&buf, sizeof(len)); + rl = read_data(c, (char *)&buf, sizeof(len)); if (rl != sizeof(len)) { @@ -312,7 +313,8 @@ BOOL get_user_creds(int c, vuser_key * uk) status = new_con ? 0x0 : 0x1; - if (write_socket(c, (char*)&status, sizeof(status)) != sizeof(status)) + if (write_socket(c, (char *)&status, sizeof(status)) != + sizeof(status)) { return False; } @@ -458,7 +460,7 @@ void msrpcd_process(msrpc_service_fns * fn, rpcsrv_struct * l, { time_t t; - if (counter > 365 * 3600) /* big number of seconds. */ + if (counter > 365 * 3600) /* big number of seconds. */ { counter = 0; service_load_counter = 0; diff --git a/source/netlogond/srv_netlogon_nt.c b/source/netlogond/srv_netlogon_nt.c index 1264a1d2f95..35dbcbae85f 100644 --- a/source/netlogond/srv_netlogon_nt.c +++ b/source/netlogond/srv_netlogon_nt.c @@ -101,7 +101,8 @@ static uint32 direct_samr_userinfo(const UNISTR2 * uni_user, } else { - status_pwd = _samr_query_userinfo(&usr_pol, level, ctr); + status_pwd = + _samr_query_userinfo(&usr_pol, level, ctr); } } if (status_usr == NT_STATUS_NOPROBLEMO) @@ -986,8 +987,8 @@ uint32 _net_sam_logon(const DOM_SAM_INFO * sam_id, /* interactive login. */ status = net_login_interactive(& - (sam_id->ctr-> - auth.id1), + (sam_id-> + ctr->auth.id1), &dc); (*auth_resp) = 1; break; @@ -997,10 +998,10 @@ uint32 _net_sam_logon(const DOM_SAM_INFO * sam_id, /* network login. lm challenge and 24 byte responses */ status = net_login_network(& - (sam_id->ctr->auth. - id2), acb_info, - &dc, usr_sess_key, -lm_pw8); + (sam_id->ctr-> + auth.id2), + acb_info, &dc, +usr_sess_key, lm_pw8); padding = lm_pw8; enc_user_sess_key = usr_sess_key; (*auth_resp) = 1; diff --git a/source/rpc_client/msrpc_lsarpc.c b/source/rpc_client/msrpc_lsarpc.c index 38cdd219add..6ee9b8ad0d4 100644 --- a/source/rpc_client/msrpc_lsarpc.c +++ b/source/rpc_client/msrpc_lsarpc.c @@ -224,7 +224,7 @@ BOOL msrpc_lsa_create_secret(const char *srv_name, const char *secret_name, /**************************************************************************** put data into secret buffer. ****************************************************************************/ -void secret_store_data(STRING2 * secret, const char* data, int len) +void secret_store_data(STRING2 * secret, const char *data, int len) { ZERO_STRUCTP(secret); @@ -240,7 +240,7 @@ void secret_store_data(STRING2 * secret, const char* data, int len) /**************************************************************************** put data into secret buffer. ****************************************************************************/ -void secret_store_data2(STRING2 * secret, const char* data, int len) +void secret_store_data2(STRING2 * secret, const char *data, int len) { ZERO_STRUCTP(secret); @@ -269,11 +269,12 @@ BOOL msrpc_lsa_set_secret(const char *srv_name, /* lookup domain controller; receive a policy handle */ res = res ? lsa_open_policy(srv_name, - &lsa_pol, True, 0x02000000) : False; + &lsa_pol, True, 0x02000000) : False; /* lookup domain controller; receive a policy handle */ res1 = res ? lsa_open_secret(&lsa_pol, - secret_name, 0x02000000, &pol_sec) : False; + secret_name, 0x02000000, + &pol_sec) : False; res2 = res1 ? (lsa_set_secret(&pol_sec, &secret) == @@ -321,7 +322,7 @@ BOOL msrpc_lsa_query_secret(const char *srv_name, /**************************************************************************** obtains a trust account password ****************************************************************************/ -BOOL secret_get_data(const STRING2 *secret, uchar *data, uint32 *len) +BOOL secret_get_data(const STRING2 * secret, uchar * data, uint32 * len) { (*len) = IVAL(secret->buffer, 0); if (secret->str_str_len != (*len) + 8) @@ -339,7 +340,7 @@ BOOL secret_get_data(const STRING2 *secret, uchar *data, uint32 *len) /**************************************************************************** obtains a trust account password ****************************************************************************/ -BOOL secret_to_nt_owf(uchar trust_passwd[16], const STRING2 *secret) +BOOL secret_to_nt_owf(uchar trust_passwd[16], const STRING2 * secret) { UNISTR2 uni_pwd; uint32 len; @@ -352,7 +353,7 @@ BOOL secret_to_nt_owf(uchar trust_passwd[16], const STRING2 *secret) } for (i = 0; i < len; i++) { - uni_pwd.buffer[i] = SVAL(data, i*2); + uni_pwd.buffer[i] = SVAL(data, i * 2); } uni_pwd.uni_str_len = len / 2; uni_pwd.uni_max_len = len / 2; diff --git a/source/rpc_parse/parse_samr.c b/source/rpc_parse/parse_samr.c index c3a6456fee1..9d42e8013fc 100644 --- a/source/rpc_parse/parse_samr.c +++ b/source/rpc_parse/parse_samr.c @@ -558,7 +558,7 @@ BOOL make_unk_info12(SAM_UNK_INFO_12 * u_12) reads or writes a structure. ********************************************************************/ static BOOL sam_io_unk_info12(char *desc, SAM_UNK_INFO_12 * u_12, - prs_struct * ps, int depth) + prs_struct * ps, int depth) { if (u_12 == NULL) return False; @@ -626,9 +626,9 @@ static BOOL sam_io_unk_info2(char *desc, SAM_UNK_INFO_2 * u_2, prs_debug(ps, depth, desc, "sam_io_unk_info2"); depth++; - prs_uint32("unknown_0", ps, depth, &u_2->unknown_0); /* 0x0000 0000 */ - prs_uint32("unknown_1", ps, depth, &u_2->unknown_1); /* 0x8000 0000 */ - prs_uint32("unknown_2", ps, depth, &u_2->unknown_2); /* 0x0000 0000 */ + prs_uint32("unknown_0", ps, depth, &u_2->unknown_0); /* 0x0000 0000 */ + prs_uint32("unknown_1", ps, depth, &u_2->unknown_1); /* 0x8000 0000 */ + prs_uint32("unknown_2", ps, depth, &u_2->unknown_2); /* 0x0000 0000 */ prs_uint32("ptr_0", ps, depth, &u_2->ptr_0); smb_io_unihdr("hdr_domain", &u_2->hdr_domain, ps, depth); @@ -638,20 +638,21 @@ static BOOL sam_io_unk_info2(char *desc, SAM_UNK_INFO_2 * u_2, pointer is referring to */ - prs_uint32("seq_num ", ps, depth, &u_2->seq_num); /* 0x0000 0099 or 0x1000 0000 */ - prs_uint32("unknown_3 ", ps, depth, &u_2->unknown_3); /* 0x0000 0000 */ + prs_uint32("seq_num ", ps, depth, &u_2->seq_num); /* 0x0000 0099 or 0x1000 0000 */ + prs_uint32("unknown_3 ", ps, depth, &u_2->unknown_3); /* 0x0000 0000 */ - prs_uint32("unknown_4 ", ps, depth, &u_2->unknown_4); /* 0x0000 0001 */ - prs_uint32("unknown_5 ", ps, depth, &u_2->unknown_5); /* 0x0000 0003 */ - prs_uint32("unknown_6 ", ps, depth, &u_2->unknown_6); /* 0x0000 0001 */ + prs_uint32("unknown_4 ", ps, depth, &u_2->unknown_4); /* 0x0000 0001 */ + prs_uint32("unknown_5 ", ps, depth, &u_2->unknown_5); /* 0x0000 0003 */ + prs_uint32("unknown_6 ", ps, depth, &u_2->unknown_6); /* 0x0000 0001 */ prs_uint32("num_domain_usrs ", ps, depth, &u_2->num_domain_usrs); prs_uint32("num_domain_grps", ps, depth, &u_2->num_domain_grps); prs_uint32("num_local_grps", ps, depth, &u_2->num_local_grps); - prs_uint8s(False, "padding", ps, depth, u_2->padding, sizeof(u_2->padding)); + prs_uint8s(False, "padding", ps, depth, u_2->padding, + sizeof(u_2->padding)); smb_io_unistr2("uni_domain", &u_2->uni_domain, u_2->hdr_domain.buffer, - ps, depth); + ps, depth); prs_align(ps); smb_io_unistr2("uni_server", &u_2->uni_server, u_2->hdr_server.buffer, ps, depth); @@ -687,10 +688,11 @@ static BOOL sam_io_unk_info1(char *desc, SAM_UNK_INFO_1 * u_1, prs_debug(ps, depth, desc, "sam_io_unk_info1"); depth++; - prs_uint8s(False, "padding", ps, depth, u_1->padding, sizeof(u_1->padding)); + prs_uint8s(False, "padding", ps, depth, u_1->padding, + sizeof(u_1->padding)); - prs_uint32("unknown_1", ps, depth, &u_1->unknown_1); /* 0x8000 0000 */ - prs_uint32("unknown_2", ps, depth, &u_1->unknown_2); /* 0x0000 0000 */ + prs_uint32("unknown_1", ps, depth, &u_1->unknown_1); /* 0x8000 0000 */ + prs_uint32("unknown_2", ps, depth, &u_1->unknown_2); /* 0x0000 0000 */ prs_align(ps); @@ -749,8 +751,8 @@ BOOL samr_io_r_query_dom_info(char *desc, SAMR_R_QUERY_DOMAIN_INFO * r_u, case 0x0c: { sam_io_unk_info12("unk_inf12", - &r_u->ctr->info.inf12, ps, - depth); + &r_u->ctr->info.inf12, ps, + depth); break; } case 0x07: @@ -1268,7 +1270,8 @@ BOOL samr_io_r_enum_dom_users(char *desc, SAMR_R_ENUM_DOM_USERS * r_u, if (UNMARSHALLING(ps) && (r_u->num_entries2 != 0)) { r_u->sam = g_new(SAM_ENTRY, r_u->num_entries2); - r_u->uni_acct_name = g_new(UNISTR2, r_u->num_entries2); + r_u->uni_acct_name = + g_new(UNISTR2, r_u->num_entries2); } if ((r_u->sam == NULL || r_u->uni_acct_name == NULL) @@ -2016,8 +2019,8 @@ BOOL samr_io_group_info4(char *desc, GROUP_INFO4 * gr4, prs_struct * ps, /******************************************************************* reads or writes a structure. ********************************************************************/ -static BOOL samr_group_info_ctr(char *desc, GROUP_INFO_CTR *ctr, - prs_struct *ps, int depth) +static BOOL samr_group_info_ctr(char *desc, GROUP_INFO_CTR * ctr, + prs_struct * ps, int depth) { if (ctr == NULL) return False; @@ -2598,8 +2601,8 @@ BOOL samr_io_r_query_groupmem(char *desc, SAMR_R_QUERY_GROUPMEM * r_u, if (r_u->num_rids != 0) { r_u->rid = (uint32 *) Realloc(r_u->rid, - sizeof(r_u-> - rid[0]) * + sizeof(r_u->rid + [0]) * r_u->num_rids); if (r_u->rid == NULL) { @@ -2620,11 +2623,10 @@ BOOL samr_io_r_query_groupmem(char *desc, SAMR_R_QUERY_GROUPMEM * r_u, if (r_u->num_attrs != 0) { r_u->attr = (uint32 *) Realloc(r_u->attr, - sizeof(r_u-> - attr[0]) + sizeof + (r_u->attr[0]) * - r_u-> - num_attrs); + r_u->num_attrs); if (r_u->attr == NULL) { samr_free_r_query_groupmem(r_u); @@ -5303,13 +5305,12 @@ BOOL make_sam_user_info23A(SAM_USER_INFO_23 * usr, NTTIME * logon_time, /* all z NTTIME * pass_must_change_time, /* all zeros */ char *user_name, /* NULL */ char *full_name, - char *home_dir, char *dir_drive, char *log_scr, char *prof_path, char *desc, char *wkstas, char *unk_str, char *mung_dial, uint32 user_rid, /* 0x0000 0000 */ - uint32 group_rid, - uint32 acb_info, - uint32 unknown_3, - uint16 logon_divs, - LOGON_HRS * hrs, - uint32 unknown_5, + char *home_dir, char *dir_drive, char *log_scr, + char *prof_path, char *desc, char *wkstas, + char *unk_str, char *mung_dial, uint32 user_rid, /* 0x0000 0000 */ + uint32 group_rid, uint32 acb_info, + uint32 unknown_3, uint16 logon_divs, + LOGON_HRS * hrs, uint32 unknown_5, char newpass[516], uint32 unknown_6) { int len_user_name = user_name != NULL ? strlen(user_name) : 0; @@ -5426,7 +5427,7 @@ static BOOL sam_io_user_info23(char *desc, SAM_USER_INFO_23 * usr, prs_uint32("user_rid ", ps, depth, &(usr->user_rid)); /* User ID */ prs_uint32("group_rid ", ps, depth, &(usr->group_rid)); /* Group ID */ - prs_uint32("acb_info ", ps, depth, &(usr->acb_info)); + prs_uint32("acb_info ", ps, depth, &(usr->acb_info)); prs_uint32("unknown_3 ", ps, depth, &(usr->unknown_3)); prs_uint16("logon_divs ", ps, depth, &(usr->logon_divs)); /* logon divisions per week */ @@ -5747,7 +5748,7 @@ BOOL sam_io_user_info21(char *desc, SAM_USER_INFO_21 * usr, prs_struct * ps, prs_uint32("user_rid ", ps, depth, &(usr->user_rid)); /* User ID */ prs_uint32("group_rid ", ps, depth, &(usr->group_rid)); /* Group ID */ - prs_uint32("acb_info ", ps, depth, &(usr->acb_info)); + prs_uint32("acb_info ", ps, depth, &(usr->acb_info)); prs_uint32("unknown_3 ", ps, depth, &(usr->unknown_3)); prs_uint16("logon_divs ", ps, depth, &(usr->logon_divs)); /* logon divisions per week */ @@ -5824,9 +5825,7 @@ uint32 make_samr_userinfo_ctr_usr21(SAM_USERINFO_CTR * ctr, { ctr->info.id = (SAM_USER_INFO_10 *) Realloc(NULL, sizeof - (*ctr-> - info. - id10)); + (*ctr->info.id10)); if (ctr->info.id == NULL) { return NT_STATUS_NO_MEMORY; @@ -5846,9 +5845,7 @@ uint32 make_samr_userinfo_ctr_usr21(SAM_USERINFO_CTR * ctr, ctr->info.id = (SAM_USER_INFO_11 *) Realloc(NULL, sizeof - (*ctr-> - info. - id11)); + (*ctr->info.id11)); make_sam_user_info11(ctr->info.id11, &expire, "BROOKFIELDS$", /* name */ 0x03ef, /* user rid */ @@ -5862,9 +5859,7 @@ uint32 make_samr_userinfo_ctr_usr21(SAM_USERINFO_CTR * ctr, { ctr->info.id = (SAM_USER_INFO_12 *) Realloc(NULL, sizeof - (*ctr-> - info. - id12)); + (*ctr->info.id12)); if (ctr->info.id == NULL) { return NT_STATUS_NO_MEMORY; @@ -5943,8 +5938,8 @@ BOOL make_samr_userinfo_ctr(SAM_USERINFO_CTR * ctr, const uchar * sess_key, /******************************************************************* reads or writes a structure. ********************************************************************/ -static BOOL samr_io_userinfo_ctr(char *desc, SAM_USERINFO_CTR *ctr, - prs_struct *ps, int depth) +static BOOL samr_io_userinfo_ctr(char *desc, SAM_USERINFO_CTR * ctr, + prs_struct * ps, int depth) { BOOL ret; if (ctr == NULL) @@ -5975,7 +5970,7 @@ static BOOL samr_io_userinfo_ctr(char *desc, SAM_USERINFO_CTR *ctr, ("samr_io_userinfo_ctr: info pointer not initialised\n")); return False; } - ret = sam_io_user_info10("", ctr->info.id10, ps, + ret = sam_io_user_info10("", ctr->info.id10, ps, depth); break; } @@ -6084,7 +6079,8 @@ frees a structure. ********************************************************************/ void free_samr_userinfo_ctr(SAM_USERINFO_CTR * ctr) { - if (ctr == NULL) return; + if (ctr == NULL) + return; safe_free(ctr->info.id); ctr->info.id = NULL; } @@ -6213,7 +6209,8 @@ frees a structure. ********************************************************************/ void free_samr_q_set_userinfo(SAMR_Q_SET_USERINFO * q_u) { - if (q_u == NULL) return; + if (q_u == NULL) + return; free_samr_userinfo_ctr(q_u->ctr); } diff --git a/source/rpcclient/cmd_netlogon.c b/source/rpcclient/cmd_netlogon.c index 49eaa7509db..d4cc160ec47 100644 --- a/source/rpcclient/cmd_netlogon.c +++ b/source/rpcclient/cmd_netlogon.c @@ -48,7 +48,7 @@ void cmd_netlogon_pwset(struct client_info *info, int argc, char *argv[]) fstring name; fstring sid; DOM_SID sid1; - uint32 user_rid; + uint32 user_rid; int opt; char *password = NULL; pstring upwb; @@ -110,17 +110,20 @@ void cmd_netlogon_pwset(struct client_info *info, int argc, char *argv[]) DEBUG(5, ("do_nt_login_test: username %s from: %s\n", nt_user_name, info->myhostname)); - res = res ? msrpc_lsa_query_trust_passwd(wks_name, "$MACHINE.ACC", - old_trust_passwd, NULL) : False; - safe_strcpy(acct_name, argv[0], sizeof(acct_name)); - len = strlen(acct_name)-1; + len = strlen(acct_name) - 1; if (acct_name[len] == '$') { safe_strcpy(name, argv[0], sizeof(name)); name[len] = 0; } + res = res ? cli_nt_setup_creds(srv_name, domain, info->myhostname, + trust_acct, + old_trust_passwd, + SEC_CHAN_WKSTA, + &validation_level) == 0x0 : False; + /* * generate new random password. unicode string is stored * in secret $MACHINE.ACC; nt owf is sent in net_srv_pwset. @@ -128,7 +131,7 @@ void cmd_netlogon_pwset(struct client_info *info, int argc, char *argv[]) upw.uni_str_len = 0xc; upw.uni_max_len = 0xc; - password = (char*)upw.buffer; + password = (char *)upw.buffer; plen = upw.uni_str_len * 2; generate_random_buffer(password, plen, True); @@ -141,17 +144,17 @@ void cmd_netlogon_pwset(struct client_info *info, int argc, char *argv[]) * local copy-of trust account out-of-sync with the * remote one, and you're stuffed! */ - res = lsa_open_policy( wks_name, &lsa_pol, True, 0x02000000); + res = lsa_open_policy(wks_name, &lsa_pol, True, 0x02000000); if (!res) { report(out_hnd, "Connection to %s FAILED\n", wks_name); report(out_hnd, "(Do a \"use \\\\%s -U localadmin\")\n", - wks_name); + wks_name); return; } - res1 = lsa_open_secret( &lsa_pol, "$MACHINE.ACC", 0x020003, &pol_sec); + res1 = lsa_open_secret(&lsa_pol, "$MACHINE.ACC", 0x020003, &pol_sec); if (!res1) { @@ -165,17 +168,19 @@ void cmd_netlogon_pwset(struct client_info *info, int argc, char *argv[]) { lsa_close(&lsa_pol); lsa_close(&pol_sec); - report(out_hnd, "Query local Trust Account password: Failed\n"); + report(out_hnd, + "Query local Trust Account password: Failed\n"); return; } - + if (net_srv_pwset(srv_name, &sid1, - acct_name, , password, plen, - &user_rid) != NT_STATUS_NOPROBLEMO) + acct_name,, password, plen, + &user_rid) != NT_STATUS_NOPROBLEMO) { lsa_close(&lsa_pol); lsa_close(&pol_sec); - report(out_hnd, "Set remote Trust Account password: Failed\n"); + report(out_hnd, + "Set remote Trust Account password: Failed\n"); return; } @@ -203,12 +208,6 @@ void cmd_netlogon_pwset(struct client_info *info, int argc, char *argv[]) memset(&upw, 0, sizeof(upw)); memset(ntpw, 0, sizeof(ntpw)); -} - res = res ? cli_nt_setup_creds(srv_name, domain, info->myhostname, - trust_acct, - old_trust_passwd, - SEC_CHAN_WKSTA, - &validation_level) == 0x0 : False; report(out_hnd, "cmd_nt_login: login (%s) test succeeded: %s\n", diff --git a/source/rpcclient/cmd_samr.c b/source/rpcclient/cmd_samr.c index 41f8717cfcb..9d31b21306a 100644 --- a/source/rpcclient/cmd_samr.c +++ b/source/rpcclient/cmd_samr.c @@ -38,99 +38,102 @@ extern int DEBUGLEVEL; extern struct user_creds *usr_creds; -extern FILE* out_hnd; +extern FILE *out_hnd; static void sam_display_domain(const char *domain) { report(out_hnd, "Domain Name: %s\n", domain); } -static void sam_display_dom_info(const char* domain, const DOM_SID *sid, - uint32 switch_value, - SAM_UNK_CTR *ctr) +static void sam_display_dom_info(const char *domain, const DOM_SID * sid, + uint32 switch_value, SAM_UNK_CTR * ctr) { fstring sidstr; sid_to_string(sidstr, sid); report(out_hnd, "Domain Name:\t%s\tSID:\t%s\n", domain, sidstr); - display_sam_unk_ctr(out_hnd, ACTION_HEADER , switch_value, ctr); + display_sam_unk_ctr(out_hnd, ACTION_HEADER, switch_value, ctr); display_sam_unk_ctr(out_hnd, ACTION_ENUMERATE, switch_value, ctr); - display_sam_unk_ctr(out_hnd, ACTION_FOOTER , switch_value, ctr); + display_sam_unk_ctr(out_hnd, ACTION_FOOTER, switch_value, ctr); } -static void sam_display_alias_info(const char *domain, const DOM_SID *sid, - uint32 alias_rid, - ALIAS_INFO_CTR *const ctr) +static void sam_display_alias_info(const char *domain, const DOM_SID * sid, + uint32 alias_rid, + ALIAS_INFO_CTR * const ctr) { - display_alias_info_ctr(out_hnd, ACTION_HEADER , ctr); + display_alias_info_ctr(out_hnd, ACTION_HEADER, ctr); display_alias_info_ctr(out_hnd, ACTION_ENUMERATE, ctr); - display_alias_info_ctr(out_hnd, ACTION_FOOTER , ctr); + display_alias_info_ctr(out_hnd, ACTION_FOOTER, ctr); } -static void sam_display_alias(const char *domain, const DOM_SID *sid, - uint32 alias_rid, const char *alias_name) +static void sam_display_alias(const char *domain, const DOM_SID * sid, + uint32 alias_rid, const char *alias_name) { report(out_hnd, "Alias RID: %8x Alias Name: %s\n", - alias_rid, alias_name); + alias_rid, alias_name); } -static void sam_display_alias_members(const char *domain, const DOM_SID *sid, - uint32 alias_rid, const char *alias_name, - uint32 num_names, - DOM_SID *const *const sids, - char *const *const name, - uint32 *const type) +static void sam_display_alias_members(const char *domain, const DOM_SID * sid, + uint32 alias_rid, + const char *alias_name, + uint32 num_names, + DOM_SID * const *const sids, + char *const *const name, + uint32 * const type) { - display_alias_members(out_hnd, ACTION_HEADER , num_names, name, type); - display_alias_members(out_hnd, ACTION_ENUMERATE, num_names, name, type); - display_alias_members(out_hnd, ACTION_FOOTER , num_names, name, type); + display_alias_members(out_hnd, ACTION_HEADER, num_names, name, type); + display_alias_members(out_hnd, ACTION_ENUMERATE, num_names, name, + type); + display_alias_members(out_hnd, ACTION_FOOTER, num_names, name, type); } -static void sam_display_group_info(const char *domain, const DOM_SID *sid, - uint32 group_rid, - GROUP_INFO_CTR *const ctr) +static void sam_display_group_info(const char *domain, const DOM_SID * sid, + uint32 group_rid, + GROUP_INFO_CTR * const ctr) { - display_group_info_ctr(out_hnd, ACTION_HEADER , ctr); + display_group_info_ctr(out_hnd, ACTION_HEADER, ctr); display_group_info_ctr(out_hnd, ACTION_ENUMERATE, ctr); - display_group_info_ctr(out_hnd, ACTION_FOOTER , ctr); + display_group_info_ctr(out_hnd, ACTION_FOOTER, ctr); } -static void sam_display_group(const char *domain, const DOM_SID *sid, - uint32 group_rid, const char *group_name) +static void sam_display_group(const char *domain, const DOM_SID * sid, + uint32 group_rid, const char *group_name) { report(out_hnd, "Group RID: %8x Group Name: %s\n", - group_rid, group_name); + group_rid, group_name); } -static void sam_display_group_members(const char *domain, const DOM_SID *sid, - uint32 group_rid, const char *group_name, - uint32 num_names, - const uint32 *rid_mem, - char *const *const name, - uint32 *const type) +static void sam_display_group_members(const char *domain, const DOM_SID * sid, + uint32 group_rid, + const char *group_name, + uint32 num_names, + const uint32 * rid_mem, + char *const *const name, + uint32 * const type) { - display_group_members(out_hnd, ACTION_HEADER , num_names, name, type); - display_group_members(out_hnd, ACTION_ENUMERATE, num_names, name, type); - display_group_members(out_hnd, ACTION_FOOTER , num_names, name, type); + display_group_members(out_hnd, ACTION_HEADER, num_names, name, type); + display_group_members(out_hnd, ACTION_ENUMERATE, num_names, name, + type); + display_group_members(out_hnd, ACTION_FOOTER, num_names, name, type); } -static void sam_display_user_info(const char *domain, const DOM_SID *sid, - uint32 user_rid, - SAM_USERINFO_CTR *const ctr) +static void sam_display_user_info(const char *domain, const DOM_SID * sid, + uint32 user_rid, + SAM_USERINFO_CTR * const ctr) { if (ctr->switch_value == 21) { SAM_USER_INFO_21 *const usr = ctr->info.id21; - display_sam_user_info_21(out_hnd, ACTION_HEADER , usr); + display_sam_user_info_21(out_hnd, ACTION_HEADER, usr); display_sam_user_info_21(out_hnd, ACTION_ENUMERATE, usr); - display_sam_user_info_21(out_hnd, ACTION_FOOTER , usr); + display_sam_user_info_21(out_hnd, ACTION_FOOTER, usr); } } -static void sam_display_user(const char *domain, const DOM_SID *sid, - uint32 user_rid, const char *user_name) +static void sam_display_user(const char *domain, const DOM_SID * sid, + uint32 user_rid, const char *user_name) { report(out_hnd, "User RID: %8x User Name: %s\n", - user_rid, user_name); + user_rid, user_name); } @@ -157,16 +160,18 @@ void cmd_sam_ntchange_pwd(struct client_info *info, int argc, char *argv[]) struct pwd_info old_pwd; safe_strcpy(acct_name, argv[1], sizeof(acct_name)); pwd_read(&old_pwd, "Old Password:", True); - pwd_get_lm_nt_16(&old_pwd, lm_oldhash, nt_oldhash ); + pwd_get_lm_nt_16(&old_pwd, lm_oldhash, nt_oldhash); } else { - safe_strcpy(acct_name, usr_creds->ntc.user_name, sizeof(acct_name)); - pwd_get_lm_nt_16(&(usr_creds->ntc.pwd), lm_oldhash, nt_oldhash ); + safe_strcpy(acct_name, usr_creds->ntc.user_name, + sizeof(acct_name)); + pwd_get_lm_nt_16(&(usr_creds->ntc.pwd), lm_oldhash, + nt_oldhash); } - new_passwd = (char*)getpass("New Password: "); - new_passwd2 = (char*)getpass("retype: "); + new_passwd = (char *)getpass("New Password: "); + new_passwd2 = (char *)getpass("retype: "); if ((new_passwd != NULL && new_passwd2 != NULL && !strequal(new_passwd, new_passwd2)) || @@ -177,9 +182,8 @@ void cmd_sam_ntchange_pwd(struct client_info *info, int argc, char *argv[]) } /* establish a connection. */ - if (msrpc_sam_ntchange_pwd( srv_name, NULL, acct_name, - lm_oldhash, nt_oldhash, - new_passwd)) + if (msrpc_sam_ntchange_pwd(srv_name, NULL, acct_name, + lm_oldhash, nt_oldhash, new_passwd)) { report(out_hnd, "NT Password changed OK\n"); } @@ -211,14 +215,13 @@ void cmd_sam_test(struct client_info *info, int argc, char *argv[]) report(out_hnd, "SAM Encryption Test\n"); usr_creds->ntc.ntlmssp_flags = NTLMSSP_NEGOTIATE_UNICODE | - NTLMSSP_NEGOTIATE_OEM | - NTLMSSP_NEGOTIATE_SIGN | - NTLMSSP_NEGOTIATE_SEAL | - NTLMSSP_NEGOTIATE_LM_KEY | - NTLMSSP_NEGOTIATE_NTLM | - NTLMSSP_NEGOTIATE_ALWAYS_SIGN | - NTLMSSP_NEGOTIATE_00001000 | - NTLMSSP_NEGOTIATE_00002000; + NTLMSSP_NEGOTIATE_OEM | + NTLMSSP_NEGOTIATE_SIGN | + NTLMSSP_NEGOTIATE_SEAL | + NTLMSSP_NEGOTIATE_LM_KEY | + NTLMSSP_NEGOTIATE_NTLM | + NTLMSSP_NEGOTIATE_ALWAYS_SIGN | + NTLMSSP_NEGOTIATE_00001000 | NTLMSSP_NEGOTIATE_00002000; /* open SAMR session. */ res = res ? cli_connection_init(srv_name, PIPE_SAMR, &con) : False; @@ -228,11 +231,11 @@ void cmd_sam_test(struct client_info *info, int argc, char *argv[]) if (res) { - DEBUG(5,("cmd_sam_test: succeeded\n")); + DEBUG(5, ("cmd_sam_test: succeeded\n")); } else { - DEBUG(5,("cmd_sam_test: failed\n")); + DEBUG(5, ("cmd_sam_test: failed\n")); } } @@ -264,23 +267,25 @@ void cmd_sam_lookup_domain(struct client_info *info, int argc, char *argv[]) report(out_hnd, "Lookup Domain %s in SAM Server\n", domain); /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res = res ? samr_query_lookup_domain( &sam_pol, domain, &dom_sid) : False; + res = + res ? samr_query_lookup_domain(&sam_pol, domain, + &dom_sid) : False; res = res ? samr_close(&sam_pol) : False; if (res) { - DEBUG(5,("cmd_sam_lookup_domain: succeeded\n")); + DEBUG(5, ("cmd_sam_lookup_domain: succeeded\n")); sid_to_string(str_sid, &dom_sid); report(out_hnd, "Domain:\t%s\tSID:\t%s\n", domain, str_sid); } else { - DEBUG(5,("cmd_sam_lookup_domain: failed\n")); + DEBUG(5, ("cmd_sam_lookup_domain: failed\n")); report(out_hnd, "Lookup Domain: FAILED\n"); } } @@ -290,14 +295,13 @@ Lookup names in SAM server. ****************************************************************************/ static void fill_domain_sid(const char *srv_name, const char *new_domain, char *domain, - DOM_SID *sid) + DOM_SID * sid) { uint32 ret; DOM_SID new_sid; fstring temp; - ret = lookup_sam_domainname(srv_name, new_domain, - &new_sid); + ret = lookup_sam_domainname(srv_name, new_domain, &new_sid); if (ret != 0x0) { @@ -323,7 +327,7 @@ void cmd_sam_lookup_names(struct client_info *info, int argc, char *argv[]) fstring srv_name; fstring domain; DOM_SID sid_dom; - uint32 ace_perms = 0x02000000; /* absolutely no idea. */ + uint32 ace_perms = 0x02000000; /* absolutely no idea. */ BOOL res = True, res1 = True; POLICY_HND pol_sam; POLICY_HND pol_dom; @@ -342,7 +346,8 @@ void cmd_sam_lookup_names(struct client_info *info, int argc, char *argv[]) if (argc < 2) { - report(out_hnd, "samlookupnames [-d <domain>] <name> [<name> ...]\n"); + report(out_hnd, + "samlookupnames [-d <domain>] <name> [<name> ...]\n"); return; } @@ -361,9 +366,11 @@ void cmd_sam_lookup_names(struct client_info *info, int argc, char *argv[]) if (sid_dom.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid_dom) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid_dom) != + 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } @@ -374,11 +381,12 @@ void cmd_sam_lookup_names(struct client_info *info, int argc, char *argv[]) argv += optind; num_names = argc; - names = (char **) argv; + names = (char **)argv; if (num_names <= 0) { - report(out_hnd, "samlookupnames [-d <domain>] <name> [<name> ...]\n"); + report(out_hnd, + "samlookupnames [-d <domain>] <name> [<name> ...]\n"); return; } @@ -389,20 +397,21 @@ void cmd_sam_lookup_names(struct client_info *info, int argc, char *argv[]) res = res ? samr_open_domain(&pol_sam, ace_perms, &sid_dom, &pol_dom) : False; - res1 = res ? samr_query_lookup_names( &pol_dom, 0x000003e8, - num_names, names, - &num_rids, &rids, &types) : False; + res1 = res ? samr_query_lookup_names(&pol_dom, 0x000003e8, + num_names, names, + &num_rids, &rids, + &types) : False; res = res ? samr_close(&pol_dom) : False; res = res ? samr_close(&pol_sam) : False; if (res1) { - DEBUG(5,("cmd_sam_lookup_names: query succeeded\n")); + DEBUG(5, ("cmd_sam_lookup_names: query succeeded\n")); } else { - DEBUG(5,("cmd_sam_lookup_names: query failed\n")); + DEBUG(5, ("cmd_sam_lookup_names: query failed\n")); } if (res1) @@ -428,7 +437,7 @@ void cmd_sam_lookup_rids(struct client_info *info, int argc, char *argv[]) fstring srv_name; fstring domain; DOM_SID sid_dom; - uint32 ace_perms = 0x02000000; /* absolutely no idea. */ + uint32 ace_perms = 0x02000000; /* absolutely no idea. */ BOOL res = True, res1 = True; POLICY_HND pol_sam; POLICY_HND pol_dom; @@ -447,7 +456,8 @@ void cmd_sam_lookup_rids(struct client_info *info, int argc, char *argv[]) if (argc < 2) { - report(out_hnd, "samlookupnames [-d <domain>] <name> [<name> ...]\n"); + report(out_hnd, + "samlookupnames [-d <domain>] <name> [<name> ...]\n"); return; } @@ -466,9 +476,11 @@ void cmd_sam_lookup_rids(struct client_info *info, int argc, char *argv[]) if (sid_dom.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid_dom) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid_dom) != + 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } @@ -480,7 +492,8 @@ void cmd_sam_lookup_rids(struct client_info *info, int argc, char *argv[]) if (argc <= 0) { - report(out_hnd, "samlookuprids [-d <domain>] <rid> [<rid> ...]\n"); + report(out_hnd, + "samlookuprids [-d <domain>] <rid> [<rid> ...]\n"); return; } @@ -488,7 +501,7 @@ void cmd_sam_lookup_rids(struct client_info *info, int argc, char *argv[]) while (num_rids < argc) { - rids = Realloc(rids, sizeof(rids[0]) * (num_rids+1)); + rids = Realloc(rids, sizeof(rids[0]) * (num_rids + 1)); if (rids == NULL) { return; @@ -504,20 +517,21 @@ void cmd_sam_lookup_rids(struct client_info *info, int argc, char *argv[]) res = res ? samr_open_domain(&pol_sam, ace_perms, &sid_dom, &pol_dom) : False; - res1 = res ? samr_query_lookup_rids( &pol_dom, 0x000003e8, - num_rids, rids, - &num_names, &names, &types) : False; + res1 = res ? samr_query_lookup_rids(&pol_dom, 0x000003e8, + num_rids, rids, + &num_names, &names, + &types) : False; res = res ? samr_close(&pol_dom) : False; res = res ? samr_close(&pol_sam) : False; if (res1) { - DEBUG(5,("cmd_sam_lookup_rids: query succeeded\n")); + DEBUG(5, ("cmd_sam_lookup_rids: query succeeded\n")); } else { - DEBUG(5,("cmd_sam_lookup_rids: query failed\n")); + DEBUG(5, ("cmd_sam_lookup_rids: query failed\n")); } if (res1) @@ -533,7 +547,7 @@ void cmd_sam_lookup_rids(struct client_info *info, int argc, char *argv[]) safe_free(rids); safe_free(types); - free_char_array(num_names, names); + free_char_array(num_names, names); } /**************************************************************************** @@ -549,8 +563,8 @@ void cmd_sam_del_aliasmem(struct client_info *info, int argc, char *argv[]) BOOL res = True; BOOL res1 = True; BOOL res2 = True; - uint32 ace_perms = 0x02000000; /* absolutely no idea. */ - DOM_SID member_sid; + uint32 ace_perms = 0x02000000; /* absolutely no idea. */ + DOM_SID member_sid; uint32 alias_rid; POLICY_HND sam_pol; POLICY_HND pol_dom; @@ -565,16 +579,19 @@ void cmd_sam_del_aliasmem(struct client_info *info, int argc, char *argv[]) if (sid1.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != + 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } if (argc < 2) { - report(out_hnd, "delaliasmem: <alias rid> [member sid1] [member sid2] ...\n"); + report(out_hnd, + "delaliasmem: <alias rid> [member sid1] [member sid2] ...\n"); return; } @@ -586,16 +603,16 @@ void cmd_sam_del_aliasmem(struct client_info *info, int argc, char *argv[]) report(out_hnd, "SAM Domain Alias Member\n"); /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, - &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res = res ? samr_open_domain( &sam_pol, ace_perms, &sid1, - &pol_dom) : False; + res = res ? samr_open_domain(&sam_pol, ace_perms, &sid1, + &pol_dom) : False; /* connect to the domain */ - res1 = res ? samr_open_alias( &pol_dom, - 0x000f001f, alias_rid, &alias_pol) : False; + res1 = res ? samr_open_alias(&pol_dom, + 0x000f001f, alias_rid, + &alias_pol) : False; while (argc > 0 && res2 && res1) { @@ -603,26 +620,29 @@ void cmd_sam_del_aliasmem(struct client_info *info, int argc, char *argv[]) argv++; /* get a sid, delete a member from the alias */ res2 = res2 ? string_to_sid(&member_sid, argv[0]) : False; - res2 = res2 ? samr_del_aliasmem(&alias_pol, &member_sid) : False; + res2 = + res2 ? samr_del_aliasmem(&alias_pol, + &member_sid) : False; if (res2) { - report(out_hnd, "SID deleted from Alias 0x%x: %s\n", alias_rid, argv[0]); + report(out_hnd, "SID deleted from Alias 0x%x: %s\n", + alias_rid, argv[0]); } } res1 = res1 ? samr_close(&alias_pol) : False; - res = res ? samr_close(&pol_dom) : False; - res = res ? samr_close(&sam_pol) : False; + res = res ? samr_close(&pol_dom) : False; + res = res ? samr_close(&sam_pol) : False; if (res && res1 && res2) { - DEBUG(5,("cmd_sam_del_aliasmem: succeeded\n")); + DEBUG(5, ("cmd_sam_del_aliasmem: succeeded\n")); report(out_hnd, "Delete Domain Alias Member: OK\n"); } else { - DEBUG(5,("cmd_sam_del_aliasmem: failed\n")); + DEBUG(5, ("cmd_sam_del_aliasmem: failed\n")); report(out_hnd, "Delete Domain Alias Member: FAILED\n"); } } @@ -630,7 +650,8 @@ void cmd_sam_del_aliasmem(struct client_info *info, int argc, char *argv[]) /**************************************************************************** SAM delete alias. ****************************************************************************/ -void cmd_sam_delete_dom_alias(struct client_info *info, int argc, char *argv[]) +void cmd_sam_delete_dom_alias(struct client_info *info, int argc, + char *argv[]) { fstring srv_name; fstring domain; @@ -641,7 +662,7 @@ void cmd_sam_delete_dom_alias(struct client_info *info, int argc, char *argv[]) BOOL res = True; BOOL res1 = True; BOOL res2 = True; - uint32 ace_perms = 0x02000000; /* absolutely no idea. */ + uint32 ace_perms = 0x02000000; /* absolutely no idea. */ uint32 alias_rid = 0; char *names[1]; uint32 *rids; @@ -660,9 +681,11 @@ void cmd_sam_delete_dom_alias(struct client_info *info, int argc, char *argv[]) if (sid1.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != + 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } @@ -678,18 +701,18 @@ void cmd_sam_delete_dom_alias(struct client_info *info, int argc, char *argv[]) report(out_hnd, "SAM Delete Domain Alias\n"); /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, - &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res = res ? samr_open_domain( &sam_pol, ace_perms, &sid1, - &pol_dom) : False; + res = res ? samr_open_domain(&sam_pol, ace_perms, &sid1, + &pol_dom) : False; names[0] = name; - res1 = res ? samr_query_lookup_names( &pol_dom, 0x000003e8, - 1, names, - &num_rids, &rids, &types) : False; + res1 = res ? samr_query_lookup_names(&pol_dom, 0x000003e8, + 1, names, + &num_rids, &rids, + &types) : False; if (res1 && num_rids == 1 && rids) { @@ -705,23 +728,24 @@ void cmd_sam_delete_dom_alias(struct client_info *info, int argc, char *argv[]) } /* connect to the domain */ - res1 = res1 ? samr_open_alias( &pol_dom, - 0x00f001f, alias_rid, &alias_pol) : False; + res1 = res1 ? samr_open_alias(&pol_dom, + 0x00f001f, alias_rid, + &alias_pol) : False; res2 = res1 ? samr_delete_dom_alias(&alias_pol) : False; res1 = res1 ? samr_close(&alias_pol) : False; - res = res ? samr_close(&pol_dom) : False; - res = res ? samr_close(&sam_pol) : False; + res = res ? samr_close(&pol_dom) : False; + res = res ? samr_close(&sam_pol) : False; if (res && res1 && res2) { - DEBUG(5,("cmd_sam_delete_dom_alias: succeeded\n")); + DEBUG(5, ("cmd_sam_delete_dom_alias: succeeded\n")); report(out_hnd, "Delete Domain Alias: OK\n"); } else { - DEBUG(5,("cmd_sam_delete_dom_alias: failed\n")); + DEBUG(5, ("cmd_sam_delete_dom_alias: failed\n")); report(out_hnd, "Delete Domain Alias: FAILED\n"); } } @@ -742,11 +766,11 @@ void cmd_sam_add_aliasmem(struct client_info *info, int argc, char *argv[]) BOOL res2 = True; BOOL res3 = True; BOOL res4 = True; - uint32 ace_perms = 0x02000000; /* absolutely no idea. */ + uint32 ace_perms = 0x02000000; /* absolutely no idea. */ uint32 alias_rid; char **names = NULL; int num_names = 0; - DOM_SID *sids = NULL; + DOM_SID *sids = NULL; int num_sids = 0; int i; POLICY_HND sam_pol; @@ -763,31 +787,34 @@ void cmd_sam_add_aliasmem(struct client_info *info, int argc, char *argv[]) if (sid1.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != + 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } if (argc < 2) { - report(out_hnd, "addaliasmem <group name> [member name1] [member name2] ...\n"); + report(out_hnd, + "addaliasmem <group name> [member name1] [member name2] ...\n"); return; } - - num_names = argc+1; - names = argv+1; + + num_names = argc + 1; + names = argv + 1; report(out_hnd, "SAM Domain Alias Member\n"); /* lookup domain controller; receive a policy handle */ res3 = res3 ? lsa_open_policy(srv_name, - &lsa_pol, True, 0x02000000) : False; + &lsa_pol, True, 0x02000000) : False; /* send lsa lookup sids call */ res4 = res3 ? lsa_lookup_names(&lsa_pol, - num_names, names, + num_names, names, &sids, NULL, &num_sids) : False; res3 = res3 ? lsa_close(&lsa_pol) : False; @@ -809,22 +836,22 @@ void cmd_sam_add_aliasmem(struct client_info *info, int argc, char *argv[]) sid_copy(&sid1, &sid_1_5_20); } else if (!sid_equal(&sids[0], &sid1)) - { + { res4 = False; } } /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, - &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res = res ? samr_open_domain( &sam_pol, ace_perms, &sid1, - &pol_dom) : False; + res = res ? samr_open_domain(&sam_pol, ace_perms, &sid1, + &pol_dom) : False; /* connect to the domain */ - res1 = res ? samr_open_alias( &pol_dom, - 0x000f001f, alias_rid, &alias_pol) : False; + res1 = res ? samr_open_alias(&pol_dom, + 0x000f001f, alias_rid, + &alias_pol) : False; for (i = 1; i < num_sids && res2 && res1; i++) { @@ -834,29 +861,30 @@ void cmd_sam_add_aliasmem(struct client_info *info, int argc, char *argv[]) if (res2) { sid_to_string(tmp, &sids[i]); - report(out_hnd, "SID added to Alias 0x%x: %s\n", alias_rid, tmp); + report(out_hnd, "SID added to Alias 0x%x: %s\n", + alias_rid, tmp); } } res1 = res1 ? samr_close(&alias_pol) : False; - res = res ? samr_close(&pol_dom) : False; - res = res ? samr_close(&sam_pol) : False; + res = res ? samr_close(&pol_dom) : False; + res = res ? samr_close(&sam_pol) : False; if (sids != NULL) { free(sids); } - + free_char_array(num_names, names); if (res && res1 && res2) { - DEBUG(5,("cmd_sam_add_aliasmem: succeeded\n")); + DEBUG(5, ("cmd_sam_add_aliasmem: succeeded\n")); report(out_hnd, "Add Domain Alias Member: OK\n"); } else { - DEBUG(5,("cmd_sam_add_aliasmem: failed\n")); + DEBUG(5, ("cmd_sam_add_aliasmem: failed\n")); report(out_hnd, "Add Domain Alias Member: FAILED\n"); } } @@ -866,7 +894,8 @@ void cmd_sam_add_aliasmem(struct client_info *info, int argc, char *argv[]) /**************************************************************************** SAM create domain user. ****************************************************************************/ -void cmd_sam_create_dom_trusting(struct client_info *info, int argc, char *argv[]) +void cmd_sam_create_dom_trusting(struct client_info *info, int argc, + char *argv[]) { fstring local_domain; fstring local_pdc; @@ -877,7 +906,7 @@ void cmd_sam_create_dom_trusting(struct client_info *info, int argc, char *argv[ fstring sid; DOM_SID sid1; - uint32 user_rid; + uint32 user_rid; fstrcpy(srv_name, "\\\\"); fstrcat(srv_name, info->dest_host); @@ -889,16 +918,19 @@ void cmd_sam_create_dom_trusting(struct client_info *info, int argc, char *argv[ if (sid1.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != + 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } if (argc < 3) { - report(out_hnd, "createtrusting: <Domain Name> <PDC Name> [password]\n"); + report(out_hnd, + "createtrusting: <Domain Name> <PDC Name> [password]\n"); return; } @@ -917,26 +949,26 @@ void cmd_sam_create_dom_trusting(struct client_info *info, int argc, char *argv[ if (argc > 0) { - safe_strcpy(password, argv[0], sizeof(password)-1); + safe_strcpy(password, argv[0], sizeof(password) - 1); } else { fstring pass_str; char *pass; - slprintf(pass_str, sizeof(pass_str)-1, "Enter %s's Password:", - user_name); - pass = (char*)getpass(pass_str); + slprintf(pass_str, sizeof(pass_str) - 1, + "Enter %s's Password:", user_name); + pass = (char *)getpass(pass_str); if (pass != NULL) { - safe_strcpy(password, pass, sizeof(password)-1); + safe_strcpy(password, pass, sizeof(password) - 1); set_passwd = True; } } report(out_hnd, "SAM Create Domain Trusting Account\n"); if (msrpc_sam_create_dom_user(srv_name, - acct_name, ACB_WSTRUST, &user_rid)) + acct_name, ACB_WSTRUST, &user_rid)) { report(out_hnd, "Create Domain User: OK\n"); } @@ -958,7 +990,7 @@ void cmd_sam_create_dom_user(struct client_info *info, int argc, char *argv[]) fstring name; fstring sid; DOM_SID sid1; - uint32 user_rid; + uint32 user_rid; uint16 acb_info = ACB_NORMAL; BOOL join_domain = False; fstring join_dom_name; @@ -985,16 +1017,19 @@ void cmd_sam_create_dom_user(struct client_info *info, int argc, char *argv[]) if (sid1.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != + 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } if (argc < 2) { - report(out_hnd, "createuser: <acct name> [-i] [-s] [-j] domain_name [-p password]\n"); + report(out_hnd, + "createuser: <acct name> [-i] [-s] [-j] domain_name [-p password]\n"); return; } @@ -1002,7 +1037,7 @@ void cmd_sam_create_dom_user(struct client_info *info, int argc, char *argv[]) argv++; safe_strcpy(acct_name, argv[0], sizeof(acct_name)); - len = strlen(acct_name)-1; + len = strlen(acct_name) - 1; if (acct_name[len] == '$') { safe_strcpy(name, argv[0], sizeof(name)); @@ -1010,7 +1045,7 @@ void cmd_sam_create_dom_user(struct client_info *info, int argc, char *argv[]) acb_info = ACB_WSTRUST; } - while ((opt = getopt(argc, argv,"isj:p:w:")) != EOF) + while ((opt = getopt(argc, argv, "isj:p:w:")) != EOF) { switch (opt) { @@ -1033,9 +1068,9 @@ void cmd_sam_create_dom_user(struct client_info *info, int argc, char *argv[]) case 'p': { fstring pwd; - safe_strcpy(pwd, optarg, sizeof(pwd)-1); + safe_strcpy(pwd, optarg, sizeof(pwd) - 1); make_unistr2(&upw, pwd, strlen(pwd)); - ascii_to_unibuf(upwb, pwd, strlen(pwd)*2); + ascii_to_unibuf(upwb, pwd, strlen(pwd) * 2); password = upwb; plen = upw.uni_str_len * 2; memset(pwd, 0, sizeof(pwd)); @@ -1069,8 +1104,8 @@ void cmd_sam_create_dom_user(struct client_info *info, int argc, char *argv[]) * local-loopback. */ - DEBUG(10,("create_dom_user: myhostname: %s server: %s\n", - info->myhostname, name)); + DEBUG(10, ("create_dom_user: myhostname: %s server: %s\n", + info->myhostname, name)); fstrcpy(wks_name, "\\\\"); if (strequal(srv_name, "\\\\.") && strequal(name, info->myhostname)) @@ -1091,8 +1126,9 @@ void cmd_sam_create_dom_user(struct client_info *info, int argc, char *argv[]) } report(out_hnd, "Domain: %s Name: %s ACB: %s\n", - domain, acct_name, - pwdb_encode_acct_ctrl(acb_info, NEW_PW_FORMAT_SPACE_PADDED_LEN)); + domain, acct_name, + pwdb_encode_acct_ctrl(acb_info, + NEW_PW_FORMAT_SPACE_PADDED_LEN)); if (acb_info == ACB_WSTRUST || acb_info == ACB_SVRTRUST) { @@ -1103,7 +1139,8 @@ void cmd_sam_create_dom_user(struct client_info *info, int argc, char *argv[]) if (password != NULL) { - report(out_hnd,("Workstation and Server Trust Accounts are randomly auto-generated\n")); + report(out_hnd, + ("Workstation and Server Trust Accounts are randomly auto-generated\n")); memset(&upw, 0, sizeof(upw)); return; } @@ -1114,16 +1151,16 @@ void cmd_sam_create_dom_user(struct client_info *info, int argc, char *argv[]) upw.uni_str_len = 0x78; upw.uni_max_len = 0x78; generate_random_buffer(rnd_data, sizeof(rnd_data), True); - for (j = 0, i = 0; i < 0x78 && j < sizeof(rnd_data); j++,i++) + for (j = 0, i = 0; i < 0x78 && j < sizeof(rnd_data); j++, i++) { for (; j < sizeof(rnd_data) && rnd_data[j] == 0; j++) { } - + upw.buffer[i] = rnd_data[j]; } #endif - password = (char*)upw.buffer; + password = (char *)upw.buffer; plen = upw.uni_str_len * 2; generate_random_buffer(password, plen, True); } @@ -1137,19 +1174,21 @@ void cmd_sam_create_dom_user(struct client_info *info, int argc, char *argv[]) * local copy-of trust account out-of-sync with the * remote one, and you're stuffed! */ - res = lsa_open_policy( wks_name, &lsa_pol, True, 0x02000000); + res = lsa_open_policy(wks_name, &lsa_pol, True, 0x02000000); if (!res) { - report(out_hnd, "Connection to %s FAILED\n", wks_name); - report(out_hnd, "(Do a \"use \\\\%s -U localadmin\")\n", - wks_name); + report(out_hnd, "Connection to %s FAILED\n", + wks_name); + report(out_hnd, + "(Do a \"use \\\\%s -U localadmin\")\n", + wks_name); } } if (res && msrpc_sam_create_dom_user(srv_name, &sid1, - acct_name, acb_info, password, plen, - &user_rid)) + acct_name, acb_info, password, + plen, &user_rid)) { report(out_hnd, "Create Domain User: OK\n"); @@ -1160,17 +1199,18 @@ void cmd_sam_create_dom_user(struct client_info *info, int argc, char *argv[]) BOOL res2 = False; uchar ntpw[16]; - + nt_owf_genW(&upw, ntpw); strupper(domain); strupper(name); - report(out_hnd, "Join %s to Domain %s\n", name, domain); + report(out_hnd, "Join %s to Domain %s\n", name, + domain); /* attempt to create, and if already exist, open */ - res1 = lsa_create_secret( &lsa_pol, "$MACHINE.ACC", - 0x020003, &pol_sec); + res1 = lsa_create_secret(&lsa_pol, "$MACHINE.ACC", + 0x020003, &pol_sec); if (res1) { @@ -1178,9 +1218,9 @@ void cmd_sam_create_dom_user(struct client_info *info, int argc, char *argv[]) } else { - res1 = lsa_open_secret( &lsa_pol, - "$MACHINE.ACC", - 0x020003, &pol_sec); + res1 = lsa_open_secret(&lsa_pol, + "$MACHINE.ACC", + 0x020003, &pol_sec); } @@ -1191,7 +1231,7 @@ void cmd_sam_create_dom_user(struct client_info *info, int argc, char *argv[]) secret_store_data(&secret, password, plen); res2 = lsa_set_secret(&pol_sec, &secret) == - NT_STATUS_NOPROBLEMO; + NT_STATUS_NOPROBLEMO; } @@ -1222,7 +1262,8 @@ void cmd_sam_create_dom_user(struct client_info *info, int argc, char *argv[]) /**************************************************************************** SAM create domain alias. ****************************************************************************/ -void cmd_sam_create_dom_alias(struct client_info *info, int argc, char *argv[]) +void cmd_sam_create_dom_alias(struct client_info *info, int argc, + char *argv[]) { fstring srv_name; fstring domain; @@ -1232,8 +1273,8 @@ void cmd_sam_create_dom_alias(struct client_info *info, int argc, char *argv[]) DOM_SID sid1; BOOL res = True; BOOL res1 = True; - uint32 ace_perms = 0x02000000; /* permissions */ - uint32 alias_rid; + uint32 ace_perms = 0x02000000; /* permissions */ + uint32 alias_rid; POLICY_HND sam_pol; POLICY_HND pol_dom; @@ -1247,9 +1288,11 @@ void cmd_sam_create_dom_alias(struct client_info *info, int argc, char *argv[]) if (sid1.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != + 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } @@ -1257,7 +1300,8 @@ void cmd_sam_create_dom_alias(struct client_info *info, int argc, char *argv[]) if (argc < 2) { - report(out_hnd, "createalias: <acct name> [acct description]\n"); + report(out_hnd, + "createalias: <acct name> [acct description]\n"); } acct_name = argv[1]; @@ -1268,36 +1312,36 @@ void cmd_sam_create_dom_alias(struct client_info *info, int argc, char *argv[]) } else { - safe_strcpy(acct_desc, argv[2], sizeof(acct_desc)-1); + safe_strcpy(acct_desc, argv[2], sizeof(acct_desc) - 1); } report(out_hnd, "SAM Create Domain Alias\n"); report(out_hnd, "Domain: %s Name: %s Description: %s\n", - domain, acct_name, acct_desc); + domain, acct_name, acct_desc); /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, - &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res = res ? samr_open_domain( &sam_pol, ace_perms, &sid1, - &pol_dom) : False; + res = res ? samr_open_domain(&sam_pol, ace_perms, &sid1, + &pol_dom) : False; /* create a domain alias */ - res1 = res ? create_samr_domain_alias( &pol_dom, - acct_name, acct_desc, &alias_rid) : False; + res1 = res ? create_samr_domain_alias(&pol_dom, + acct_name, acct_desc, + &alias_rid) : False; - res = res ? samr_close( &pol_dom) : False; - res = res ? samr_close( &sam_pol) : False; + res = res ? samr_close(&pol_dom) : False; + res = res ? samr_close(&sam_pol) : False; if (res && res1) { - DEBUG(5,("cmd_sam_create_dom_alias: succeeded\n")); + DEBUG(5, ("cmd_sam_create_dom_alias: succeeded\n")); report(out_hnd, "Create Domain Alias: OK\n"); } else { - DEBUG(5,("cmd_sam_create_dom_alias: failed\n")); + DEBUG(5, ("cmd_sam_create_dom_alias: failed\n")); report(out_hnd, "Create Domain Alias: FAILED\n"); } } @@ -1316,8 +1360,8 @@ void cmd_sam_del_groupmem(struct client_info *info, int argc, char *argv[]) BOOL res = True; BOOL res1 = True; BOOL res2 = True; - uint32 ace_perms = 0x02000000; /* absolutely no idea. */ - uint32 member_rid; + uint32 ace_perms = 0x02000000; /* absolutely no idea. */ + uint32 member_rid; uint32 group_rid; POLICY_HND sam_pol; POLICY_HND pol_dom; @@ -1332,16 +1376,19 @@ void cmd_sam_del_groupmem(struct client_info *info, int argc, char *argv[]) if (sid1.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != + 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } if (argc < 2) { - report(out_hnd, "delgroupmem: <group rid> [member rid1] [member rid2] ...\n"); + report(out_hnd, + "delgroupmem: <group rid> [member rid1] [member rid2] ...\n"); return; } @@ -1353,16 +1400,15 @@ void cmd_sam_del_groupmem(struct client_info *info, int argc, char *argv[]) report(out_hnd, "SAM Add Domain Group member\n"); /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, - &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res = res ? samr_open_domain( &sam_pol, ace_perms, &sid1, - &pol_dom) : False; + res = res ? samr_open_domain(&sam_pol, ace_perms, &sid1, + &pol_dom) : False; /* connect to the domain */ - res1 = res ? samr_open_group( &pol_dom, - 0x0000001f, group_rid, &pol_grp) : False; + res1 = res ? samr_open_group(&pol_dom, + 0x0000001f, group_rid, &pol_grp) : False; while (argc > 0 && res2 && res1) { @@ -1375,22 +1421,23 @@ void cmd_sam_del_groupmem(struct client_info *info, int argc, char *argv[]) if (res2) { - report(out_hnd, "RID deleted from Group 0x%x: 0x%x\n", group_rid, member_rid); + report(out_hnd, "RID deleted from Group 0x%x: 0x%x\n", + group_rid, member_rid); } } res1 = res1 ? samr_close(&pol_grp) : False; - res = res ? samr_close(&pol_dom) : False; - res = res ? samr_close(&sam_pol) : False; + res = res ? samr_close(&pol_dom) : False; + res = res ? samr_close(&sam_pol) : False; if (res && res1 && res2) { - DEBUG(5,("cmd_sam_del_groupmem: succeeded\n")); + DEBUG(5, ("cmd_sam_del_groupmem: succeeded\n")); report(out_hnd, "Add Domain Group Member: OK\n"); } else { - DEBUG(5,("cmd_sam_del_groupmem: failed\n")); + DEBUG(5, ("cmd_sam_del_groupmem: failed\n")); report(out_hnd, "Add Domain Group Member: FAILED\n"); } } @@ -1429,9 +1476,11 @@ void cmd_sam_delete_dom_user(struct client_info *info, int argc, char *argv[]) if (sid1.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != + 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } @@ -1447,18 +1496,18 @@ void cmd_sam_delete_dom_user(struct client_info *info, int argc, char *argv[]) report(out_hnd, "SAM Delete Domain User\n"); /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, - &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res = res ? samr_open_domain( &sam_pol, 0x0200, &sid1, - &pol_dom) : False; + res = res ? samr_open_domain(&sam_pol, 0x0200, &sid1, + &pol_dom) : False; names[0] = name; - res1 = res ? samr_query_lookup_names( &pol_dom, 0x000003e8, - 1, names, - &num_rids, &rids, &types) : False; + res1 = res ? samr_query_lookup_names(&pol_dom, 0x000003e8, + 1, names, + &num_rids, &rids, + &types) : False; if (res1 && num_rids == 1 && rids) { @@ -1478,24 +1527,24 @@ void cmd_sam_delete_dom_user(struct client_info *info, int argc, char *argv[]) safe_free(types); /* connect to the domain */ - res1 = res1 ? samr_open_user( &pol_dom, - 0x010000, user_rid, &pol_usr) : False; + res1 = res1 ? samr_open_user(&pol_dom, + 0x010000, user_rid, &pol_usr) : False; res2 = res1 ? samr_unknown_2d(&pol_dom, &sid_usr) : False; res2 = res2 ? samr_delete_dom_user(&pol_usr) : False; res2 = res2 ? samr_unknown_2d(&pol_dom, &sid_usr) : False; - res = res ? samr_close(&pol_dom) : False; - res = res ? samr_close(&sam_pol) : False; + res = res ? samr_close(&pol_dom) : False; + res = res ? samr_close(&sam_pol) : False; if (res && res1 && res2) { - DEBUG(5,("cmd_sam_delete_dom_user: succeeded\n")); + DEBUG(5, ("cmd_sam_delete_dom_user: succeeded\n")); report(out_hnd, "Delete Domain User: OK\n"); } else { - DEBUG(5,("cmd_sam_delete_dom_user: failed\n")); + DEBUG(5, ("cmd_sam_delete_dom_user: failed\n")); report(out_hnd, "Delete Domain User: FAILED\n"); } } @@ -1504,7 +1553,8 @@ void cmd_sam_delete_dom_user(struct client_info *info, int argc, char *argv[]) /**************************************************************************** SAM delete group. ****************************************************************************/ -void cmd_sam_delete_dom_group(struct client_info *info, int argc, char *argv[]) +void cmd_sam_delete_dom_group(struct client_info *info, int argc, + char *argv[]) { fstring srv_name; fstring domain; @@ -1515,7 +1565,7 @@ void cmd_sam_delete_dom_group(struct client_info *info, int argc, char *argv[]) BOOL res = True; BOOL res1 = True; BOOL res2 = True; - uint32 ace_perms = 0x02000000; /* absolutely no idea. */ + uint32 ace_perms = 0x02000000; /* absolutely no idea. */ uint32 group_rid = 0; char *names[1]; uint32 *rids; @@ -1534,9 +1584,11 @@ void cmd_sam_delete_dom_group(struct client_info *info, int argc, char *argv[]) if (sid1.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != + 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } @@ -1552,18 +1604,18 @@ void cmd_sam_delete_dom_group(struct client_info *info, int argc, char *argv[]) report(out_hnd, "SAM Delete Domain Group\n"); /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, - &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res = res ? samr_open_domain( &sam_pol, ace_perms, &sid1, - &pol_dom) : False; + res = res ? samr_open_domain(&sam_pol, ace_perms, &sid1, + &pol_dom) : False; names[0] = name; - res1 = res ? samr_query_lookup_names( &pol_dom, 0x000003e8, - 1, names, - &num_rids, &rids, &types) : False; + res1 = res ? samr_query_lookup_names(&pol_dom, 0x000003e8, + 1, names, + &num_rids, &rids, + &types) : False; if (res1 && num_rids == 1 && rids) { @@ -1579,23 +1631,24 @@ void cmd_sam_delete_dom_group(struct client_info *info, int argc, char *argv[]) } /* connect to the domain */ - res1 = res1 ? samr_open_group( &pol_dom, - 0x0000001f, group_rid, &pol_grp) : False; + res1 = res1 ? samr_open_group(&pol_dom, + 0x0000001f, group_rid, + &pol_grp) : False; res2 = res1 ? samr_delete_dom_group(&pol_grp) : False; res1 = res1 ? samr_close(&pol_grp) : False; - res = res ? samr_close(&pol_dom) : False; - res = res ? samr_close(&sam_pol) : False; + res = res ? samr_close(&pol_dom) : False; + res = res ? samr_close(&sam_pol) : False; if (res && res1 && res2) { - DEBUG(5,("cmd_sam_delete_dom_group: succeeded\n")); + DEBUG(5, ("cmd_sam_delete_dom_group: succeeded\n")); report(out_hnd, "Delete Domain Group: OK\n"); } else { - DEBUG(5,("cmd_sam_delete_dom_group: failed\n")); + DEBUG(5, ("cmd_sam_delete_dom_group: failed\n")); report(out_hnd, "Delete Domain Group: FAILED\n"); } } @@ -1616,7 +1669,7 @@ void cmd_sam_add_groupmem(struct client_info *info, int argc, char *argv[]) BOOL res2 = True; BOOL res3 = True; BOOL res4 = True; - uint32 ace_perms = 0x02000000; /* absolutely no idea. */ + uint32 ace_perms = 0x02000000; /* absolutely no idea. */ uint32 *group_rids; uint32 *group_types; char **names = NULL; @@ -1645,19 +1698,22 @@ void cmd_sam_add_groupmem(struct client_info *info, int argc, char *argv[]) if (sid1.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != + 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } if (argc < 3) { - report(out_hnd, "addgroupmem <group name> [member name1] [member name2] ...\n"); + report(out_hnd, + "addgroupmem <group name> [member name1] [member name2] ...\n"); return; } - + argc--; argv++; @@ -1667,30 +1723,33 @@ void cmd_sam_add_groupmem(struct client_info *info, int argc, char *argv[]) argv++; num_names = argc; - names = (char **) argv; + names = (char **)argv; report(out_hnd, "SAM Add Domain Group member\n"); /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res4 = res ? samr_open_domain( &sam_pol, ace_perms, &sid1, - &pol_dom) : False; + res4 = res ? samr_open_domain(&sam_pol, ace_perms, &sid1, + &pol_dom) : False; /* connect to the domain */ - res3 = res ? samr_open_domain( &sam_pol, ace_perms, &sid_1_5_20, - &pol_blt) : False; + res3 = res ? samr_open_domain(&sam_pol, ace_perms, &sid_1_5_20, + &pol_blt) : False; - res2 = res4 ? samr_query_lookup_names( &pol_dom, 0x000003e8, - 1, group_names, - &num_group_rids, &group_rids, &group_types) : False; + res2 = res4 ? samr_query_lookup_names(&pol_dom, 0x000003e8, + 1, group_names, + &num_group_rids, &group_rids, + &group_types) : False; /* open the group */ - res2 = res2 ? samr_open_group( &pol_dom, - 0x0000001f, group_rids[0], &pol_grp) : False; + res2 = res2 ? samr_open_group(&pol_dom, + 0x0000001f, group_rids[0], + &pol_grp) : False; - if (!res2 || (group_types != NULL && group_types[0] == SID_NAME_UNKNOWN)) + if (!res2 + || (group_types != NULL && group_types[0] == SID_NAME_UNKNOWN)) { if (group_rids != NULL) { @@ -1701,19 +1760,23 @@ void cmd_sam_add_groupmem(struct client_info *info, int argc, char *argv[]) free(group_types); } - res2 = res3 ? samr_query_lookup_names( &pol_blt, 0x000003e8, - 1, group_names, - &num_group_rids, &group_rids, &group_types) : False; + res2 = res3 ? samr_query_lookup_names(&pol_blt, 0x000003e8, + 1, group_names, + &num_group_rids, + &group_rids, + &group_types) : False; /* open the group */ - res2 = res2 ? samr_open_group( &pol_blt, - 0x0000001f, group_rids[0], &pol_grp) : False; + res2 = res2 ? samr_open_group(&pol_blt, + 0x0000001f, group_rids[0], + &pol_grp) : False; } if (res2 && group_types[0] == SID_NAME_ALIAS) { - report(out_hnd, "%s is a local alias, not a group. Use addaliasmem command instead\n", - group_name); + report(out_hnd, + "%s is a local alias, not a group. Use addaliasmem command instead\n", + group_name); if (group_rids != NULL) { free(group_rids); @@ -1724,9 +1787,10 @@ void cmd_sam_add_groupmem(struct client_info *info, int argc, char *argv[]) } return; } - res1 = res2 ? samr_query_lookup_names( &pol_dom, 0x000003e8, - num_names, names, - &num_rids, &rids, &types) : False; + res1 = res2 ? samr_query_lookup_names(&pol_dom, 0x000003e8, + num_names, names, + &num_rids, &rids, + &types) : False; if (num_rids == 0) { @@ -1742,8 +1806,9 @@ void cmd_sam_add_groupmem(struct client_info *info, int argc, char *argv[]) { if (samr_add_groupmem(&pol_grp, rids[i])) { - report(out_hnd, "RID added to Group 0x%x: 0x%x\n", - group_rids[0], rids[i]); + report(out_hnd, + "RID added to Group 0x%x: 0x%x\n", + group_rids[0], rids[i]); } } } @@ -1751,20 +1816,20 @@ void cmd_sam_add_groupmem(struct client_info *info, int argc, char *argv[]) res1 = res ? samr_close(&pol_grp) : False; res1 = res3 ? samr_close(&pol_blt) : False; res1 = res4 ? samr_close(&pol_dom) : False; - res = res ? samr_close(&sam_pol) : False; + res = res ? samr_close(&sam_pol) : False; #if 0 free_char_array(num_names, names); #endif - + if (res && res1 && res2) { - DEBUG(5,("cmd_sam_add_groupmem: succeeded\n")); + DEBUG(5, ("cmd_sam_add_groupmem: succeeded\n")); report(out_hnd, "Add Domain Group Member: OK\n"); } else { - DEBUG(5,("cmd_sam_add_groupmem: failed\n")); + DEBUG(5, ("cmd_sam_add_groupmem: failed\n")); report(out_hnd, "Add Domain Group Member: FAILED\n"); } if (group_rids != NULL) @@ -1789,7 +1854,8 @@ void cmd_sam_add_groupmem(struct client_info *info, int argc, char *argv[]) /**************************************************************************** SAM create domain group. ****************************************************************************/ -void cmd_sam_create_dom_group(struct client_info *info, int argc, char *argv[]) +void cmd_sam_create_dom_group(struct client_info *info, int argc, + char *argv[]) { fstring srv_name; fstring domain; @@ -1799,8 +1865,8 @@ void cmd_sam_create_dom_group(struct client_info *info, int argc, char *argv[]) DOM_SID sid1; BOOL res = True; BOOL res1 = True; - uint32 ace_perms = 0x02000000; /* absolutely no idea. */ - uint32 group_rid; + uint32 ace_perms = 0x02000000; /* absolutely no idea. */ + uint32 group_rid; POLICY_HND sam_pol; POLICY_HND pol_dom; @@ -1814,9 +1880,11 @@ void cmd_sam_create_dom_group(struct client_info *info, int argc, char *argv[]) if (sid1.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != + 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } @@ -1824,7 +1892,8 @@ void cmd_sam_create_dom_group(struct client_info *info, int argc, char *argv[]) if (argc < 2) { - report(out_hnd, "creategroup: <acct name> [acct description]\n"); + report(out_hnd, + "creategroup: <acct name> [acct description]\n"); } acct_name = argv[1]; @@ -1835,37 +1904,37 @@ void cmd_sam_create_dom_group(struct client_info *info, int argc, char *argv[]) } else { - safe_strcpy(acct_desc, argv[2], sizeof(acct_desc)-1); + safe_strcpy(acct_desc, argv[2], sizeof(acct_desc) - 1); } report(out_hnd, "SAM Create Domain Group\n"); report(out_hnd, "Domain: %s Name: %s Description: %s\n", - domain, acct_name, acct_desc); + domain, acct_name, acct_desc); /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, - &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res = res ? samr_open_domain( &sam_pol, ace_perms, &sid1, - &pol_dom) : False; + res = res ? samr_open_domain(&sam_pol, ace_perms, &sid1, + &pol_dom) : False; /* read some users */ - res1 = res ? create_samr_domain_group( &pol_dom, - acct_name, acct_desc, &group_rid) : False; + res1 = res ? create_samr_domain_group(&pol_dom, + acct_name, acct_desc, + &group_rid) : False; - res = res ? samr_close( &pol_dom) : False; - res = res ? samr_close( &sam_pol) : False; + res = res ? samr_close(&pol_dom) : False; + res = res ? samr_close(&sam_pol) : False; if (res && res1) { - DEBUG(5,("cmd_sam_create_dom_group: succeeded\n")); + DEBUG(5, ("cmd_sam_create_dom_group: succeeded\n")); report(out_hnd, "Create Domain Group: OK\n"); } else { - DEBUG(5,("cmd_sam_create_dom_group: failed\n")); + DEBUG(5, ("cmd_sam_create_dom_group: failed\n")); report(out_hnd, "Create Domain Group: FAILED\n"); } } @@ -1875,7 +1944,7 @@ experimental SAM users enum. ****************************************************************************/ void cmd_sam_enum_users(struct client_info *info, int argc, char *argv[]) { - BOOL request_user_info = False; + BOOL request_user_info = False; BOOL request_group_info = False; BOOL request_alias_info = False; struct acct_info *sam = NULL; @@ -1897,9 +1966,11 @@ void cmd_sam_enum_users(struct client_info *info, int argc, char *argv[]) if (sid1.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != + 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } @@ -1910,7 +1981,7 @@ void cmd_sam_enum_users(struct client_info *info, int argc, char *argv[]) { case 'u': { - request_user_info = True; + request_user_info = True; break; } case 'g': @@ -1929,11 +2000,13 @@ void cmd_sam_enum_users(struct client_info *info, int argc, char *argv[]) report(out_hnd, "SAM Enumerate Users\n"); msrpc_sam_enum_users(srv_name, domain, &sid1, - &sam, &num_sam_entries, - sam_display_user, - request_user_info ? sam_display_user_info : NULL, - request_group_info ? sam_display_group_members : NULL, - request_alias_info ? sam_display_group_members : NULL); + &sam, &num_sam_entries, + sam_display_user, + request_user_info ? sam_display_user_info : NULL, + request_group_info ? sam_display_group_members : + NULL, + request_alias_info ? sam_display_group_members : + NULL); if (sam != NULL) { @@ -1973,7 +2046,8 @@ void cmd_sam_query_groupmem(struct client_info *info, int argc, char *argv[]) { if (msrpc_sam_get_first_domain(srv_name, domain, &sid) != 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } @@ -1990,42 +2064,41 @@ void cmd_sam_query_groupmem(struct client_info *info, int argc, char *argv[]) report(out_hnd, "SAM Query Group: %s\n", group_name); report(out_hnd, "From: %s To: %s Domain: %s SID: %s\n", - info->myhostname, srv_name, domain, sid_str); + info->myhostname, srv_name, domain, sid_str); /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, - &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res = res ? samr_open_domain( &sam_pol, 0x304, &sid, - &pol_dom) : False; + res = res ? samr_open_domain(&sam_pol, 0x304, &sid, &pol_dom) : False; /* look up group rid */ names[0] = group_name; - res1 = res ? samr_query_lookup_names( &pol_dom, 0x3e8, - 1, names, - &num_rids, &rids, &types) : False; + res1 = res ? samr_query_lookup_names(&pol_dom, 0x3e8, + 1, names, + &num_rids, &rids, + &types) : False; if (res1 && num_rids == 1) { - res1 = req_groupmem_info( &pol_dom, - domain, - &sid, - rids[0], - group_name, - sam_display_group_members); + res1 = req_groupmem_info(&pol_dom, + domain, + &sid, + rids[0], + group_name, + sam_display_group_members); } - res = res ? samr_close( &pol_dom) : False; - res = res ? samr_close( &sam_pol) : False; + res = res ? samr_close(&pol_dom) : False; + res = res ? samr_close(&sam_pol) : False; if (res1) { - DEBUG(5,("cmd_sam_query_group: succeeded\n")); + DEBUG(5, ("cmd_sam_query_group: succeeded\n")); } else { - DEBUG(5,("cmd_sam_query_group: failed\n")); + DEBUG(5, ("cmd_sam_query_group: failed\n")); } if (rids != NULL) { @@ -2069,7 +2142,8 @@ void cmd_sam_query_group(struct client_info *info, int argc, char *argv[]) { if (msrpc_sam_get_first_domain(srv_name, domain, &sid) != 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } @@ -2086,39 +2160,38 @@ void cmd_sam_query_group(struct client_info *info, int argc, char *argv[]) report(out_hnd, "SAM Query Group: %s\n", group_name); report(out_hnd, "From: %s To: %s Domain: %s SID: %s\n", - info->myhostname, srv_name, domain, sid_str); + info->myhostname, srv_name, domain, sid_str); /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res = res ? samr_open_domain( &sam_pol, 0x304, &sid, &pol_dom) : False; + res = res ? samr_open_domain(&sam_pol, 0x304, &sid, &pol_dom) : False; /* look up group rid */ names[0] = group_name; - res1 = res ? samr_query_lookup_names( &pol_dom, 0x3e8, - 1, names, - &num_rids, &rids, &types) : False; + res1 = res ? samr_query_lookup_names(&pol_dom, 0x3e8, + 1, names, + &num_rids, &rids, + &types) : False; if (res1 && num_rids == 1) { - res1 = query_groupinfo( &pol_dom, - domain, - &sid, - rids[0], - sam_display_group_info); + res1 = query_groupinfo(&pol_dom, + domain, + &sid, rids[0], sam_display_group_info); } - res = res ? samr_close( &pol_dom) : False; - res = res ? samr_close( &sam_pol) : False; + res = res ? samr_close(&pol_dom) : False; + res = res ? samr_close(&sam_pol) : False; if (res1) { - DEBUG(5,("cmd_sam_query_group: succeeded\n")); + DEBUG(5, ("cmd_sam_query_group: succeeded\n")); } else { - DEBUG(5,("cmd_sam_query_group: failed\n")); + DEBUG(5, ("cmd_sam_query_group: failed\n")); } if (rids != NULL) { @@ -2128,7 +2201,7 @@ void cmd_sam_query_group(struct client_info *info, int argc, char *argv[]) { free(types); } - + } @@ -2163,7 +2236,8 @@ void cmd_sam_query_sec_obj(struct client_info *info, int argc, char *argv[]) { if (msrpc_sam_get_first_domain(srv_name, domain, &sid) != 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } @@ -2183,21 +2257,20 @@ void cmd_sam_query_sec_obj(struct client_info *info, int argc, char *argv[]) report(out_hnd, "SAM Query User: %s\n", user_name); report(out_hnd, "From: %s To: %s Domain: %s SID: %s\n", - info->myhostname, srv_name, domain, sid_str); + info->myhostname, srv_name, domain, sid_str); /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, - &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res = res ? samr_open_domain( &sam_pol, 0x304, &sid, - &pol_dom) : False; + res = res ? samr_open_domain(&sam_pol, 0x304, &sid, &pol_dom) : False; /* look up user rid */ names[0] = user_name; - res1 = res ? samr_query_lookup_names( &pol_dom, 0x3e8, - 1, names, - &num_rids, &rids, &types) : False; + res1 = res ? samr_query_lookup_names(&pol_dom, 0x3e8, + 1, names, + &num_rids, &rids, + &types) : False; /* send user info query */ if (res1 && num_rids == 1) @@ -2207,15 +2280,15 @@ void cmd_sam_query_sec_obj(struct client_info *info, int argc, char *argv[]) SEC_DESC_BUF buf; /* send open domain (on user sid) */ - ret = samr_open_user( &pol_dom, 0x02011b, rids[0], &pol_usr); + ret = samr_open_user(&pol_dom, 0x02011b, rids[0], &pol_usr); res1 = ret ? samr_query_sec_obj(&pol_usr, 0x04, &buf) : False; - ret = ret ? samr_close (&pol_usr) : False; + ret = ret ? samr_close(&pol_usr) : False; if (buf.sec != NULL) { - display_sec_desc(out_hnd, ACTION_HEADER , buf.sec); + display_sec_desc(out_hnd, ACTION_HEADER, buf.sec); display_sec_desc(out_hnd, ACTION_ENUMERATE, buf.sec); - display_sec_desc(out_hnd, ACTION_FOOTER , buf.sec); + display_sec_desc(out_hnd, ACTION_FOOTER, buf.sec); } free_sec_desc_buf(&buf); @@ -2225,16 +2298,16 @@ void cmd_sam_query_sec_obj(struct client_info *info, int argc, char *argv[]) res1 = False; } - res = res ? samr_close( &pol_dom) : False; - res = res ? samr_close( &sam_pol) : False; + res = res ? samr_close(&pol_dom) : False; + res = res ? samr_close(&sam_pol) : False; if (res1) { - DEBUG(5,("cmd_sam_query_sec_obj: succeeded\n")); + DEBUG(5, ("cmd_sam_query_sec_obj: succeeded\n")); } else { - DEBUG(5,("cmd_sam_query_sec_obj: failed\n")); + DEBUG(5, ("cmd_sam_query_sec_obj: failed\n")); } if (rids != NULL) { @@ -2268,7 +2341,7 @@ void cmd_sam_query_user(struct client_info *info, int argc, char *argv[]) POLICY_HND pol_dom; uint16 info_level = 0x15; - BOOL request_user_info = False; + BOOL request_user_info = False; BOOL request_group_info = False; BOOL request_alias_info = False; @@ -2283,7 +2356,8 @@ void cmd_sam_query_user(struct client_info *info, int argc, char *argv[]) { if (msrpc_sam_get_first_domain(srv_name, domain, &sid) != 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } @@ -2305,7 +2379,7 @@ void cmd_sam_query_user(struct client_info *info, int argc, char *argv[]) { case 'u': { - request_user_info = True; + request_user_info = True; break; } case 'g': @@ -2330,49 +2404,51 @@ void cmd_sam_query_user(struct client_info *info, int argc, char *argv[]) report(out_hnd, "SAM Query User: %s\n", user_name); report(out_hnd, "From: %s To: %s Domain: %s SID: %s\n", - info->myhostname, srv_name, domain, sid_str); + info->myhostname, srv_name, domain, sid_str); /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, - &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res = res ? samr_open_domain( &sam_pol, 0x304, &sid, - &pol_dom) : False; + res = res ? samr_open_domain(&sam_pol, 0x304, &sid, &pol_dom) : False; /* look up user rid */ names[0] = user_name; - res1 = res ? samr_query_lookup_names( &pol_dom, 0x3e8, - 1, names, - &num_rids, &rids, &types) : False; + res1 = res ? samr_query_lookup_names(&pol_dom, 0x3e8, + 1, names, + &num_rids, &rids, + &types) : False; /* send user info query */ if (res1 && num_rids == 1) { - msrpc_sam_user( &pol_dom, NULL, - domain, - &sid, NULL, - rids[0], info_level, user_name, - sam_display_user, - request_user_info ? sam_display_user_info : NULL, - request_group_info ? sam_display_group_members : NULL, - request_alias_info ? sam_display_group_members : NULL); + msrpc_sam_user(&pol_dom, NULL, + domain, + &sid, NULL, + rids[0], info_level, user_name, + sam_display_user, + request_user_info ? sam_display_user_info : + NULL, + request_group_info ? sam_display_group_members + : NULL, + request_alias_info ? sam_display_group_members + : NULL); } else { res1 = False; } - res = res ? samr_close( &pol_dom) : False; - res = res ? samr_close( &sam_pol) : False; + res = res ? samr_close(&pol_dom) : False; + res = res ? samr_close(&sam_pol) : False; if (res1) { - DEBUG(5,("cmd_sam_query_user: succeeded\n")); + DEBUG(5, ("cmd_sam_query_user: succeeded\n")); } else { - DEBUG(5,("cmd_sam_query_user: failed\n")); + DEBUG(5, ("cmd_sam_query_user: failed\n")); } if (rids != NULL) { @@ -2427,14 +2503,16 @@ void cmd_sam_set_userinfo2(struct client_info *info, int argc, char *argv[]) { if (msrpc_sam_get_first_domain(srv_name, domain, &sid) != 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } if (argc < 2) { - report(out_hnd, "samuserset2 <name> [-s <acb_bits>] [-c <acb_bits]\n"); + report(out_hnd, + "samuserset2 <name> [-s <acb_bits>] [-c <acb_bits]\n"); return; } @@ -2443,7 +2521,7 @@ void cmd_sam_set_userinfo2(struct client_info *info, int argc, char *argv[]) safe_strcpy(user_name, argv[0], sizeof(user_name)); - while ((opt = getopt(argc, argv,"s:c:p:")) != EOF) + while ((opt = getopt(argc, argv, "s:c:p:")) != EOF) { switch (opt) { @@ -2451,7 +2529,7 @@ void cmd_sam_set_userinfo2(struct client_info *info, int argc, char *argv[]) { set_passwd = True; safe_strcpy(password, optarg, - sizeof(password)-1); + sizeof(password) - 1); break; } case 's': @@ -2474,18 +2552,18 @@ void cmd_sam_set_userinfo2(struct client_info *info, int argc, char *argv[]) report(out_hnd, "SAM Set User Info: %s\n", user_name); /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, - &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res = res ? samr_open_domain( &sam_pol, 0x02000000, &sid, - &pol_dom) : False; + res = res ? samr_open_domain(&sam_pol, 0x02000000, &sid, + &pol_dom) : False; /* look up user rid */ names[0] = user_name; - res1 = res ? samr_query_lookup_names( &pol_dom, 0x3e8, - 1, names, - &num_rids, &rids, &types) : False; + res1 = res ? samr_query_lookup_names(&pol_dom, 0x3e8, + 1, names, + &num_rids, &rids, + &types) : False; if (set_passwd && res1 && num_rids == 1) @@ -2493,34 +2571,36 @@ void cmd_sam_set_userinfo2(struct client_info *info, int argc, char *argv[]) void *usr = NULL; uint32 switch_value = 0; - SAM_USER_INFO_12 *p = (SAM_USER_INFO_12 *)malloc(sizeof(SAM_USER_INFO_12)); - usr = (void*)p; + SAM_USER_INFO_12 *p = + (SAM_USER_INFO_12 *) malloc(sizeof(SAM_USER_INFO_12)); + usr = (void *)p; switch_value = 0x12; - + if (usr != NULL) { nt_lm_owf_gen(password, p->nt_pwd, p->lm_pwd); p->lm_pwd_active = 1; p->nt_pwd_active = 1; - res1 = set_samr_set_userinfo2( &pol_dom, - switch_value, rids[0], usr); + res1 = set_samr_set_userinfo2(&pol_dom, + switch_value, rids[0], + usr); } } /* send set user info */ if ((!set_passwd) && res1 && num_rids == 1 && - get_samr_query_userinfo( &pol_dom, - 0x10, rids[0], - &ctr)) + get_samr_query_userinfo(&pol_dom, 0x10, rids[0], &ctr)) { void *usr = NULL; uint32 switch_value = 0; if (True) { - SAM_USER_INFO_10 *p = (SAM_USER_INFO_10 *)malloc(sizeof(SAM_USER_INFO_10)); + SAM_USER_INFO_10 *p = + (SAM_USER_INFO_10 *) + malloc(sizeof(SAM_USER_INFO_10)); p->acb_info = ctr.info.id10->acb_info; - DEBUG(10,("acb_info: %x\n", p->acb_info)); + DEBUG(10, ("acb_info: %x\n", p->acb_info)); if (set_acb_bits) { p->acb_info |= acb_set; @@ -2531,31 +2611,32 @@ void cmd_sam_set_userinfo2(struct client_info *info, int argc, char *argv[]) p->acb_info &= (~acb_clr); } - DEBUG(10,("acb_info: %x\n", p->acb_info)); + DEBUG(10, ("acb_info: %x\n", p->acb_info)); - usr = (void*)p; + usr = (void *)p; switch_value = 16; } - + if (usr != NULL) { - res1 = set_samr_set_userinfo2( &pol_dom, - switch_value, rids[0], usr); + res1 = set_samr_set_userinfo2(&pol_dom, + switch_value, rids[0], + usr); } } - res = res ? samr_close( &pol_dom) : False; - res = res ? samr_close( &sam_pol) : False; + res = res ? samr_close(&pol_dom) : False; + res = res ? samr_close(&sam_pol) : False; if (res1) { report(out_hnd, "Set User Info: OK\n"); - DEBUG(5,("cmd_sam_query_user: succeeded\n")); + DEBUG(5, ("cmd_sam_query_user: succeeded\n")); } else { report(out_hnd, "Set User Info: Failed\n"); - DEBUG(5,("cmd_sam_query_user: failed\n")); + DEBUG(5, ("cmd_sam_query_user: failed\n")); } safe_free(rids); safe_free(types); @@ -2600,7 +2681,8 @@ void cmd_sam_set_userinfo(struct client_info *info, int argc, char *argv[]) { if (msrpc_sam_get_first_domain(srv_name, domain, &sid) != 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } @@ -2620,20 +2702,19 @@ void cmd_sam_set_userinfo(struct client_info *info, int argc, char *argv[]) { fstring pass_str; char *pass; - slprintf(pass_str, sizeof(pass_str)-1, "Enter %s's Password:", - user_name); - pass = (char*)getpass(pass_str); + slprintf(pass_str, sizeof(pass_str) - 1, + "Enter %s's Password:", user_name); + pass = (char *)getpass(pass_str); if (pass != NULL) { - safe_strcpy(password, pass, - sizeof(password)-1); + safe_strcpy(password, pass, sizeof(password) - 1); set_passwd = True; } } else { - while ((opt = getopt(argc, argv,"p:")) != EOF) + while ((opt = getopt(argc, argv, "p:")) != EOF) { switch (opt) { @@ -2641,7 +2722,7 @@ void cmd_sam_set_userinfo(struct client_info *info, int argc, char *argv[]) { set_passwd = True; safe_strcpy(password, optarg, - sizeof(password)-1); + sizeof(password) - 1); break; } } @@ -2654,22 +2735,23 @@ void cmd_sam_set_userinfo(struct client_info *info, int argc, char *argv[]) report(out_hnd, "Password: %s\n", password); /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, - &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res = res ? samr_open_domain( &sam_pol, 0x02000000, &sid, - &pol_dom) : False; + res = res ? samr_open_domain(&sam_pol, 0x02000000, &sid, + &pol_dom) : False; /* look up user rid */ names[0] = user_name; - res1 = res ? samr_query_lookup_names( &pol_dom, 0x3e8, - 1, names, - &num_rids, &rids, &types) : False; + res1 = res ? samr_query_lookup_names(&pol_dom, 0x3e8, + 1, names, + &num_rids, &rids, + &types) : False; /* send set user info */ - if (res1 && num_rids == 1 && get_samr_query_userinfo( &pol_dom, - 0x15, rids[0], &ctr)) + if (res1 && num_rids == 1 && get_samr_query_userinfo(&pol_dom, + 0x15, rids[0], + &ctr)) { void *usr = NULL; uint32 switch_value = 0; @@ -2678,77 +2760,78 @@ void cmd_sam_set_userinfo(struct client_info *info, int argc, char *argv[]) if (set_passwd) { encode_pw_buffer(pwbuf, password, - strlen(password), True); + strlen(password), True); } if (True) { - SAM_USER_INFO_24 *p = (SAM_USER_INFO_24*)malloc(sizeof(SAM_USER_INFO_24)); + SAM_USER_INFO_24 *p = + (SAM_USER_INFO_24 *) + malloc(sizeof(SAM_USER_INFO_24)); make_sam_user_info24(p, pwbuf, strlen(password)); usr = p; switch_value = 24; } - + if (False) { SAM_USER_INFO_21 *usr21 = ctr.info.id21; - SAM_USER_INFO_23 *p = (SAM_USER_INFO_23*)malloc(sizeof(SAM_USER_INFO_23)); + SAM_USER_INFO_23 *p = + (SAM_USER_INFO_23 *) + malloc(sizeof(SAM_USER_INFO_23)); /* send user info query, level 0x15 */ make_sam_user_info23W(p, - &usr21->logon_time, - &usr21->logoff_time, - &usr21->kickoff_time, - &usr21->pass_last_set_time, - &usr21->pass_can_change_time, - &usr21->pass_must_change_time, - - &usr21->uni_user_name, - &usr21->uni_full_name, - &usr21->uni_home_dir, - &usr21->uni_dir_drive, - &usr21->uni_logon_script, - &usr21->uni_profile_path, - &usr21->uni_acct_desc, - &usr21->uni_workstations, - &usr21->uni_unknown_str, - &usr21->uni_munged_dial, - - 0x0, - usr21->group_rid, - usr21->acb_info, - - 0x09f827fa, - usr21->logon_divs, - &usr21->logon_hrs, - usr21->unknown_5, - pwbuf, - usr21->unknown_6); + &usr21->logon_time, + &usr21->logoff_time, + &usr21->kickoff_time, + &usr21->pass_last_set_time, + &usr21->pass_can_change_time, + &usr21->pass_must_change_time, + &usr21->uni_user_name, + &usr21->uni_full_name, + &usr21->uni_home_dir, + &usr21->uni_dir_drive, + &usr21->uni_logon_script, + &usr21->uni_profile_path, + &usr21->uni_acct_desc, + &usr21->uni_workstations, + &usr21->uni_unknown_str, + &usr21->uni_munged_dial, + 0x0, + usr21->group_rid, + usr21->acb_info, + 0x09f827fa, + usr21->logon_divs, + &usr21->logon_hrs, + usr21->unknown_5, + pwbuf, usr21->unknown_6); usr = p; switch_value = 23; } if (usr != NULL) { - res1 = set_samr_set_userinfo( &pol_dom, - switch_value, rids[0], usr); + res1 = set_samr_set_userinfo(&pol_dom, + switch_value, rids[0], + usr); } } free_samr_userinfo_ctr(&ctr); - res = res ? samr_close( &pol_dom) : False; - res = res ? samr_close( &sam_pol) : False; + res = res ? samr_close(&pol_dom) : False; + res = res ? samr_close(&sam_pol) : False; if (res1) { report(out_hnd, "Set User Info: OK\n"); - DEBUG(5,("cmd_sam_query_user: succeeded\n")); + DEBUG(5, ("cmd_sam_query_user: succeeded\n")); } else { report(out_hnd, "Set User Info: Failed\n"); - DEBUG(5,("cmd_sam_query_user: failed\n")); + DEBUG(5, ("cmd_sam_query_user: failed\n")); } if (rids != NULL) { @@ -2761,16 +2844,15 @@ void cmd_sam_set_userinfo(struct client_info *info, int argc, char *argv[]) free_samr_userinfo_ctr(&ctr); } -static void sam_display_disp_info(const char* domain, const DOM_SID *sid, - uint16 info, uint32 num, - SAM_DISPINFO_CTR *ctr) - +static void sam_display_disp_info(const char *domain, const DOM_SID * sid, + uint16 info, uint32 num, + SAM_DISPINFO_CTR * ctr) { report(out_hnd, "SAM Display Info for Domain %s\n", domain); - display_sam_disp_info_ctr(out_hnd, ACTION_HEADER , info, num, ctr); + display_sam_disp_info_ctr(out_hnd, ACTION_HEADER, info, num, ctr); display_sam_disp_info_ctr(out_hnd, ACTION_ENUMERATE, info, num, ctr); - display_sam_disp_info_ctr(out_hnd, ACTION_FOOTER , info, num, ctr); + display_sam_disp_info_ctr(out_hnd, ACTION_FOOTER, info, num, ctr); } /**************************************************************************** @@ -2798,30 +2880,33 @@ void cmd_sam_query_dispinfo(struct client_info *info, int argc, char *argv[]) if (sid1.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != + 0x0) { - fprintf(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + fprintf(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } if (argc > 1) { - switch_value = strtoul(argv[1], (char**)NULL, 10); + switch_value = strtoul(argv[1], (char **)NULL, 10); } ctr.sam.info1 = &inf1; - if (msrpc_sam_query_dispinfo( srv_name, domain, &sid1, - switch_value, - &num_entries, &ctr, sam_display_disp_info)) + if (msrpc_sam_query_dispinfo(srv_name, domain, &sid1, + switch_value, + &num_entries, &ctr, + sam_display_disp_info)) { - DEBUG(5,("cmd_sam_query_dispinfo: succeeded\n")); + DEBUG(5, ("cmd_sam_query_dispinfo: succeeded\n")); } else { - DEBUG(5,("cmd_sam_query_dispinfo: failed\n")); + DEBUG(5, ("cmd_sam_query_dispinfo: failed\n")); } } @@ -2847,26 +2932,28 @@ void cmd_sam_query_dominfo(struct client_info *info, int argc, char *argv[]) if (sid1.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != + 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } if (argc > 1) { - switch_value = strtoul(argv[1], (char**)NULL, 10); + switch_value = strtoul(argv[1], (char **)NULL, 10); } if (sam_query_dominfo(srv_name, &sid1, switch_value, &ctr)) { - DEBUG(5,("cmd_sam_query_dominfo: succeeded\n")); + DEBUG(5, ("cmd_sam_query_dominfo: succeeded\n")); sam_display_dom_info(domain, &sid1, switch_value, &ctr); } else { - DEBUG(5,("cmd_sam_query_dominfo: failed\n")); + DEBUG(5, ("cmd_sam_query_dominfo: failed\n")); } } @@ -2901,7 +2988,8 @@ void cmd_sam_query_aliasmem(struct client_info *info, int argc, char *argv[]) { if (msrpc_sam_get_first_domain(srv_name, domain, &sid) != 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } @@ -2918,43 +3006,42 @@ void cmd_sam_query_aliasmem(struct client_info *info, int argc, char *argv[]) report(out_hnd, "SAM Query Alias: %s\n", alias_name); report(out_hnd, "From: %s To: %s Domain: %s SID: %s\n", - info->myhostname, srv_name, domain, sid_str); + info->myhostname, srv_name, domain, sid_str); /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, - &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res = res ? samr_open_domain( &sam_pol, 0x304, &sid, - &pol_dom) : False; + res = res ? samr_open_domain(&sam_pol, 0x304, &sid, &pol_dom) : False; /* look up alias rid */ names[0] = alias_name; - res1 = res ? samr_query_lookup_names( &pol_dom, 0x3e8, - 1, names, - &num_rids, &rids, &types) : False; + res1 = res ? samr_query_lookup_names(&pol_dom, 0x3e8, + 1, names, + &num_rids, &rids, + &types) : False; if (res1 && num_rids == 1) { res1 = req_aliasmem_info(srv_name, - &pol_dom, - domain, - &sid, - rids[0], - alias_name, - sam_display_alias_members); + &pol_dom, + domain, + &sid, + rids[0], + alias_name, + sam_display_alias_members); } - res = res ? samr_close( &pol_dom) : False; - res = res ? samr_close( &sam_pol) : False; + res = res ? samr_close(&pol_dom) : False; + res = res ? samr_close(&sam_pol) : False; if (res1) { - DEBUG(5,("cmd_sam_query_alias: succeeded\n")); + DEBUG(5, ("cmd_sam_query_alias: succeeded\n")); } else { - DEBUG(5,("cmd_sam_query_alias: failed\n")); + DEBUG(5, ("cmd_sam_query_alias: failed\n")); } if (rids != NULL) { @@ -2998,7 +3085,8 @@ void cmd_sam_query_alias(struct client_info *info, int argc, char *argv[]) { if (msrpc_sam_get_first_domain(srv_name, domain, &sid) != 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } @@ -3015,41 +3103,38 @@ void cmd_sam_query_alias(struct client_info *info, int argc, char *argv[]) report(out_hnd, "SAM Query Alias: %s\n", alias_name); report(out_hnd, "From: %s To: %s Domain: %s SID: %s\n", - info->myhostname, srv_name, domain, sid_str); + info->myhostname, srv_name, domain, sid_str); /* establish a connection. */ - res = res ? samr_connect( srv_name, 0x02000000, - &sam_pol) : False; + res = res ? samr_connect(srv_name, 0x02000000, &sam_pol) : False; /* connect to the domain */ - res = res ? samr_open_domain( &sam_pol, 0x304, &sid, - &pol_dom) : False; + res = res ? samr_open_domain(&sam_pol, 0x304, &sid, &pol_dom) : False; /* look up alias rid */ names[0] = alias_name; - res1 = res ? samr_query_lookup_names( &pol_dom, 0x3e8, - 1, names, - &num_rids, &rids, &types) : False; + res1 = res ? samr_query_lookup_names(&pol_dom, 0x3e8, + 1, names, + &num_rids, &rids, + &types) : False; if (res1 && num_rids == 1) { - res1 = query_aliasinfo( &pol_dom, - domain, - &sid, - rids[0], - sam_display_alias_info); + res1 = query_aliasinfo(&pol_dom, + domain, + &sid, rids[0], sam_display_alias_info); } - res = res ? samr_close( &pol_dom) : False; - res = res ? samr_close( &sam_pol) : False; + res = res ? samr_close(&pol_dom) : False; + res = res ? samr_close(&sam_pol) : False; if (res1) { - DEBUG(5,("cmd_sam_query_alias: succeeded\n")); + DEBUG(5, ("cmd_sam_query_alias: succeeded\n")); } else { - DEBUG(5,("cmd_sam_query_alias: failed\n")); + DEBUG(5, ("cmd_sam_query_alias: failed\n")); } if (rids != NULL) { @@ -3098,7 +3183,7 @@ void cmd_sam_enum_aliases(struct client_info *info, int argc, char *argv[]) } case 'm': { - request_member_info = True; + request_member_info = True; break; } case 'a': @@ -3111,20 +3196,24 @@ void cmd_sam_enum_aliases(struct client_info *info, int argc, char *argv[]) if (sid1.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != + 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } report(out_hnd, "SAM Enumerate Aliases\n"); - msrpc_sam_enum_aliases(srv_name, domain, &sid1, - &sam, &num_sam_entries, - sam_display_alias, - request_alias_info ? sam_display_alias_info : NULL, - request_member_info ? sam_display_alias_members : NULL); + msrpc_sam_enum_aliases(srv_name, domain, &sid1, + &sam, &num_sam_entries, + sam_display_alias, + request_alias_info ? sam_display_alias_info : + NULL, + request_member_info ? sam_display_alias_members + : NULL); if (sam != NULL) { @@ -3158,9 +3247,11 @@ void cmd_sam_enum_groups(struct client_info *info, int argc, char *argv[]) if (sid1.num_auths == 0) { - if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != 0x0) + if (msrpc_sam_get_first_domain(srv_name, domain, &sid1) != + 0x0) { - report(out_hnd, "please use 'lsaquery' first, to ascertain the SID\n"); + report(out_hnd, + "please use 'lsaquery' first, to ascertain the SID\n"); return; } } @@ -3171,7 +3262,7 @@ void cmd_sam_enum_groups(struct client_info *info, int argc, char *argv[]) { case 'm': { - request_member_info = True; + request_member_info = True; break; } case 'g': @@ -3184,11 +3275,13 @@ void cmd_sam_enum_groups(struct client_info *info, int argc, char *argv[]) report(out_hnd, "SAM Enumerate Groups\n"); - msrpc_sam_enum_groups(srv_name, domain, &sid1, - &sam, &num_sam_entries, - sam_display_group, - request_group_info ? sam_display_group_info : NULL, - request_member_info ? sam_display_group_members : NULL); + msrpc_sam_enum_groups(srv_name, domain, &sid1, + &sam, &num_sam_entries, + sam_display_group, + request_group_info ? sam_display_group_info : + NULL, + request_member_info ? sam_display_group_members + : NULL); if (sam != NULL) { @@ -3218,7 +3311,7 @@ void cmd_sam_enum_domains(struct client_info *info, int argc, char *argv[]) { case 'i': { - request_domain_info= True; + request_domain_info = True; break; } } @@ -3227,13 +3320,14 @@ void cmd_sam_enum_domains(struct client_info *info, int argc, char *argv[]) report(out_hnd, "SAM Enumerate Domains\n"); msrpc_sam_enum_domains(srv_name, - &sam, &num_sam_entries, - request_domain_info ? NULL : sam_display_domain, - request_domain_info ? sam_display_dom_info : NULL); + &sam, &num_sam_entries, + request_domain_info ? NULL : + sam_display_domain, + request_domain_info ? sam_display_dom_info : + NULL); if (sam != NULL) { free(sam); } } - diff --git a/source/samrd/srv_samr_passdb.c b/source/samrd/srv_samr_passdb.c index c855dba9b07..63d9077e965 100644 --- a/source/samrd/srv_samr_passdb.c +++ b/source/samrd/srv_samr_passdb.c @@ -33,25 +33,25 @@ extern int DEBUGLEVEL; /**************************************************************************** set samr sid ****************************************************************************/ -static BOOL set_policy_samr_sid(struct policy_cache *cache, POLICY_HND *hnd, - const DOM_SID *sid) +static BOOL set_policy_samr_sid(struct policy_cache *cache, POLICY_HND * hnd, + const DOM_SID * sid) { pstring sidstr; DOM_SID *dev = sid_dup(sid); - DEBUG(3,("Setting policy sid=%s\n", sid_to_string(sidstr, sid))); + DEBUG(3, ("Setting policy sid=%s\n", sid_to_string(sidstr, sid))); if (dev != NULL) { - if (set_policy_state(cache, hnd, NULL, (void*)dev)) + if (set_policy_state(cache, hnd, NULL, (void *)dev)) { - DEBUG(3,("Service setting policy sid=%s\n", sidstr)); + DEBUG(3, ("Service setting policy sid=%s\n", sidstr)); return True; } free(dev); return True; } - DEBUG(3,("Error setting policy sid\n")); + DEBUG(3, ("Error setting policy sid\n")); return False; } @@ -59,19 +59,20 @@ static BOOL set_policy_samr_sid(struct policy_cache *cache, POLICY_HND *hnd, get samr sid ****************************************************************************/ static BOOL get_policy_samr_sid(struct policy_cache *cache, - const POLICY_HND *hnd, DOM_SID *sid) + const POLICY_HND * hnd, DOM_SID * sid) { - DOM_SID *dev = (DOM_SID*)get_policy_state_info(cache, hnd); + DOM_SID *dev = (DOM_SID *) get_policy_state_info(cache, hnd); if (dev != NULL) { pstring tmp; sid_copy(sid, dev); - DEBUG(3,("Getting policy sid=%s\n", sid_to_string(tmp, sid))); + DEBUG(3, + ("Getting policy sid=%s\n", sid_to_string(tmp, sid))); return True; } - DEBUG(3,("Error getting policy sid\n")); + DEBUG(3, ("Error getting policy sid\n")); return False; } @@ -80,11 +81,10 @@ static BOOL get_policy_samr_sid(struct policy_cache *cache, dynamically returns the correct user info..... JRA. ********************************************************************/ -static BOOL get_sampwd_entries(SAM_USER_INFO_21 *pw_buf, - int start_idx, - int *total_entries, int *num_entries, - int max_num_entries, - uint16 acb_mask) +static BOOL get_sampwd_entries(SAM_USER_INFO_21 * pw_buf, + int start_idx, + int *total_entries, int *num_entries, + int max_num_entries, uint16 acb_mask) { void *vp = NULL; struct sam_passwd *pwd = NULL; @@ -92,16 +92,19 @@ static BOOL get_sampwd_entries(SAM_USER_INFO_21 *pw_buf, (*num_entries) = 0; (*total_entries) = 0; - if (pw_buf == NULL) return False; + if (pw_buf == NULL) + return False; vp = startsmbpwent(False); if (!vp) { - DEBUG(0, ("get_sampwd_entries: Unable to open SMB password database.\n")); + DEBUG(0, + ("get_sampwd_entries: Unable to open SMB password database.\n")); return False; } - while (((pwd = getsam21pwent(vp)) != NULL) && (*num_entries) < max_num_entries) + while (((pwd = getsam21pwent(vp)) != NULL) + && (*num_entries) < max_num_entries) { int user_name_len; @@ -110,7 +113,8 @@ static BOOL get_sampwd_entries(SAM_USER_INFO_21 *pw_buf, /* skip the requested number of entries. not very efficient, but hey... */ - if (acb_mask == 0 || IS_BITS_SET_SOME(pwd->acct_ctrl, acb_mask)) + if (acb_mask == 0 + || IS_BITS_SET_SOME(pwd->acct_ctrl, acb_mask)) { start_idx--; } @@ -118,31 +122,35 @@ static BOOL get_sampwd_entries(SAM_USER_INFO_21 *pw_buf, } user_name_len = strlen(pwd->nt_name); - make_unistr2(&(pw_buf[(*num_entries)].uni_user_name), pwd->nt_name, user_name_len); - make_uni_hdr(&(pw_buf[(*num_entries)].hdr_user_name), user_name_len); + make_unistr2(&(pw_buf[(*num_entries)].uni_user_name), + pwd->nt_name, user_name_len); + make_uni_hdr(&(pw_buf[(*num_entries)].hdr_user_name), + user_name_len); pw_buf[(*num_entries)].user_rid = pwd->user_rid; - bzero( pw_buf[(*num_entries)].nt_pwd , 16); + bzero(pw_buf[(*num_entries)].nt_pwd, 16); /* Now check if the NT compatible password is available. */ if (pwd->smb_nt_passwd != NULL) { - memcpy( pw_buf[(*num_entries)].nt_pwd , pwd->smb_nt_passwd, 16); + memcpy(pw_buf[(*num_entries)].nt_pwd, + pwd->smb_nt_passwd, 16); } - pw_buf[(*num_entries)].acb_info = (uint16)pwd->acct_ctrl; + pw_buf[(*num_entries)].acb_info = (uint16) pwd->acct_ctrl; DEBUG(5, ("entry idx: %d user %s, rid 0x%x, acb %x", - (*num_entries), pwd->nt_name, - pwd->user_rid, pwd->acct_ctrl)); + (*num_entries), pwd->nt_name, + pwd->user_rid, pwd->acct_ctrl)); - if (acb_mask == 0 || IS_BITS_SET_SOME(pwd->acct_ctrl, acb_mask)) + if (acb_mask == 0 + || IS_BITS_SET_SOME(pwd->acct_ctrl, acb_mask)) { - DEBUG(5,(" acb_mask %x accepts\n", acb_mask)); + DEBUG(5, (" acb_mask %x accepts\n", acb_mask)); (*num_entries)++; } else { - DEBUG(5,(" acb_mask %x rejects\n", acb_mask)); + DEBUG(5, (" acb_mask %x rejects\n", acb_mask)); } (*total_entries)++; @@ -156,22 +164,21 @@ static BOOL get_sampwd_entries(SAM_USER_INFO_21 *pw_buf, /******************************************************************* opens a samr group by rid, returns a policy handle. ********************************************************************/ -static uint32 samr_open_by_sid( const POLICY_HND *parent_pol, - const DOM_SID *dom_sid, - POLICY_HND *pol, - uint32 access_mask, - uint32 rid) +static uint32 samr_open_by_sid(const POLICY_HND * parent_pol, + const DOM_SID * dom_sid, + POLICY_HND * pol, + uint32 access_mask, uint32 rid) { DOM_SID sid; - + /* get a (unique) handle. open a policy on it. */ if (!open_policy_hnd_link(get_global_hnd_cache(), - parent_pol, pol, access_mask)) + parent_pol, pol, access_mask)) { return NT_STATUS_ACCESS_DENIED; } - DEBUG(0,("TODO: verify that the rid exists\n")); + DEBUG(0, ("TODO: verify that the rid exists\n")); /* associate a SID with the (unique) handle. */ sid_copy(&sid, dom_sid); @@ -191,7 +198,7 @@ static uint32 samr_open_by_sid( const POLICY_HND *parent_pol, /******************************************************************* _samr_close ********************************************************************/ -uint32 _samr_close(POLICY_HND *hnd) +uint32 _samr_close(POLICY_HND * hnd) { /* close the policy handle */ if (close_policy_hnd(get_global_hnd_cache(), hnd)) @@ -204,18 +211,19 @@ uint32 _samr_close(POLICY_HND *hnd) /******************************************************************* samr_reply_unknown_2d ********************************************************************/ -uint32 _samr_unknown_2d(const POLICY_HND *domain_pol, const DOM_SID *sid) +uint32 _samr_unknown_2d(const POLICY_HND * domain_pol, const DOM_SID * sid) { DOM_SID dom_sid; /* associate the domain SID with the (unique) handle. */ - if (!get_policy_samr_sid(get_global_hnd_cache(), domain_pol, &dom_sid)) + if (!get_policy_samr_sid + (get_global_hnd_cache(), domain_pol, &dom_sid)) { return NT_STATUS_ACCESS_DENIED; } - DEBUG(0,("_samr_unknown_2d: not implemented, returning OK\n")); - DEBUG(5,("_samr_unknown_2d: %d\n", __LINE__)); + DEBUG(0, ("_samr_unknown_2d: not implemented, returning OK\n")); + DEBUG(5, ("_samr_unknown_2d: %d\n", __LINE__)); return NT_STATUS_NOPROBLEMO; } @@ -223,10 +231,9 @@ uint32 _samr_unknown_2d(const POLICY_HND *domain_pol, const DOM_SID *sid) /******************************************************************* samr_reply_open_domain ********************************************************************/ -uint32 _samr_open_domain(const POLICY_HND *connect_pol, - uint32 ace_perms, - const DOM_SID *sid, - POLICY_HND *domain_pol) +uint32 _samr_open_domain(const POLICY_HND * connect_pol, + uint32 ace_perms, + const DOM_SID * sid, POLICY_HND * domain_pol) { /* find the connection policy handle. */ if (find_policy_by_hnd(get_global_hnd_cache(), connect_pol) == -1) @@ -236,13 +243,12 @@ uint32 _samr_open_domain(const POLICY_HND *connect_pol, /* get a (unique) handle. open a policy on it. */ if (!open_policy_hnd_link(get_global_hnd_cache(), - connect_pol, domain_pol, ace_perms)) + connect_pol, domain_pol, ace_perms)) { return NT_STATUS_ACCESS_DENIED; } - policy_hnd_set_name(get_global_hnd_cache(), - domain_pol, "sam_domain"); + policy_hnd_set_name(get_global_hnd_cache(), domain_pol, "sam_domain"); /* associate the domain SID with the (unique) handle. */ if (!set_policy_samr_sid(get_global_hnd_cache(), domain_pol, sid)) @@ -251,7 +257,7 @@ uint32 _samr_open_domain(const POLICY_HND *connect_pol, return NT_STATUS_ACCESS_DENIED; } - DEBUG(5,("_samr_open_domain: %d\n", __LINE__)); + DEBUG(5, ("_samr_open_domain: %d\n", __LINE__)); return NT_STATUS_NOPROBLEMO; } @@ -259,10 +265,9 @@ uint32 _samr_open_domain(const POLICY_HND *connect_pol, /******************************************************************* samr_reply_get_usrdom_pwinfo ********************************************************************/ -uint32 _samr_get_usrdom_pwinfo(const POLICY_HND *user_pol, - uint16 *unknown_0, - uint16 *unknown_1, - uint32 *unknown_2) +uint32 _samr_get_usrdom_pwinfo(const POLICY_HND * user_pol, + uint16 * unknown_0, + uint16 * unknown_1, uint32 * unknown_2) { uint32 rid; DOM_SID sid; @@ -279,7 +284,7 @@ uint32 _samr_get_usrdom_pwinfo(const POLICY_HND *user_pol, *unknown_1 = 0x0015; *unknown_2 = 0x00000000; - DEBUG(5,("samr_get_usrdom_pwinfo: %d\n", __LINE__)); + DEBUG(5, ("samr_get_usrdom_pwinfo: %d\n", __LINE__)); return NT_STATUS_NOPROBLEMO; } @@ -287,7 +292,7 @@ uint32 _samr_get_usrdom_pwinfo(const POLICY_HND *user_pol, /******************************************************************* samr_reply_query_sec_obj ********************************************************************/ -uint32 _samr_query_sec_obj(const POLICY_HND *user_pol, SEC_DESC_BUF *buf) +uint32 _samr_query_sec_obj(const POLICY_HND * user_pol, SEC_DESC_BUF * buf) { DOM_SID usr_sid; @@ -297,7 +302,7 @@ uint32 _samr_query_sec_obj(const POLICY_HND *user_pol, SEC_DESC_BUF *buf) return NT_STATUS_INVALID_HANDLE; } - SMB_ASSERT_ARRAY(usr_sid.sub_auths, usr_sid.num_auths+1); + SMB_ASSERT_ARRAY(usr_sid.sub_auths, usr_sid.num_auths + 1); #if 0 /* maybe need another 1 or 2 (S-1-5-0x20-0x220 and S-1-5-20-0x224) */ @@ -305,13 +310,11 @@ uint32 _samr_query_sec_obj(const POLICY_HND *user_pol, SEC_DESC_BUF *buf) make_dom_sid3(&sid_stuff->sid[0], 0x035b, 0x0002, &global_sid_S_1_1); make_dom_sid3(&sid_stuff->sid[1], 0x0044, 0x0002, &usr_sid); - make_sam_sid_stuff(sid_stuff, - 0x0001, 0x8004, - 0x00000014, 0x0002, 0x0070, - 2); + make_sam_sid_stuff(sid_stuff, + 0x0001, 0x8004, 0x00000014, 0x0002, 0x0070, 2); #endif - DEBUG(5,("samr_query_sec_obj: %d\n", __LINE__)); + DEBUG(5, ("samr_query_sec_obj: %d\n", __LINE__)); return samr_make_usr_obj_sd(buf, &usr_sid); } @@ -319,9 +322,9 @@ uint32 _samr_query_sec_obj(const POLICY_HND *user_pol, SEC_DESC_BUF *buf) /******************************************************************* makes a SAM_ENTRY / UNISTR2* structure. ********************************************************************/ -static void make_samr_dom_users(SAM_ENTRY **sam, UNISTR2 **uni_acct_name, - uint32 num_sam_entries, - SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES]) +static void make_samr_dom_users(SAM_ENTRY ** sam, UNISTR2 ** uni_acct_name, + uint32 num_sam_entries, + SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES]) { uint32 i; @@ -333,12 +336,16 @@ static void make_samr_dom_users(SAM_ENTRY **sam, UNISTR2 **uni_acct_name, return; } - (*sam) = (SAM_ENTRY*)Realloc(NULL, num_sam_entries * sizeof((*sam)[0])); - (*uni_acct_name) = (UNISTR2*)Realloc(NULL, num_sam_entries * sizeof((*uni_acct_name)[0])); + (*sam) = (SAM_ENTRY *) Realloc(NULL, num_sam_entries * sizeof((*sam)[0])); + + (*uni_acct_name) = + (UNISTR2 *) Realloc(NULL, + num_sam_entries * + sizeof((*uni_acct_name)[0])); if ((*sam) == NULL || (*uni_acct_name) == NULL) { - DEBUG(0,("NULL pointers in SAMR_R_QUERY_DISPINFO\n")); + DEBUG(0, ("NULL pointers in SAMR_R_QUERY_DISPINFO\n")); return; } @@ -348,18 +355,18 @@ static void make_samr_dom_users(SAM_ENTRY **sam, UNISTR2 **uni_acct_name, pass[i].uni_user_name.uni_str_len, pass[i].user_rid); - copy_unistr2(&((*uni_acct_name)[i]), &(pass[i].uni_user_name)); + copy_unistr2(&((*uni_acct_name)[i]), + &(pass[i].uni_user_name)); } } /******************************************************************* samr_reply_enum_dom_users ********************************************************************/ -uint32 _samr_enum_dom_users( const POLICY_HND *pol, uint32 *start_idx, - uint16 acb_mask, uint16 unk_1, uint32 size, - SAM_ENTRY **sam, - UNISTR2 **uni_acct_name, - uint32 *num_sam_users) +uint32 _samr_enum_dom_users(const POLICY_HND * pol, uint32 * start_idx, + uint16 acb_mask, uint16 unk_1, uint32 size, + SAM_ENTRY ** sam, + UNISTR2 ** uni_acct_name, uint32 * num_sam_users) { SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES]; int total_entries; @@ -371,12 +378,11 @@ uint32 _samr_enum_dom_users( const POLICY_HND *pol, uint32 *start_idx, return NT_STATUS_INVALID_HANDLE; } - DEBUG(5,("samr_reply_enum_dom_users: %d\n", __LINE__)); + DEBUG(5, ("samr_reply_enum_dom_users: %d\n", __LINE__)); become_root(True); ret = get_sampwd_entries(pass, (*start_idx), &total_entries, - num_sam_users, - MAX_SAM_ENTRIES, acb_mask); + num_sam_users, MAX_SAM_ENTRIES, acb_mask); unbecome_root(True); if (!ret) { @@ -386,7 +392,7 @@ uint32 _samr_enum_dom_users( const POLICY_HND *pol, uint32 *start_idx, (*start_idx) += (*num_sam_users); make_samr_dom_users(sam, uni_acct_name, (*num_sam_users), pass); - DEBUG(5,("samr_enum_dom_users: %d\n", __LINE__)); + DEBUG(5, ("samr_enum_dom_users: %d\n", __LINE__)); return NT_STATUS_NOPROBLEMO; } @@ -394,7 +400,7 @@ uint32 _samr_enum_dom_users( const POLICY_HND *pol, uint32 *start_idx, /******************************************************************* samr_reply_add_groupmem ********************************************************************/ -uint32 _samr_add_groupmem(const POLICY_HND *pol, uint32 rid, uint32 unknown) +uint32 _samr_add_groupmem(const POLICY_HND * pol, uint32 rid, uint32 unknown) { DOM_SID group_sid; uint32 group_rid; @@ -409,14 +415,14 @@ uint32 _samr_add_groupmem(const POLICY_HND *pol, uint32 rid, uint32 unknown) sid_to_string(group_sid_str, &group_sid); sid_split_rid(&group_sid, &group_rid); - DEBUG(10,("sid is %s\n", group_sid_str)); + DEBUG(10, ("sid is %s\n", group_sid_str)); if (!sid_equal(&group_sid, &global_sam_sid)) { return NT_STATUS_NO_SUCH_GROUP; } - DEBUG(10,("lookup on Domain SID\n")); + DEBUG(10, ("lookup on Domain SID\n")); if (!add_group_member(group_rid, rid)) { @@ -429,7 +435,7 @@ uint32 _samr_add_groupmem(const POLICY_HND *pol, uint32 rid, uint32 unknown) /******************************************************************* samr_reply_del_groupmem ********************************************************************/ -uint32 _samr_del_groupmem(const POLICY_HND *pol, uint32 rid) +uint32 _samr_del_groupmem(const POLICY_HND * pol, uint32 rid) { DOM_SID group_sid; uint32 group_rid; @@ -444,13 +450,13 @@ uint32 _samr_del_groupmem(const POLICY_HND *pol, uint32 rid) sid_to_string(group_sid_str, &group_sid); sid_split_rid(&group_sid, &group_rid); - DEBUG(10,("sid is %s\n", group_sid_str)); + DEBUG(10, ("sid is %s\n", group_sid_str)); if (!sid_equal(&group_sid, &global_sam_sid)) { return NT_STATUS_NO_SUCH_GROUP; } - DEBUG(10,("lookup on Domain SID\n")); + DEBUG(10, ("lookup on Domain SID\n")); if (!del_group_member(group_rid, rid)) { @@ -463,25 +469,26 @@ uint32 _samr_del_groupmem(const POLICY_HND *pol, uint32 rid) /******************************************************************* samr_reply_add_aliasmem ********************************************************************/ -uint32 _samr_add_aliasmem(const POLICY_HND *alias_pol, const DOM_SID *sid) +uint32 _samr_add_aliasmem(const POLICY_HND * alias_pol, const DOM_SID * sid) { DOM_SID alias_sid; uint32 alias_rid; fstring alias_sid_str; /* find the policy handle. open a policy on it. */ - if (!get_policy_samr_sid(get_global_hnd_cache(), alias_pol, &alias_sid)) + if (!get_policy_samr_sid + (get_global_hnd_cache(), alias_pol, &alias_sid)) { return NT_STATUS_INVALID_HANDLE; } sid_to_string(alias_sid_str, &alias_sid); sid_split_rid(&alias_sid, &alias_rid); - DEBUG(10,("sid is %s\n", alias_sid_str)); + DEBUG(10, ("sid is %s\n", alias_sid_str)); if (sid_equal(&alias_sid, &global_sam_sid)) { - DEBUG(10,("add member on Domain SID\n")); + DEBUG(10, ("add member on Domain SID\n")); if (!add_alias_member(alias_rid, sid)) { @@ -490,7 +497,7 @@ uint32 _samr_add_aliasmem(const POLICY_HND *alias_pol, const DOM_SID *sid) } else if (sid_equal(&alias_sid, global_sid_builtin)) { - DEBUG(10,("add member on BUILTIN SID\n")); + DEBUG(10, ("add member on BUILTIN SID\n")); if (!add_builtin_member(alias_rid, sid)) { @@ -508,25 +515,26 @@ uint32 _samr_add_aliasmem(const POLICY_HND *alias_pol, const DOM_SID *sid) /******************************************************************* samr_reply_del_aliasmem ********************************************************************/ -uint32 _samr_del_aliasmem(const POLICY_HND *alias_pol, const DOM_SID *sid) +uint32 _samr_del_aliasmem(const POLICY_HND * alias_pol, const DOM_SID * sid) { DOM_SID alias_sid; uint32 alias_rid; fstring alias_sid_str; /* find the policy handle. open a policy on it. */ - if (!get_policy_samr_sid(get_global_hnd_cache(), alias_pol, &alias_sid)) + if (!get_policy_samr_sid + (get_global_hnd_cache(), alias_pol, &alias_sid)) { return NT_STATUS_INVALID_HANDLE; } sid_to_string(alias_sid_str, &alias_sid); sid_split_rid(&alias_sid, &alias_rid); - DEBUG(10,("sid is %s\n", alias_sid_str)); + DEBUG(10, ("sid is %s\n", alias_sid_str)); if (sid_equal(&alias_sid, &global_sam_sid)) { - DEBUG(10,("del member on Domain SID\n")); + DEBUG(10, ("del member on Domain SID\n")); if (!del_alias_member(alias_rid, sid)) { @@ -535,7 +543,7 @@ uint32 _samr_del_aliasmem(const POLICY_HND *alias_pol, const DOM_SID *sid) } else if (sid_equal(&alias_sid, global_sid_builtin)) { - DEBUG(10,("del member on BUILTIN SID\n")); + DEBUG(10, ("del member on BUILTIN SID\n")); if (!del_builtin_member(alias_rid, sid)) { @@ -553,12 +561,12 @@ uint32 _samr_del_aliasmem(const POLICY_HND *alias_pol, const DOM_SID *sid) /****************************************************************** makes a SAMR_R_ENUM_DOMAINS structure. ********************************************************************/ -static void make_enum_domains(SAM_ENTRY **sam, UNISTR2 **uni_dom_name, - uint32 num_sam_entries, char **doms) +static void make_enum_domains(SAM_ENTRY ** sam, UNISTR2 ** uni_dom_name, + uint32 num_sam_entries, char **doms) { uint32 i; - DEBUG(5,("make_enum_domains\n")); + DEBUG(5, ("make_enum_domains\n")); (*sam) = NULL; (*uni_dom_name) = NULL; @@ -568,12 +576,16 @@ static void make_enum_domains(SAM_ENTRY **sam, UNISTR2 **uni_dom_name, return; } - (*sam) = (SAM_ENTRY*)Realloc(NULL, num_sam_entries * sizeof((*sam)[0])); - (*uni_dom_name) = (UNISTR2*)Realloc(NULL, num_sam_entries * sizeof((*uni_dom_name)[0])); + (*sam) = (SAM_ENTRY *) Realloc(NULL, num_sam_entries * sizeof((*sam)[0])); + + (*uni_dom_name) = + (UNISTR2 *) Realloc(NULL, + num_sam_entries * + sizeof((*uni_dom_name)[0])); if ((*sam) == NULL || (*uni_dom_name) == NULL) { - DEBUG(0,("NULL pointers in make_enum_domains\n")); + DEBUG(0, ("NULL pointers in make_enum_domains\n")); return; } @@ -590,7 +602,7 @@ static void make_enum_domains(SAM_ENTRY **sam, UNISTR2 **uni_dom_name, /************************************************************************** enumerates all domains for which the SAM server is responsible ***************************************************************************/ -static BOOL enumdomains(char ***doms, uint32 *num_entries) +static BOOL enumdomains(char ***doms, uint32 * num_entries) { add_chars_to_array(num_entries, doms, global_sam_name); add_chars_to_array(num_entries, doms, "Builtin"); @@ -601,13 +613,12 @@ static BOOL enumdomains(char ***doms, uint32 *num_entries) /******************************************************************* samr_reply_enum_domains ********************************************************************/ -uint32 _samr_enum_domains(const POLICY_HND *pol, uint32 *start_idx, - uint32 size, - SAM_ENTRY **sam, - UNISTR2 **uni_acct_name, - uint32 *num_sam_users) +uint32 _samr_enum_domains(const POLICY_HND * pol, uint32 * start_idx, + uint32 size, + SAM_ENTRY ** sam, + UNISTR2 ** uni_acct_name, uint32 * num_sam_users) { - char **doms = NULL; + char **doms = NULL; uint32 num_entries = 0; /* find the connection policy handle. */ @@ -616,7 +627,7 @@ uint32 _samr_enum_domains(const POLICY_HND *pol, uint32 *start_idx, return NT_STATUS_INVALID_HANDLE; } - DEBUG(5,("samr_reply_enum_domains:\n")); + DEBUG(5, ("samr_reply_enum_domains:\n")); if (!enumdomains(&doms, &num_entries)) { @@ -636,12 +647,12 @@ uint32 _samr_enum_domains(const POLICY_HND *pol, uint32 *start_idx, /******************************************************************* makes a SAMR_R_ENUM_DOM_GROUPS structure. ********************************************************************/ -static void make_samr_dom_groups(SAM_ENTRY **sam, UNISTR2 **uni_grp_name, - uint32 num_sam_entries, DOMAIN_GRP *grps) +static void make_samr_dom_groups(SAM_ENTRY ** sam, UNISTR2 ** uni_grp_name, + uint32 num_sam_entries, DOMAIN_GRP * grps) { uint32 i; - DEBUG(5,("make_samr_dom_groups\n")); + DEBUG(5, ("make_samr_dom_groups\n")); (*sam) = NULL; (*uni_grp_name) = NULL; @@ -651,12 +662,16 @@ static void make_samr_dom_groups(SAM_ENTRY **sam, UNISTR2 **uni_grp_name, return; } - (*sam) = (SAM_ENTRY*)Realloc(NULL, num_sam_entries * sizeof((*sam)[0])); - (*uni_grp_name) = (UNISTR2*)Realloc(NULL, num_sam_entries * sizeof((*uni_grp_name)[0])); + (*sam) = (SAM_ENTRY *) Realloc(NULL, num_sam_entries * sizeof((*sam)[0])); + + (*uni_grp_name) = + (UNISTR2 *) Realloc(NULL, + num_sam_entries * + sizeof((*uni_grp_name)[0])); if ((*sam) == NULL || (*uni_grp_name) == NULL) { - DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_GROUPS\n")); + DEBUG(0, ("NULL pointers in SAMR_R_ENUM_DOM_GROUPS\n")); return; } @@ -672,11 +687,11 @@ static void make_samr_dom_groups(SAM_ENTRY **sam, UNISTR2 **uni_grp_name, /******************************************************************* samr_reply_enum_dom_groups ********************************************************************/ -uint32 _samr_enum_dom_groups(const POLICY_HND *pol, - uint32 *start_idx, uint32 size, - SAM_ENTRY **sam, - UNISTR2 **uni_acct_name, - uint32 *num_sam_groups) +uint32 _samr_enum_dom_groups(const POLICY_HND * pol, + uint32 * start_idx, uint32 size, + SAM_ENTRY ** sam, + UNISTR2 ** uni_acct_name, + uint32 * num_sam_groups) { DOMAIN_GRP *grps = NULL; int num_entries = 0; @@ -692,7 +707,7 @@ uint32 _samr_enum_dom_groups(const POLICY_HND *pol, sid_to_string(sid_str, &sid); - DEBUG(5,("samr_reply_enum_dom_groups: sid %s\n", sid_str)); + DEBUG(5, ("samr_reply_enum_dom_groups: sid %s\n", sid_str)); if (!sid_equal(&sid, &global_sam_sid)) { @@ -720,12 +735,12 @@ uint32 _samr_enum_dom_groups(const POLICY_HND *pol, /******************************************************************* makes a SAMR_R_ENUM_DOM_ALIASES structure. ********************************************************************/ -static void make_samr_dom_aliases(SAM_ENTRY **sam, UNISTR2 **uni_grp_name, - uint32 num_sam_entries, LOCAL_GRP *alss) +static void make_samr_dom_aliases(SAM_ENTRY ** sam, UNISTR2 ** uni_grp_name, + uint32 num_sam_entries, LOCAL_GRP * alss) { uint32 i; - DEBUG(5,("make_samr_r_enum_dom_aliases\n")); + DEBUG(5, ("make_samr_r_enum_dom_aliases\n")); (*sam) = NULL; (*uni_grp_name) = NULL; @@ -735,12 +750,16 @@ static void make_samr_dom_aliases(SAM_ENTRY **sam, UNISTR2 **uni_grp_name, return; } - (*sam) = (SAM_ENTRY*)Realloc(NULL, num_sam_entries * sizeof((*sam)[0])); - (*uni_grp_name) = (UNISTR2*)Realloc(NULL, num_sam_entries * sizeof((*uni_grp_name)[0])); + (*sam) = (SAM_ENTRY *) Realloc(NULL, num_sam_entries * sizeof((*sam)[0])); + + (*uni_grp_name) = + (UNISTR2 *) Realloc(NULL, + num_sam_entries * + sizeof((*uni_grp_name)[0])); if ((*sam) == NULL || (*uni_grp_name) == NULL) { - DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_ALIASES\n")); + DEBUG(0, ("NULL pointers in SAMR_R_ENUM_DOM_ALIASES\n")); return; } @@ -748,7 +767,7 @@ static void make_samr_dom_aliases(SAM_ENTRY **sam, UNISTR2 **uni_grp_name, { int len = strlen(alss[i].name); - make_sam_entry(&((*sam)[i]), len, alss[i].rid); + make_sam_entry(&((*sam)[i]), len, alss[i].rid); make_unistr2(&((*uni_grp_name)[i]), alss[i].name, len); } } @@ -756,11 +775,11 @@ static void make_samr_dom_aliases(SAM_ENTRY **sam, UNISTR2 **uni_grp_name, /******************************************************************* samr_reply_enum_dom_aliases ********************************************************************/ -uint32 _samr_enum_dom_aliases(const POLICY_HND *pol, - uint32 *start_idx, uint32 size, - SAM_ENTRY **sam, - UNISTR2 **uni_acct_name, - uint32 *num_sam_aliases) +uint32 _samr_enum_dom_aliases(const POLICY_HND * pol, + uint32 * start_idx, uint32 size, + SAM_ENTRY ** sam, + UNISTR2 ** uni_acct_name, + uint32 * num_sam_aliases) { LOCAL_GRP *alss = NULL; int num_entries = 0; @@ -775,7 +794,7 @@ uint32 _samr_enum_dom_aliases(const POLICY_HND *pol, sid_to_string(sid_str, &sid); - DEBUG(5,("samr_reply_enum_dom_aliases: sid %s\n", sid_str)); + DEBUG(5, ("samr_reply_enum_dom_aliases: sid %s\n", sid_str)); /* well-known aliases */ if (sid_equal(&sid, global_sid_builtin)) @@ -804,7 +823,7 @@ uint32 _samr_enum_dom_aliases(const POLICY_HND *pol, return NT_STATUS_ACCESS_DENIED; } } - + (*start_idx) += num_entries; (*num_sam_aliases) = num_entries; @@ -818,13 +837,12 @@ uint32 _samr_enum_dom_aliases(const POLICY_HND *pol, /******************************************************************* samr_reply_query_dispinfo ********************************************************************/ -uint32 _samr_query_dispinfo( const POLICY_HND *domain_pol, uint16 level, - uint32 start_idx, - uint32 max_entries, - uint32 max_size, - uint32 *data_size, - uint32 *num_entries, - SAM_DISPINFO_CTR *ctr) +uint32 _samr_query_dispinfo(const POLICY_HND * domain_pol, uint16 level, + uint32 start_idx, + uint32 max_entries, + uint32 max_size, + uint32 * data_size, + uint32 * num_entries, SAM_DISPINFO_CTR * ctr) { SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES]; DOMAIN_GRP *grps = NULL; @@ -833,7 +851,7 @@ uint32 _samr_query_dispinfo( const POLICY_HND *domain_pol, uint16 level, int num_sam_entries = 0; int total_entries = 0; - DEBUG(5,("samr_reply_query_dispinfo: %d\n", __LINE__)); + DEBUG(5, ("samr_reply_query_dispinfo: %d\n", __LINE__)); (*num_entries) = 0; (*data_size) = 0; @@ -841,7 +859,7 @@ uint32 _samr_query_dispinfo( const POLICY_HND *domain_pol, uint16 level, /* find the policy handle. open a policy on it. */ if (find_policy_by_hnd(get_global_hnd_cache(), domain_pol) == -1) { - DEBUG(5,("samr_reply_query_dispinfo: invalid handle\n")); + DEBUG(5, ("samr_reply_query_dispinfo: invalid handle\n")); return NT_STATUS_INVALID_HANDLE; } @@ -860,12 +878,13 @@ uint32 _samr_query_dispinfo( const POLICY_HND *domain_pol, uint16 level, become_root(True); ret = get_sampwd_entries(pass, start_idx, - &total_entries, &num_sam_entries, - MAX_SAM_ENTRIES, acb_mask); + &total_entries, + &num_sam_entries, + MAX_SAM_ENTRIES, acb_mask); unbecome_root(True); if (!ret) { - DEBUG(5,("get_sampwd_entries: failed\n")); + DEBUG(5, ("get_sampwd_entries: failed\n")); return NT_STATUS_ACCESS_DENIED; } break; @@ -883,10 +902,13 @@ uint32 _samr_query_dispinfo( const POLICY_HND *domain_pol, uint16 level, return NT_STATUS_ACCESS_DENIED; } - if (start_idx < num_sam_entries) { + if (start_idx < num_sam_entries) + { grps = sam_grps + start_idx; num_sam_entries -= start_idx; - } else { + } + else + { num_sam_entries = 0; } break; @@ -904,8 +926,8 @@ uint32 _samr_query_dispinfo( const POLICY_HND *domain_pol, uint16 level, if ((*num_entries) > MAX_SAM_ENTRIES) { (*num_entries) = MAX_SAM_ENTRIES; - DEBUG(5,("limiting number of entries to %d\n", - (*num_entries))); + DEBUG(5, ("limiting number of entries to %d\n", + (*num_entries))); } (*data_size) = max_size; @@ -961,7 +983,7 @@ uint32 _samr_query_dispinfo( const POLICY_HND *domain_pol, uint16 level, } } - DEBUG(5,("samr_reply_query_dispinfo: %d\n", __LINE__)); + DEBUG(5, ("samr_reply_query_dispinfo: %d\n", __LINE__)); safe_free(sam_grps); @@ -977,9 +999,9 @@ uint32 _samr_query_dispinfo( const POLICY_HND *domain_pol, uint16 level, /******************************************************************* samr_reply_delete_dom_user ********************************************************************/ -uint32 _samr_delete_dom_user(POLICY_HND *user_pol) +uint32 _samr_delete_dom_user(POLICY_HND * user_pol) { - DEBUG(0,("samr_delete_dom_user: not implemented\n")); + DEBUG(0, ("samr_delete_dom_user: not implemented\n")); return NT_STATUS_ACCESS_DENIED; } @@ -987,30 +1009,31 @@ uint32 _samr_delete_dom_user(POLICY_HND *user_pol) /******************************************************************* samr_reply_delete_dom_group ********************************************************************/ -uint32 _samr_delete_dom_group(POLICY_HND *group_pol) +uint32 _samr_delete_dom_group(POLICY_HND * group_pol) { DOM_SID group_sid; uint32 group_rid; fstring group_sid_str; - DEBUG(5,("samr_delete_dom_group: %d\n", __LINE__)); + DEBUG(5, ("samr_delete_dom_group: %d\n", __LINE__)); /* find the policy handle. open a policy on it. */ - if (!get_policy_samr_sid(get_global_hnd_cache(), group_pol, &group_sid)) + if (!get_policy_samr_sid + (get_global_hnd_cache(), group_pol, &group_sid)) { return NT_STATUS_INVALID_HANDLE; } sid_to_string(group_sid_str, &group_sid); sid_split_rid(&group_sid, &group_rid); - DEBUG(10,("sid is %s\n", group_sid_str)); + DEBUG(10, ("sid is %s\n", group_sid_str)); if (!sid_equal(&group_sid, &global_sam_sid)) { return NT_STATUS_NO_SUCH_GROUP; } - DEBUG(10,("lookup on Domain SID\n")); + DEBUG(10, ("lookup on Domain SID\n")); if (!del_group_entry(group_rid)) { @@ -1024,10 +1047,8 @@ uint32 _samr_delete_dom_group(POLICY_HND *group_pol) /******************************************************************* samr_reply_query_groupmem ********************************************************************/ -uint32 _samr_query_groupmem(const POLICY_HND *group_pol, - uint32 *num_mem, - uint32 **rid, - uint32 **attr) +uint32 _samr_query_groupmem(const POLICY_HND * group_pol, + uint32 * num_mem, uint32 ** rid, uint32 ** attr) { DOMAIN_GRP_MEMBER *mem_grp = NULL; DOMAIN_GRP *grp = NULL; @@ -1036,55 +1057,56 @@ uint32 _samr_query_groupmem(const POLICY_HND *group_pol, uint32 group_rid; fstring group_sid_str; - DEBUG(5,("samr_query_groupmem: %d\n", __LINE__)); + DEBUG(5, ("samr_query_groupmem: %d\n", __LINE__)); (*rid) = NULL; (*attr) = NULL; (*num_mem) = 0; /* find the policy handle. open a policy on it. */ - if (!get_policy_samr_sid(get_global_hnd_cache(), group_pol, &group_sid)) + if (!get_policy_samr_sid + (get_global_hnd_cache(), group_pol, &group_sid)) { return NT_STATUS_INVALID_HANDLE; } sid_to_string(group_sid_str, &group_sid); sid_split_rid(&group_sid, &group_rid); - DEBUG(10,("sid is %s\n", group_sid_str)); + DEBUG(10, ("sid is %s\n", group_sid_str)); if (!sid_equal(&group_sid, &global_sam_sid)) { return NT_STATUS_NO_SUCH_GROUP; } - DEBUG(10,("lookup on Domain SID\n")); + DEBUG(10, ("lookup on Domain SID\n")); become_root(True); grp = getgrouprid(group_rid, &mem_grp, &num_rids); unbecome_root(True); - if (grp == NULL) - { - return NT_STATUS_NO_SUCH_GROUP; - } + if (grp == NULL) + { + return NT_STATUS_NO_SUCH_GROUP; + } if (num_rids > 0) { - (*rid) = malloc(num_rids * sizeof(uint32)); + (*rid) = malloc(num_rids * sizeof(uint32)); (*attr) = malloc(num_rids * sizeof(uint32)); if (mem_grp != NULL && (*rid) != NULL && (*attr) != NULL) { int i; for (i = 0; i < num_rids; i++) { - (*rid) [i] = mem_grp[i].rid; + (*rid)[i] = mem_grp[i].rid; (*attr)[i] = mem_grp[i].attr; } } } safe_free(mem_grp); - + (*num_mem) = num_rids; return NT_STATUS_NOPROBLEMO; @@ -1093,9 +1115,8 @@ uint32 _samr_query_groupmem(const POLICY_HND *group_pol, /******************************************************************* samr_set_groupinfo ********************************************************************/ -uint32 _samr_set_groupinfo(const POLICY_HND *pol, - uint16 switch_level, - const GROUP_INFO_CTR* ctr) +uint32 _samr_set_groupinfo(const POLICY_HND * pol, + uint16 switch_level, const GROUP_INFO_CTR * ctr) { return NT_STATUS_ACCESS_DENIED; } @@ -1103,9 +1124,8 @@ uint32 _samr_set_groupinfo(const POLICY_HND *pol, /******************************************************************* samr_reply_query_groupinfo ********************************************************************/ -uint32 _samr_query_groupinfo(const POLICY_HND *pol, - uint16 switch_level, - GROUP_INFO_CTR* ctr) +uint32 _samr_query_groupinfo(const POLICY_HND * pol, + uint16 switch_level, GROUP_INFO_CTR * ctr) { /* find the policy handle. open a policy on it. */ if ((find_policy_by_hnd(get_global_hnd_cache(), pol) == -1)) @@ -1119,15 +1139,15 @@ uint32 _samr_query_groupinfo(const POLICY_HND *pol, { ctr->switch_value1 = 1; make_samr_group_info1(&ctr->group.info1, - "fake account name", - "fake account description", 2); + "fake account name", + "fake account description", 2); break; } case 4: { ctr->switch_value1 = 4; make_samr_group_info4(&ctr->group.info4, - "fake account description"); + "fake account description"); break; } default: @@ -1143,9 +1163,8 @@ uint32 _samr_query_groupinfo(const POLICY_HND *pol, /******************************************************************* samr_reply_query_aliasinfo ********************************************************************/ -uint32 _samr_query_aliasinfo(const POLICY_HND *alias_pol, - uint16 switch_level, - ALIAS_INFO_CTR *ctr) +uint32 _samr_query_aliasinfo(const POLICY_HND * alias_pol, + uint16 switch_level, ALIAS_INFO_CTR * ctr) { /* find the policy handle. open a policy on it. */ if ((find_policy_by_hnd(get_global_hnd_cache(), alias_pol) == -1)) @@ -1159,7 +1178,7 @@ uint32 _samr_query_aliasinfo(const POLICY_HND *alias_pol, { ctr->switch_value1 = 3; make_samr_alias_info3(&ctr->alias.info3, - "<fake account description>"); + "<fake account description>"); break; } default: @@ -1175,9 +1194,9 @@ uint32 _samr_query_aliasinfo(const POLICY_HND *alias_pol, /******************************************************************* samr_reply_query_useraliases ********************************************************************/ -uint32 _samr_query_useraliases(const POLICY_HND *pol, - const uint32 *ptr_sid, const DOM_SID2 *sid, - uint32 *num_aliases, uint32 **rid) +uint32 _samr_query_useraliases(const POLICY_HND * pol, + const uint32 * ptr_sid, const DOM_SID2 * sid, + uint32 * num_aliases, uint32 ** rid) { LOCAL_GRP *mem_grp = NULL; int num_rids = 0; @@ -1189,7 +1208,7 @@ uint32 _samr_query_useraliases(const POLICY_HND *pol, fstring dom_sid_str; fstring usr_sid_str; - DEBUG(5,("samr_query_useraliases: %d\n", __LINE__)); + DEBUG(5, ("samr_query_useraliases: %d\n", __LINE__)); (*rid) = NULL; (*num_aliases) = 0; @@ -1199,7 +1218,7 @@ uint32 _samr_query_useraliases(const POLICY_HND *pol, { return NT_STATUS_INVALID_HANDLE; } - sid_to_string(dom_sid_str, &dom_sid ); + sid_to_string(dom_sid_str, &dom_sid); sid_to_string(sam_sid_str, &global_sam_sid); usr_sid = sid[0].sid; @@ -1216,16 +1235,16 @@ uint32 _samr_query_useraliases(const POLICY_HND *pol, return NT_STATUS_NO_SUCH_USER; } - DEBUG(10,("sid is %s\n", dom_sid_str)); + DEBUG(10, ("sid is %s\n", dom_sid_str)); if (sid_equal(&dom_sid, global_sid_builtin)) { BOOL ret; - DEBUG(10,("lookup on S-1-5-20\n")); + DEBUG(10, ("lookup on S-1-5-20\n")); become_root(True); ret = getuserbuiltinntnam(sam_pass->nt_name, &mem_grp, - &num_rids); + &num_rids); unbecome_root(True); if (!ret) @@ -1236,11 +1255,11 @@ uint32 _samr_query_useraliases(const POLICY_HND *pol, else if (sid_equal(&dom_sid, &usr_sid)) { BOOL ret; - DEBUG(10,("lookup on Domain SID\n")); + DEBUG(10, ("lookup on Domain SID\n")); become_root(True); ret = getuseraliasntnam(sam_pass->nt_name, &mem_grp, - &num_rids); + &num_rids); unbecome_root(True); if (!ret) @@ -1250,7 +1269,7 @@ uint32 _samr_query_useraliases(const POLICY_HND *pol, } else { - return NT_STATUS_NO_SUCH_USER; /* no user (in domain) */ + return NT_STATUS_NO_SUCH_USER; /* no user (in domain) */ } if (num_rids > 0) @@ -1275,31 +1294,32 @@ uint32 _samr_query_useraliases(const POLICY_HND *pol, /******************************************************************* samr_reply_delete_dom_alias ********************************************************************/ -uint32 _samr_delete_dom_alias(POLICY_HND *alias_pol) +uint32 _samr_delete_dom_alias(POLICY_HND * alias_pol) { DOM_SID alias_sid; uint32 alias_rid; fstring alias_sid_str; - DEBUG(5,("samr_delete_dom_alias: %d\n", __LINE__)); + DEBUG(5, ("samr_delete_dom_alias: %d\n", __LINE__)); /* find the policy handle. open a policy on it. */ - if (!get_policy_samr_sid(get_global_hnd_cache(), alias_pol, &alias_sid)) + if (!get_policy_samr_sid + (get_global_hnd_cache(), alias_pol, &alias_sid)) { return NT_STATUS_INVALID_HANDLE; } - sid_to_string(alias_sid_str, &alias_sid ); + sid_to_string(alias_sid_str, &alias_sid); sid_split_rid(&alias_sid, &alias_rid); - DEBUG(10,("sid is %s\n", alias_sid_str)); + DEBUG(10, ("sid is %s\n", alias_sid_str)); if (!sid_equal(&alias_sid, &global_sam_sid)) { return NT_STATUS_NO_SUCH_ALIAS; } - DEBUG(10,("lookup on Domain SID\n")); + DEBUG(10, ("lookup on Domain SID\n")); if (!del_alias_entry(alias_rid)) { @@ -1313,8 +1333,8 @@ uint32 _samr_delete_dom_alias(POLICY_HND *alias_pol) /******************************************************************* samr_reply_query_aliasmem ********************************************************************/ -uint32 _samr_query_aliasmem(const POLICY_HND *alias_pol, - uint32 *num_mem, DOM_SID2 **sid) +uint32 _samr_query_aliasmem(const POLICY_HND * alias_pol, + uint32 * num_mem, DOM_SID2 ** sid) { LOCAL_GRP_MEMBER *mem_grp = NULL; LOCAL_GRP *grp = NULL; @@ -1323,24 +1343,25 @@ uint32 _samr_query_aliasmem(const POLICY_HND *alias_pol, uint32 alias_rid; fstring alias_sid_str; - DEBUG(5,("samr_query_aliasmem: %d\n", __LINE__)); + DEBUG(5, ("samr_query_aliasmem: %d\n", __LINE__)); (*sid) = NULL; (*num_mem) = 0; /* find the policy handle. open a policy on it. */ - if (!get_policy_samr_sid(get_global_hnd_cache(), alias_pol, &alias_sid)) + if (!get_policy_samr_sid + (get_global_hnd_cache(), alias_pol, &alias_sid)) { return NT_STATUS_INVALID_HANDLE; } - sid_to_string(alias_sid_str, &alias_sid ); + sid_to_string(alias_sid_str, &alias_sid); sid_split_rid(&alias_sid, &alias_rid); - DEBUG(10,("sid is %s\n", alias_sid_str)); + DEBUG(10, ("sid is %s\n", alias_sid_str)); if (sid_equal(&alias_sid, global_sid_builtin)) { - DEBUG(10,("lookup on S-1-5-20\n")); + DEBUG(10, ("lookup on S-1-5-20\n")); become_root(True); grp = getbuiltinrid(alias_rid, &mem_grp, &num_sids); @@ -1348,7 +1369,7 @@ uint32 _samr_query_aliasmem(const POLICY_HND *alias_pol, } else if (sid_equal(&alias_sid, &global_sam_sid)) { - DEBUG(10,("lookup on Domain SID\n")); + DEBUG(10, ("lookup on Domain SID\n")); become_root(True); grp = getaliasrid(alias_rid, &mem_grp, &num_sids); @@ -1390,17 +1411,14 @@ uint32 _samr_query_aliasmem(const POLICY_HND *alias_pol, /******************************************************************* samr_reply_lookup_names ********************************************************************/ -uint32 _samr_lookup_names(const POLICY_HND *pol, - - uint32 num_names1, - uint32 flags, - uint32 ptr, - const UNISTR2 *uni_name, - - uint32 *num_rids1, - uint32 rid[MAX_SAM_ENTRIES], - uint32 *num_types1, - uint32 type[MAX_SAM_ENTRIES]) +uint32 _samr_lookup_names(const POLICY_HND * pol, + uint32 num_names1, + uint32 flags, + uint32 ptr, + const UNISTR2 * uni_name, + uint32 * num_rids1, + uint32 rid[MAX_SAM_ENTRIES], + uint32 * num_types1, uint32 type[MAX_SAM_ENTRIES]) { int i; int num_rids = num_names1; @@ -1408,7 +1426,7 @@ uint32 _samr_lookup_names(const POLICY_HND *pol, fstring tmp; BOOL found_one = False; - DEBUG(5,("samr_lookup_names: %d\n", __LINE__)); + DEBUG(5, ("samr_lookup_names: %d\n", __LINE__)); if (!get_policy_samr_sid(get_global_hnd_cache(), pol, &pol_sid)) { @@ -1416,12 +1434,14 @@ uint32 _samr_lookup_names(const POLICY_HND *pol, } sid_to_string(tmp, &pol_sid); - DEBUG(5,("pol_sid: %s\n", tmp)); + DEBUG(5, ("pol_sid: %s\n", tmp)); if (num_rids > MAX_SAM_ENTRIES) { num_rids = MAX_SAM_ENTRIES; - DEBUG(5,("samr_lookup_names: truncating entries to %d\n", num_rids)); + DEBUG(5, + ("samr_lookup_names: truncating entries to %d\n", + num_rids)); } for (i = 0; i < num_rids; i++) @@ -1429,7 +1449,7 @@ uint32 _samr_lookup_names(const POLICY_HND *pol, DOM_SID sid; fstring name; uint32 status1; - unistr2_to_ascii(name, &uni_name[i], sizeof(name)-1); + unistr2_to_ascii(name, &uni_name[i], sizeof(name) - 1); status1 = lookup_name(name, &sid, &(type[i])); if (status1 == 0x0) @@ -1439,13 +1459,13 @@ uint32 _samr_lookup_names(const POLICY_HND *pol, } if ((status1 != 0x0) || !sid_equal(&pol_sid, &sid)) { - rid [i] = 0xffffffff; + rid[i] = 0xffffffff; type[i] = SID_NAME_UNKNOWN; } sid_to_string(tmp, &sid); - DEBUG(10,("name: %s sid: %s rid: %x type: %d\n", - name, tmp, rid[i], type[i])); + DEBUG(10, ("name: %s sid: %s rid: %x type: %d\n", + name, tmp, rid[i], type[i])); } if (!found_one) @@ -1462,24 +1482,23 @@ uint32 _samr_lookup_names(const POLICY_HND *pol, /******************************************************************* samr_reply_chgpasswd_user ********************************************************************/ -uint32 _samr_chgpasswd_user( const UNISTR2 *uni_dest_host, - const UNISTR2 *uni_user_name, - const char nt_newpass[516], - const uchar nt_oldhash[16], - const char lm_newpass[516], - const uchar lm_oldhash[16]) +uint32 _samr_chgpasswd_user(const UNISTR2 * uni_dest_host, + const UNISTR2 * uni_user_name, + const char nt_newpass[516], + const uchar nt_oldhash[16], + const char lm_newpass[516], + const uchar lm_oldhash[16]) { fstring user_name; fstring wks; - unistr2_to_ascii(user_name, uni_user_name, sizeof(user_name)-1); - unistr2_to_ascii(wks, uni_dest_host, sizeof(wks)-1); + unistr2_to_ascii(user_name, uni_user_name, sizeof(user_name) - 1); + unistr2_to_ascii(wks, uni_dest_host, sizeof(wks) - 1); - DEBUG(5,("samr_chgpasswd_user: user: %s wks: %s\n", user_name, wks)); + DEBUG(5, ("samr_chgpasswd_user: user: %s wks: %s\n", user_name, wks)); if (!pass_oem_change(user_name, - lm_newpass, lm_oldhash, - nt_newpass, nt_oldhash)) + lm_newpass, lm_oldhash, nt_newpass, nt_oldhash)) { return NT_STATUS_WRONG_PASSWORD; } @@ -1491,8 +1510,8 @@ uint32 _samr_chgpasswd_user( const UNISTR2 *uni_dest_host, /******************************************************************* samr_reply_get_dom_pwinfo ********************************************************************/ -uint32 _samr_get_dom_pwinfo(const UNISTR2 *uni_srv_name, - uint16 *unk_0, uint16 *unk_1, uint16 *unk_2) +uint32 _samr_get_dom_pwinfo(const UNISTR2 * uni_srv_name, + uint16 * unk_0, uint16 * unk_1, uint16 * unk_2) { /* absolutely no idea what to do, here */ *unk_0 = 0; @@ -1505,23 +1524,27 @@ uint32 _samr_get_dom_pwinfo(const UNISTR2 *uni_srv_name, /******************************************************************* makes a SAMR_R_LOOKUP_RIDS structure. ********************************************************************/ -static BOOL make_samr_lookup_rids( uint32 num_names, char *const *name, - UNIHDR **hdr_name, UNISTR2** uni_name) +static BOOL make_samr_lookup_rids(uint32 num_names, char *const *name, + UNIHDR ** hdr_name, UNISTR2 ** uni_name) { uint32 i; - if (name == NULL) return False; + if (name == NULL) + return False; *uni_name = NULL; *hdr_name = NULL; if (num_names != 0) { - (*hdr_name) = (UNIHDR*)malloc(num_names * sizeof((*hdr_name)[0])); + (*hdr_name) = (UNIHDR *) malloc(num_names * sizeof((*hdr_name)[0])); if ((*hdr_name) == NULL) { return False; } - (*uni_name) = (UNISTR2*)malloc(num_names * sizeof((*uni_name)[0])); + + (*uni_name) = + (UNISTR2 *) malloc(num_names * + sizeof((*uni_name)[0])); if ((*uni_name) == NULL) { free(*uni_name); @@ -1533,7 +1556,7 @@ static BOOL make_samr_lookup_rids( uint32 num_names, char *const *name, for (i = 0; i < num_names; i++) { int len = name[i] != NULL ? strlen(name[i]) : 0; - DEBUG(10,("name[%d]:%s\n", i, name[i])); + DEBUG(10, ("name[%d]:%s\n", i, name[i])); make_uni_hdr(&((*hdr_name)[i]), len); make_unistr2(&((*uni_name)[i]), name[i], len); } @@ -1544,19 +1567,19 @@ static BOOL make_samr_lookup_rids( uint32 num_names, char *const *name, /******************************************************************* samr_reply_lookup_rids ********************************************************************/ -uint32 _samr_lookup_rids(const POLICY_HND *pol, - uint32 num_rids, uint32 flags, - const uint32 *rids, - uint32 *num_names, - UNIHDR **hdr_name, UNISTR2** uni_name, - uint32 **types) +uint32 _samr_lookup_rids(const POLICY_HND * pol, + uint32 num_rids, uint32 flags, + const uint32 * rids, + uint32 * num_names, + UNIHDR ** hdr_name, UNISTR2 ** uni_name, + uint32 ** types) { char **grp_names = NULL; DOM_SID pol_sid; BOOL found_one = False; - int i; + int i; - DEBUG(5,("samr_lookup_rids: %d\n", __LINE__)); + DEBUG(5, ("samr_lookup_rids: %d\n", __LINE__)); /* find the policy handle. open a policy on it. */ if (find_policy_by_hnd(get_global_hnd_cache(), pol) == -1) @@ -1623,9 +1646,9 @@ uint32 _samr_lookup_rids(const POLICY_HND *pol, /******************************************************************* samr_reply_open_user ********************************************************************/ -uint32 _samr_open_user(const POLICY_HND *domain_pol, - uint32 access_mask, uint32 user_rid, - POLICY_HND *user_pol) +uint32 _samr_open_user(const POLICY_HND * domain_pol, + uint32 access_mask, uint32 user_rid, + POLICY_HND * user_pol) { struct sam_passwd *sam_pass; DOM_SID sid; @@ -1657,14 +1680,14 @@ uint32 _samr_open_user(const POLICY_HND *domain_pol, } return samr_open_by_sid(domain_pol, &sid, user_pol, - access_mask, user_rid); + access_mask, user_rid); } /************************************************************************* get_user_info_10 *************************************************************************/ -static BOOL get_user_info_10(SAM_USER_INFO_10 *id10, uint32 user_rid) +static BOOL get_user_info_10(SAM_USER_INFO_10 * id10, uint32 user_rid) { struct sam_passwd *sam_pass; @@ -1674,13 +1697,13 @@ static BOOL get_user_info_10(SAM_USER_INFO_10 *id10, uint32 user_rid) if (sam_pass == NULL) { - DEBUG(4,("User 0x%x not found\n", user_rid)); + DEBUG(4, ("User 0x%x not found\n", user_rid)); return False; } - DEBUG(3,("User:[%s]\n", sam_pass->nt_name)); + DEBUG(3, ("User:[%s]\n", sam_pass->nt_name)); - make_sam_user_info10(id10, sam_pass->acct_ctrl); + make_sam_user_info10(id10, sam_pass->acct_ctrl); return True; } @@ -1688,7 +1711,7 @@ static BOOL get_user_info_10(SAM_USER_INFO_10 *id10, uint32 user_rid) /************************************************************************* get_user_info_21 *************************************************************************/ -static BOOL get_user_info_12(SAM_USER_INFO_12 *id12, uint32 user_rid) +static BOOL get_user_info_12(SAM_USER_INFO_12 * id12, uint32 user_rid) { struct sam_passwd *sam_pass; @@ -1698,11 +1721,11 @@ static BOOL get_user_info_12(SAM_USER_INFO_12 *id12, uint32 user_rid) if (sam_pass == NULL) { - DEBUG(4,("User 0x%x not found\n", user_rid)); + DEBUG(4, ("User 0x%x not found\n", user_rid)); return False; } - DEBUG(3,("User:[%s] %x\n", sam_pass->nt_name, sam_pass->acct_ctrl)); + DEBUG(3, ("User:[%s] %x\n", sam_pass->nt_name, sam_pass->acct_ctrl)); if (IS_BITS_SET_ALL(sam_pass->acct_ctrl, ACB_DISABLED)) { @@ -1710,7 +1733,7 @@ static BOOL get_user_info_12(SAM_USER_INFO_12 *id12, uint32 user_rid) } make_sam_user_info12(id12, sam_pass->smb_passwd, - sam_pass->smb_nt_passwd); + sam_pass->smb_nt_passwd); return True; } @@ -1718,7 +1741,7 @@ static BOOL get_user_info_12(SAM_USER_INFO_12 *id12, uint32 user_rid) /************************************************************************* get_user_info_21 *************************************************************************/ -static BOOL get_user_info_21(SAM_USER_INFO_21 *id21, uint32 user_rid) +static BOOL get_user_info_21(SAM_USER_INFO_21 * id21, uint32 user_rid) { struct sam_passwd *sam_pass; LOGON_HRS hrs; @@ -1730,11 +1753,11 @@ static BOOL get_user_info_21(SAM_USER_INFO_21 *id21, uint32 user_rid) if (sam_pass == NULL) { - DEBUG(4,("User 0x%x not found\n", user_rid)); + DEBUG(4, ("User 0x%x not found\n", user_rid)); return False; } - DEBUG(3,("User:[%s]\n", sam_pass->nt_name)); + DEBUG(3, ("User:[%s]\n", sam_pass->nt_name)); /* create a LOGON_HRS structure */ hrs.len = sam_pass->hours_len; @@ -1744,35 +1767,22 @@ static BOOL get_user_info_21(SAM_USER_INFO_21 *id21, uint32 user_rid) hrs.hours[i] = sam_pass->hours[i]; } - make_sam_user_info21A(id21, - - &sam_pass->logon_time, - &sam_pass->logoff_time, - &sam_pass->kickoff_time, - &sam_pass->pass_last_set_time, - &sam_pass->pass_can_change_time, - &sam_pass->pass_must_change_time, - - sam_pass->nt_name, /* user_name */ - sam_pass->full_name, /* full_name */ - sam_pass->home_dir, /* home_dir */ - sam_pass->dir_drive, /* dir_drive */ - sam_pass->logon_script, /* logon_script */ - sam_pass->profile_path, /* profile_path */ - sam_pass->acct_desc, /* description */ - sam_pass->workstations, /* workstations user can log in from */ - sam_pass->unknown_str, /* don't know, yet */ - sam_pass->munged_dial, /* dialin info. contains dialin path and tel no */ - - sam_pass->user_rid, /* RID user_id */ - sam_pass->group_rid, /* RID group_id */ - sam_pass->acct_ctrl, - - sam_pass->unknown_3, /* unknown_3 */ - sam_pass->logon_divs, /* divisions per week */ - &hrs, /* logon hours */ - sam_pass->unknown_5, - sam_pass->unknown_6); + make_sam_user_info21A(id21, &sam_pass->logon_time, &sam_pass->logoff_time, &sam_pass->kickoff_time, &sam_pass->pass_last_set_time, &sam_pass->pass_can_change_time, &sam_pass->pass_must_change_time, sam_pass->nt_name, /* user_name */ + sam_pass->full_name, /* full_name */ + sam_pass->home_dir, /* home_dir */ + sam_pass->dir_drive, /* dir_drive */ + sam_pass->logon_script, /* logon_script */ + sam_pass->profile_path, /* profile_path */ + sam_pass->acct_desc, /* description */ + sam_pass->workstations, /* workstations user can log in from */ + sam_pass->unknown_str, /* don't know, yet */ + sam_pass->munged_dial, /* dialin info. contains dialin path and tel no */ + sam_pass->user_rid, /* RID user_id */ + sam_pass->group_rid, /* RID group_id */ + sam_pass->acct_ctrl, sam_pass->unknown_3, /* unknown_3 */ + sam_pass->logon_divs, /* divisions per week */ + &hrs, /* logon hours */ + sam_pass->unknown_5, sam_pass->unknown_6); return True; } @@ -1780,8 +1790,8 @@ static BOOL get_user_info_21(SAM_USER_INFO_21 *id21, uint32 user_rid) /******************************************************************* samr_reply_query_userinfo ********************************************************************/ -uint32 _samr_query_userinfo(const POLICY_HND *pol, uint16 switch_value, - SAM_USERINFO_CTR *ctr) +uint32 _samr_query_userinfo(const POLICY_HND * pol, uint16 switch_value, + SAM_USERINFO_CTR * ctr) { uint32 rid = 0x0; DOM_SID group_sid; @@ -1793,7 +1803,7 @@ uint32 _samr_query_userinfo(const POLICY_HND *pol, uint16 switch_value, } sid_split_rid(&group_sid, &rid); - DEBUG(5,("samr_reply_query_userinfo: rid:0x%x\n", rid)); + DEBUG(5, ("samr_reply_query_userinfo: rid:0x%x\n", rid)); /* ok! user info levels (lots: see MSDEV help), off we go... */ ctr->switch_value = switch_value; @@ -1801,8 +1811,11 @@ uint32 _samr_query_userinfo(const POLICY_HND *pol, uint16 switch_value, { case 0x10: { - ctr->info.id = (SAM_USER_INFO_10*)Realloc(NULL, - sizeof(*ctr->info.id10)); + ctr->info.id = (SAM_USER_INFO_10 *) Realloc(NULL, + sizeof + (*ctr-> + info. + id10)); if (ctr->info.id == NULL) { return NT_STATUS_NO_MEMORY; @@ -1818,26 +1831,32 @@ uint32 _samr_query_userinfo(const POLICY_HND *pol, uint16 switch_value, case 0x11: { NTTIME expire; - info = (void*)&id11; - - expire.low = 0xffffffff; + info = (void *)&id11; + + expire.low = 0xffffffff; expire.high = 0x7fffffff; - ctr->info.id = (SAM_USER_INFO_11*)Realloc(NULL, - sizeof(*ctr->info.id11)); + ctr->info.id = (SAM_USER_INFO_11 *) Realloc(NULL, + sizeof + (*ctr-> + info. + id11)); make_sam_user_info11(ctr->info.id11, &expire, - "BROOKFIELDS$", /* name */ - 0x03ef, /* user rid */ - 0x201, /* group rid */ - 0x0080); /* acb info */ + "BROOKFIELDS$", /* name */ + 0x03ef, /* user rid */ + 0x201, /* group rid */ + 0x0080); /* acb info */ break; } #endif case 0x12: { - ctr->info.id = (SAM_USER_INFO_12*)Realloc(NULL, - sizeof(*ctr->info.id12)); + ctr->info.id = (SAM_USER_INFO_12 *) Realloc(NULL, + sizeof + (*ctr-> + info. + id12)); if (ctr->info.id == NULL) { return NT_STATUS_NO_MEMORY; @@ -1850,8 +1869,11 @@ uint32 _samr_query_userinfo(const POLICY_HND *pol, uint16 switch_value, } case 21: { - ctr->info.id = (SAM_USER_INFO_21*)Realloc(NULL, - sizeof(*ctr->info.id21)); + ctr->info.id = (SAM_USER_INFO_21 *) Realloc(NULL, + sizeof + (*ctr-> + info. + id21)); if (ctr->info.id == NULL) { return NT_STATUS_NO_MEMORY; @@ -1875,7 +1897,7 @@ uint32 _samr_query_userinfo(const POLICY_HND *pol, uint16 switch_value, /******************************************************************* set_user_info_12 ********************************************************************/ -static BOOL set_user_info_12(const SAM_USER_INFO_12 *id12, uint32 rid) +static BOOL set_user_info_12(const SAM_USER_INFO_12 * id12, uint32 rid) { struct sam_passwd *pwd = getsam21pwrid(rid); struct sam_passwd new_pwd; @@ -1898,7 +1920,7 @@ static BOOL set_user_info_12(const SAM_USER_INFO_12 *id12, uint32 rid) memcpy(nt_hash, id12->nt_pwd, sizeof(nt_hash)); memcpy(lm_hash, id12->lm_pwd, sizeof(lm_hash)); - new_pwd.smb_passwd = lm_hash; + new_pwd.smb_passwd = lm_hash; new_pwd.smb_nt_passwd = nt_hash; return mod_sam21pwd_entry(&new_pwd, True); @@ -1907,7 +1929,7 @@ static BOOL set_user_info_12(const SAM_USER_INFO_12 *id12, uint32 rid) /******************************************************************* set_user_info_24 ********************************************************************/ -static BOOL set_user_info_24(const SAM_USER_INFO_24 *id24, uint32 rid) +static BOOL set_user_info_24(const SAM_USER_INFO_24 * id24, uint32 rid) { struct sam_passwd *pwd = getsam21pwrid(rid); struct sam_passwd new_pwd; @@ -1934,7 +1956,7 @@ static BOOL set_user_info_24(const SAM_USER_INFO_24 *id24, uint32 rid) nt_lm_owf_genW(&new_pw, nt_hash, lm_hash); - new_pwd.smb_passwd = lm_hash; + new_pwd.smb_passwd = lm_hash; new_pwd.smb_nt_passwd = nt_hash; return mod_sam21pwd_entry(&new_pwd, True); @@ -1943,7 +1965,7 @@ static BOOL set_user_info_24(const SAM_USER_INFO_24 *id24, uint32 rid) /******************************************************************* set_user_info_23 ********************************************************************/ -static BOOL set_user_info_23(const SAM_USER_INFO_23 *id23, uint32 rid) +static BOOL set_user_info_23(const SAM_USER_INFO_23 * id23, uint32 rid) { struct sam_passwd *pwd = getsam21pwrid(rid); struct sam_passwd new_pwd; @@ -1966,7 +1988,7 @@ static BOOL set_user_info_23(const SAM_USER_INFO_23 *id23, uint32 rid) copy_sam_passwd(&new_pwd, pwd); copy_id23_to_sam_passwd(&new_pwd, id23); - if (!decode_pw_buffer(id23->pass, (char*)new_pw.buffer, 256, &len)) + if (!decode_pw_buffer(id23->pass, (char *)new_pw.buffer, 256, &len)) { return False; } @@ -1976,7 +1998,7 @@ static BOOL set_user_info_23(const SAM_USER_INFO_23 *id23, uint32 rid) nt_lm_owf_genW(&new_pw, nt_hash, lm_hash); - new_pwd.smb_passwd = lm_hash; + new_pwd.smb_passwd = lm_hash; new_pwd.smb_nt_passwd = nt_hash; return mod_sam21pwd_entry(&new_pwd, True); @@ -1985,14 +2007,14 @@ static BOOL set_user_info_23(const SAM_USER_INFO_23 *id23, uint32 rid) /******************************************************************* samr_reply_set_userinfo ********************************************************************/ -uint32 _samr_set_userinfo(const POLICY_HND *pol, uint16 switch_value, - SAM_USERINFO_CTR *ctr) +uint32 _samr_set_userinfo(const POLICY_HND * pol, uint16 switch_value, + SAM_USERINFO_CTR * ctr) { uchar user_sess_key[16]; uint32 rid = 0x0; DOM_SID sid; - DEBUG(5,("samr_reply_set_userinfo: %d\n", __LINE__)); + DEBUG(5, ("samr_reply_set_userinfo: %d\n", __LINE__)); /* search for the handle */ if (find_policy_by_hnd(get_global_hnd_cache(), pol) == -1) @@ -2013,11 +2035,11 @@ uint32 _samr_set_userinfo(const POLICY_HND *pol, uint16 switch_value, sid_split_rid(&sid, &rid); - DEBUG(5,("samr_reply_set_userinfo: rid:0x%x\n", rid)); + DEBUG(5, ("samr_reply_set_userinfo: rid:0x%x\n", rid)); if (ctr == NULL) { - DEBUG(5,("samr_reply_set_userinfo: NULL info level\n")); + DEBUG(5, ("samr_reply_set_userinfo: NULL info level\n")); return NT_STATUS_INVALID_INFO_CLASS; } @@ -2049,7 +2071,8 @@ uint32 _samr_set_userinfo(const POLICY_HND *pol, uint16 switch_value, { SAM_USER_INFO_23 *id23 = ctr->info.id23; SamOEMhash(id23->pass, user_sess_key, 1); - dump_data_pw("pass buff:\n", id23->pass, sizeof(id23->pass)); + dump_data_pw("pass buff:\n", id23->pass, + sizeof(id23->pass)); dbgflush(); if (!set_user_info_23(id23, rid)) @@ -2071,7 +2094,7 @@ uint32 _samr_set_userinfo(const POLICY_HND *pol, uint16 switch_value, /******************************************************************* set_user_info_10 ********************************************************************/ -static BOOL set_user_info_10(const SAM_USER_INFO_10 *id10, uint32 rid) +static BOOL set_user_info_10(const SAM_USER_INFO_10 * id10, uint32 rid) { struct sam_passwd *pwd = getsam21pwrid(rid); struct sam_passwd new_pwd; @@ -2096,13 +2119,13 @@ static BOOL set_user_info_10(const SAM_USER_INFO_10 *id10, uint32 rid) /******************************************************************* samr_reply_set_userinfo2 ********************************************************************/ -uint32 _samr_set_userinfo2(const POLICY_HND *pol, uint16 switch_value, - SAM_USERINFO_CTR *ctr) +uint32 _samr_set_userinfo2(const POLICY_HND * pol, uint16 switch_value, + SAM_USERINFO_CTR * ctr) { DOM_SID sid; uint32 rid = 0x0; - DEBUG(5,("samr_reply_set_userinfo2: %d\n", __LINE__)); + DEBUG(5, ("samr_reply_set_userinfo2: %d\n", __LINE__)); /* find the policy handle. open a policy on it. */ if (!get_policy_samr_sid(get_global_hnd_cache(), pol, &sid)) @@ -2112,11 +2135,11 @@ uint32 _samr_set_userinfo2(const POLICY_HND *pol, uint16 switch_value, sid_split_rid(&sid, &rid); - DEBUG(5,("samr_reply_set_userinfo2: rid:0x%x\n", rid)); + DEBUG(5, ("samr_reply_set_userinfo2: rid:0x%x\n", rid)); if (ctr == NULL) { - DEBUG(5,("samr_reply_set_userinfo2: NULL info level\n")); + DEBUG(5, ("samr_reply_set_userinfo2: NULL info level\n")); return NT_STATUS_INVALID_INFO_CLASS; } @@ -2148,9 +2171,8 @@ uint32 _samr_set_userinfo2(const POLICY_HND *pol, uint16 switch_value, /******************************************************************* samr_reply_query_usergroups ********************************************************************/ -uint32 _samr_query_usergroups(const POLICY_HND *pol, - uint32 *num_groups, - DOM_GID **gids) +uint32 _samr_query_usergroups(const POLICY_HND * pol, + uint32 * num_groups, DOM_GID ** gids) { DOMAIN_GRP *mem_grp = NULL; struct sam_passwd *sam_pass; @@ -2158,7 +2180,7 @@ uint32 _samr_query_usergroups(const POLICY_HND *pol, uint32 rid; BOOL ret; - DEBUG(5,("samr_query_usergroups: %d\n", __LINE__)); + DEBUG(5, ("samr_query_usergroups: %d\n", __LINE__)); /* find the policy handle. open a policy on it. */ if (!get_policy_samr_sid(get_global_hnd_cache(), pol, &sid)) @@ -2200,10 +2222,10 @@ uint32 _samr_query_usergroups(const POLICY_HND *pol, /******************************************************************* _samr_create_dom_alias ********************************************************************/ -uint32 _samr_create_dom_alias(const POLICY_HND *domain_pol, - const UNISTR2 *uni_acct_name, - uint32 access_mask, - POLICY_HND *alias_pol, uint32 *rid) +uint32 _samr_create_dom_alias(const POLICY_HND * domain_pol, + const UNISTR2 * uni_acct_name, + uint32 access_mask, + POLICY_HND * alias_pol, uint32 * rid) { uint32 status; DOM_SID dom_sid; @@ -2218,7 +2240,8 @@ uint32 _samr_create_dom_alias(const POLICY_HND *domain_pol, } /* find the domain sid */ - if (!get_policy_samr_sid(get_global_hnd_cache(), domain_pol, &dom_sid)) + if (!get_policy_samr_sid + (get_global_hnd_cache(), domain_pol, &dom_sid)) { return NT_STATUS_OBJECT_TYPE_MISMATCH; } @@ -2228,13 +2251,13 @@ uint32 _samr_create_dom_alias(const POLICY_HND *domain_pol, return NT_STATUS_ACCESS_DENIED; } - unistr2_to_ascii(grp.name, uni_acct_name, sizeof(grp.name)-1); + unistr2_to_ascii(grp.name, uni_acct_name, sizeof(grp.name) - 1); fstrcpy(grp.comment, ""); *rid = grp.rid = 0xffffffff; *rid = grp.rid; status = samr_open_by_sid(domain_pol, &dom_sid, alias_pol, - access_mask, grp.rid); + access_mask, grp.rid); if (status != 0x0) { @@ -2252,10 +2275,10 @@ uint32 _samr_create_dom_alias(const POLICY_HND *domain_pol, /******************************************************************* _samr_create_dom_group ********************************************************************/ -uint32 _samr_create_dom_group(const POLICY_HND *domain_pol, - const UNISTR2 *uni_acct_name, - uint32 access_mask, - POLICY_HND *group_pol, uint32 *rid) +uint32 _samr_create_dom_group(const POLICY_HND * domain_pol, + const UNISTR2 * uni_acct_name, + uint32 access_mask, + POLICY_HND * group_pol, uint32 * rid) { uint32 status; DOM_SID dom_sid; @@ -2270,7 +2293,8 @@ uint32 _samr_create_dom_group(const POLICY_HND *domain_pol, } /* find the domain sid */ - if (!get_policy_samr_sid(get_global_hnd_cache(), domain_pol, &dom_sid)) + if (!get_policy_samr_sid + (get_global_hnd_cache(), domain_pol, &dom_sid)) { return NT_STATUS_OBJECT_TYPE_MISMATCH; } @@ -2280,14 +2304,14 @@ uint32 _samr_create_dom_group(const POLICY_HND *domain_pol, return NT_STATUS_ACCESS_DENIED; } - unistr2_to_ascii(grp.name, uni_acct_name, sizeof(grp.name)-1); + unistr2_to_ascii(grp.name, uni_acct_name, sizeof(grp.name) - 1); fstrcpy(grp.comment, ""); *rid = grp.rid = 0xffffffff; grp.attr = 0x07; *rid = grp.rid; status = samr_open_by_sid(domain_pol, &dom_sid, group_pol, - access_mask, grp.rid); + access_mask, grp.rid); if (status != 0x0) { return status; @@ -2304,14 +2328,13 @@ uint32 _samr_create_dom_group(const POLICY_HND *domain_pol, /******************************************************************* _samr_query_dom_info ********************************************************************/ -uint32 _samr_query_dom_info(const POLICY_HND *domain_pol, - uint16 switch_value, - SAM_UNK_CTR *ctr) +uint32 _samr_query_dom_info(const POLICY_HND * domain_pol, + uint16 switch_value, SAM_UNK_CTR * ctr) { /* find the policy handle. open a policy on it. */ if (find_policy_by_hnd(get_global_hnd_cache(), domain_pol) == -1) { - DEBUG(5,("samr_reply_query_dom_info: invalid handle\n")); + DEBUG(5, ("samr_reply_query_dom_info: invalid handle\n")); return NT_STATUS_INVALID_HANDLE; } @@ -2341,7 +2364,8 @@ uint32 _samr_query_dom_info(const POLICY_HND *domain_pol, { extern fstring global_sam_name; extern pstring global_myname; - make_unk_info2(&(ctr->info.inf2), global_sam_name, global_myname); + make_unk_info2(&(ctr->info.inf2), global_sam_name, + global_myname); break; } case 0x01: @@ -2361,11 +2385,11 @@ uint32 _samr_query_dom_info(const POLICY_HND *domain_pol, /******************************************************************* _samr_create_user ********************************************************************/ -uint32 _samr_create_user(const POLICY_HND *domain_pol, - const UNISTR2 *uni_username, - uint16 acb_info, uint32 access_mask, - POLICY_HND *user_pol, - uint32 *unknown_0, uint32 *user_rid) +uint32 _samr_create_user(const POLICY_HND * domain_pol, + const UNISTR2 * uni_username, + uint16 acb_info, uint32 access_mask, + POLICY_HND * user_pol, + uint32 * unknown_0, uint32 * user_rid) { DOM_SID sid; @@ -2393,7 +2417,7 @@ uint32 _samr_create_user(const POLICY_HND *domain_pol, return NT_STATUS_ACCESS_DENIED; } - unistr2_to_ascii(user_name, uni_username, sizeof(user_name)-1); + unistr2_to_ascii(user_name, uni_username, sizeof(user_name) - 1); sam_pass = getsam21pwntnam(user_name); @@ -2404,12 +2428,11 @@ uint32 _samr_create_user(const POLICY_HND *domain_pol, } if (!local_password_change(user_name, True, - acb_info | ACB_DISABLED | ACB_PWNOTREQ, 0xffff, - NULL, - err_str, sizeof(err_str), - msg_str, sizeof(msg_str))) + acb_info | ACB_DISABLED | ACB_PWNOTREQ, + 0xffff, NULL, err_str, sizeof(err_str), + msg_str, sizeof(msg_str))) { - DEBUG(0,("%s\n", err_str)); + DEBUG(0, ("%s\n", err_str)); return NT_STATUS_ACCESS_DENIED; } @@ -2424,19 +2447,18 @@ uint32 _samr_create_user(const POLICY_HND *domain_pol, *user_rid = sam_pass->user_rid; return samr_open_by_sid(domain_pol, &sid, user_pol, - access_mask, *user_rid); + access_mask, *user_rid); } /******************************************************************* _samr_connect_anon ********************************************************************/ -uint32 _samr_connect_anon(const UNISTR2 *srv_name, uint32 access_mask, - POLICY_HND *connect_pol) - +uint32 _samr_connect_anon(const UNISTR2 * srv_name, uint32 access_mask, + POLICY_HND * connect_pol) { /* get a (unique) handle. open a policy on it. */ if (!open_policy_hnd(get_global_hnd_cache(), - get_sec_ctx(), connect_pol, access_mask)) + get_sec_ctx(), connect_pol, access_mask)) { return NT_STATUS_ACCESS_DENIED; } @@ -2450,12 +2472,12 @@ uint32 _samr_connect_anon(const UNISTR2 *srv_name, uint32 access_mask, /******************************************************************* _samr_connect ********************************************************************/ -uint32 _samr_connect(const UNISTR2 *srv_name, uint32 access_mask, - POLICY_HND *connect_pol) +uint32 _samr_connect(const UNISTR2 * srv_name, uint32 access_mask, + POLICY_HND * connect_pol) { /* get a (unique) handle. open a policy on it. */ if (!open_policy_hnd(get_global_hnd_cache(), - get_sec_ctx(), connect_pol, access_mask)) + get_sec_ctx(), connect_pol, access_mask)) { return NT_STATUS_ACCESS_DENIED; } @@ -2469,9 +2491,9 @@ uint32 _samr_connect(const UNISTR2 *srv_name, uint32 access_mask, /******************************************************************* _samr_open_alias ********************************************************************/ -uint32 _samr_open_alias(const POLICY_HND *domain_pol, - uint32 access_mask, uint32 alias_rid, - POLICY_HND *alias_pol) +uint32 _samr_open_alias(const POLICY_HND * domain_pol, + uint32 access_mask, uint32 alias_rid, + POLICY_HND * alias_pol) { DOM_SID sid; @@ -2488,15 +2510,15 @@ uint32 _samr_open_alias(const POLICY_HND *domain_pol, return NT_STATUS_ACCESS_DENIED; } - return samr_open_by_sid(domain_pol, &sid, alias_pol, access_mask, alias_rid); + return samr_open_by_sid(domain_pol, &sid, alias_pol, access_mask, + alias_rid); } /******************************************************************* _samr_open_group ********************************************************************/ -uint32 _samr_open_group(const POLICY_HND *domain_pol, uint32 access_mask, - uint32 group_rid, - POLICY_HND *group_pol) +uint32 _samr_open_group(const POLICY_HND * domain_pol, uint32 access_mask, + uint32 group_rid, POLICY_HND * group_pol) { DOM_SID sid; @@ -2512,15 +2534,15 @@ uint32 _samr_open_group(const POLICY_HND *domain_pol, uint32 access_mask, return NT_STATUS_ACCESS_DENIED; } - return samr_open_by_sid(domain_pol, &sid, group_pol, access_mask, group_rid); + return samr_open_by_sid(domain_pol, &sid, group_pol, access_mask, + group_rid); } /******************************************************************* _samr_lookup_domain ********************************************************************/ -uint32 _samr_lookup_domain(const POLICY_HND *connect_pol, - const UNISTR2 *uni_domain, - DOM_SID *dom_sid) +uint32 _samr_lookup_domain(const POLICY_HND * connect_pol, + const UNISTR2 * uni_domain, DOM_SID * dom_sid) { fstring domain; @@ -2550,10 +2572,9 @@ uint32 _samr_lookup_domain(const POLICY_HND *connect_pol, BOOL pwdbsam_initialise(void) { - return initialise_password_db() && + return initialise_password_db() && initialise_sam_password_db() && initialise_passgrp_db() && initialise_group_db() && - initialise_alias_db() && - initialise_builtin_db(); + initialise_alias_db() && initialise_builtin_db(); } diff --git a/source/winregd/srv_reg_nt.c b/source/winregd/srv_reg_nt.c index 7b4e65bbf67..520ca57e628 100644 --- a/source/winregd/srv_reg_nt.c +++ b/source/winregd/srv_reg_nt.c @@ -139,8 +139,8 @@ uint32 _reg_open_entry(const POLICY_HND * pol, const UNISTR2 * uni_name, /******************************************************************* _reg_info ********************************************************************/ -uint32 _reg_info(POLICY_HND* pol, BUFFER2* buf, uint32* type) -{ +uint32 _reg_info(POLICY_HND * pol, BUFFER2 * buf, uint32 * type) +{ fstring name; if (!get_policy_reg_name(get_global_hnd_cache(), pol, name)) @@ -148,7 +148,8 @@ uint32 _reg_info(POLICY_HND* pol, BUFFER2* buf, uint32* type) return NT_STATUS_INVALID_HANDLE; } - if (strequal(name, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions")) + if (strequal + (name, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions")) { char *key; if (lp_server_role() == ROLE_DOMAIN_PDC) @@ -164,9 +165,9 @@ uint32 _reg_info(POLICY_HND* pol, BUFFER2* buf, uint32* type) } else { - return 0x2; /* Win32 status code. ick */ - } - + return 0x2; /* Win32 status code. ick */ + } + return NT_STATUS_NOPROBLEMO; } |