3 Unix SMB/Netbios implementation.
5 Pipe SMB utility routines
6 Copyright (C) Andrew Tridgell 1992-1997,
7 Copyright (C) Luke Kenneth Casson Leighton 1996-1997.
8 Copyright (C) Paul Ashton 1997.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 This file handles reply_ calls on named pipes that the server
26 makes to handle specific protocols
33 extern int DEBUGLEVEL;
35 /* this function is due to be replaced */
36 void initrpcreply(char *inbuf, char *q)
40 SCVAL(q, 0, 5); q++; /* RPC version 5 */
41 SCVAL(q, 0, 0); q++; /* minor version 0 */
42 SCVAL(q, 0, 2); q++; /* RPC response packet */
43 SCVAL(q, 0, 3); q++; /* first frag + last frag */
44 RSIVAL(q, 0, 0x10000000); q += 4; /* packed data representation */
45 RSSVAL(q, 0, 0); q += 2; /* fragment length, fill in later */
46 SSVAL(q, 0, 0); q += 2; /* authentication length */
47 callid = RIVAL(inbuf, 12);
48 RSIVAL(q, 0, callid); q += 4; /* call identifier - match incoming RPC */
49 SIVAL(q, 0, 0x18); q += 4; /* allocation hint (no idea) */
50 SSVAL(q, 0, 0); q += 2; /* presentation context identifier */
51 SCVAL(q, 0, 0); q++; /* cancel count */
52 SCVAL(q, 0, 0); q++; /* reserved */
55 /* this function is due to be replaced */
56 void endrpcreply(char *inbuf, char *q, int datalen, int rtnval, int *rlen)
58 SSVAL(q, 8, datalen + 4);
59 SIVAL(q,0x10,datalen+4-0x18); /* allocation hint */
60 SIVAL(q, datalen, rtnval);
62 { int fd; fd = open("/tmp/rpc", O_RDWR); write(fd, q, datalen + 4); }
65 /* Group and User RID username mapping function */
66 BOOL name_to_rid(char *user_name, uint32 *u_rid, uint32 *g_rid)
68 struct passwd *pw = Get_Pwnam(user_name, False);
70 if (u_rid == NULL || g_rid == NULL || user_name == NULL)
77 DEBUG(1,("Username %s is invalid on this system\n", user_name));
81 if (user_in_list(user_name, lp_domain_guest_users()))
83 *u_rid = DOMAIN_USER_RID_GUEST;
85 else if (user_in_list(user_name, lp_domain_admin_users()))
87 *u_rid = DOMAIN_USER_RID_ADMIN;
91 /* turn the unix UID into a Domain RID. this is what the posix
92 sub-system does (adds 1000 to the uid) */
93 *u_rid = (uint32)(pw->pw_uid + 1000);
96 /* absolutely no idea what to do about the unix GID to Domain RID mapping */
97 *g_rid = (uint32)(pw->pw_gid + 1000);
103 /* BIG NOTE: this function only does SIDS where the identauth is not >= 2^32 */
104 char *dom_sid_to_string(DOM_SID *sid)
106 static pstring sidstr;
109 uint32 ia = (sid->id_auth[5]) +
110 (sid->id_auth[4] << 8 ) +
111 (sid->id_auth[3] << 16) +
112 (sid->id_auth[2] << 24);
114 sprintf(sidstr, "S-%d-%d", sid->sid_rev_num, ia);
116 for (i = 0; i < sid->num_auths; i++)
118 sprintf(subauth, "-%d", sid->sub_auths[i]);
119 strcat(sidstr, subauth);
122 DEBUG(5,("dom_sid_to_string returning %s\n", sidstr));
126 int make_dom_sids(char *sids_str, DOM_SID *sids, int max_sids)
132 DEBUG(4,("make_dom_sids: %s\n", sids_str));
134 if (sids_str == NULL || *sids_str == 0) return 0;
136 for (count = 0, ptr = sids_str; next_token(&ptr, s2, NULL) && count < max_sids; count++)
138 make_dom_sid(&sids[count], s2);
144 /* array lookup of well-known RID aliases. the purpose of these escapes me.. */
145 /* XXXX this structure should not have the well-known RID groups added to it,
146 i.e the DOMAIN_GROUP_RID_ADMIN/USER/GUEST. */
154 { DOMAIN_ALIAS_RID_ADMINS , "admins" },
155 { DOMAIN_ALIAS_RID_USERS , "users" },
156 { DOMAIN_ALIAS_RID_GUESTS , "guests" },
157 { DOMAIN_ALIAS_RID_POWER_USERS , "power_users" },
159 { DOMAIN_ALIAS_RID_ACCOUNT_OPS , "account_ops" },
160 { DOMAIN_ALIAS_RID_SYSTEM_OPS , "system_ops" },
161 { DOMAIN_ALIAS_RID_PRINT_OPS , "print_ops" },
162 { DOMAIN_ALIAS_RID_BACKUP_OPS , "backup_ops" },
163 { DOMAIN_ALIAS_RID_REPLICATOR , "replicator" },
167 int make_dom_gids(char *gids_str, DOM_GID *gids)
173 DEBUG(4,("make_dom_gids: %s\n", gids_str));
175 if (gids_str == NULL || *gids_str == 0) return 0;
177 for (count = 0, ptr = gids_str; next_token(&ptr, s2, NULL) && count < LSA_MAX_GROUPS; count++)
179 /* the entries are of the form GID/ATTR, ATTR being optional.*/
184 attr = strchr(s2,'/');
185 if (attr) *attr++ = 0;
186 if (!attr || !*attr) attr = "7"; /* default value for attribute is 7 */
188 /* look up the RID string and see if we can turn it into a rid number */
189 for (i = 0; rid_lookups[i].rid_name != NULL; i++)
191 if (strequal(rid_lookups[i].rid_name, s2))
193 rid = rid_lookups[i].rid;
198 if (rid == 0) rid = atoi(s2);
202 DEBUG(1,("make_dom_gids: unknown well-known alias RID %s/%s\n",
208 gids[count].g_rid = rid;
209 gids[count].attr = atoi(attr);
211 DEBUG(5,("group id: %d attr: %d\n",
220 int create_rpc_request(uint32 call_id, uint8 op_num, char *q, int data_len)
224 make_rpc_hdr_rr(&hdr, RPC_REQUEST, call_id, data_len, op_num);
225 return smb_io_rpc_hdr_rr(False, &hdr, q, q, 4, 0) - q;
228 int create_rpc_reply(uint32 call_id, char *q, int data_len)
232 make_rpc_hdr_rr(&hdr, RPC_RESPONSE, call_id, data_len, 0);
233 return smb_io_rpc_hdr_rr(False, &hdr, q, q, 4, 0) - q;