static int rap_netshareenum(struct smb_ctx *ctx, int *entriesp, int *totalp, struct share_info **entries_listp) { int error, bufsize, i, entries, total, nreturned; struct smb_share_info_1 *rpbuf, *ep; struct share_info *entry_list, *elp; char *cp; int lbound, rbound; bufsize = 0xffe0; /* samba notes win2k bug for 65535 */ rpbuf = malloc(bufsize); if (rpbuf == NULL) return (errno); error = smb_rap_NetShareEnum(ctx, 1, rpbuf, &bufsize, &entries, &total); if (error && error != (ERROR_MORE_DATA | SMB_RAP_ERROR)) { free(rpbuf); return (error); } entry_list = malloc(entries * sizeof (struct share_info)); if (entry_list == NULL) { error = errno; free(rpbuf); return (error); } lbound = entries * (sizeof (struct smb_share_info_1)); rbound = bufsize; for (ep = rpbuf, elp = entry_list, i = 0, nreturned = 0; i < entries; i++, ep++) { elp->type = letohs(ep->shi1_type); ep->shi1_pad = '\0'; /* ensure null termination */ elp->netname = convert_wincs_to_utf8(ep->shi1_netname); if (elp->netname == NULL) continue; /* punt on this entry */ /* * Check for validity of offset. */ if (ep->shi1_remark >= lbound && ep->shi1_remark < rbound) { cp = (char *)rpbuf + ep->shi1_remark; elp->remark = convert_wincs_to_utf8(cp); } else elp->remark = NULL; elp++; nreturned++; } *entriesp = nreturned; *totalp = total; *entries_listp = entry_list; free(rpbuf); return (0); }
/* Convert to UTF8 using system code page */ char * SMBConvertFromCodePageToUTF8(const char *cpStr) { return convert_wincs_to_utf8(cpStr, getPrefsCodePage()); }