本文整理汇总了C++中SAFE_FREE函数的典型用法代码示例。如果您正苦于以下问题:C++ SAFE_FREE函数的具体用法?C++ SAFE_FREE怎么用?C++ SAFE_FREE使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SAFE_FREE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: open_sockets_smbd
//.........这里部分代码省略.........
interpret_addr(lp_socket_address()),True);
if (s == -1)
return(False);
/* ready to listen */
#ifndef _XBOX
set_socket_options(s,"SO_KEEPALIVE");
#endif
set_socket_options(s,user_socket_options);
/* Set server socket to non-blocking for the accept. */
set_blocking(s,False);
if (listen(s, SMBD_LISTEN_BACKLOG) == -1) {
DEBUG(0,("open_sockets_smbd: listen: %s\n",
strerror(errno)));
close(s);
return False;
}
fd_listenset[num_sockets] = s;
FD_SET(s,&listen_set);
maxfd = MAX( maxfd, s);
num_sockets++;
if (num_sockets >= FD_SETSIZE) {
DEBUG(0,("open_sockets_smbd: Too many sockets to bind to\n"));
return False;
}
}
}
SAFE_FREE(ports);
/* Listen to messages */
message_register(MSG_SMB_SAM_SYNC, msg_sam_sync);
message_register(MSG_SMB_SAM_REPL, msg_sam_repl);
message_register(MSG_SHUTDOWN, msg_exit_server);
message_register(MSG_SMB_FILE_RENAME, msg_file_was_renamed);
message_register(MSG_SMB_CONF_UPDATED, smb_conf_updated);
#ifdef DEVELOPER
message_register(MSG_SMB_INJECT_FAULT, msg_inject_fault);
#endif
/* now accept incoming connections - forking a new process
for each incoming connection */
DEBUG(2,("waiting for a connection\n"));
while (1) {
fd_set lfds;
int num;
/* Free up temporary memory from the main smbd. */
lp_TALLOC_FREE();
/* Ensure we respond to PING and DEBUG messages from the main smbd. */
message_dispatch();
memcpy((char *)&lfds, (char *)&listen_set,
sizeof(listen_set));
num = sys_select(maxfd+1,&lfds,NULL,NULL,NULL);
if (num == -1 && errno == EINTR) {
示例2: DlgProcIconImport
INT_PTR CALLBACK DlgProcIconImport(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
static HWND hwndParent, hwndDragOver;
static int dragging;
static int dragItem, dropHiLite;
static HWND hPreview = NULL;
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
hwndParent = (HWND)lParam;
hPreview = GetDlgItem(hwndDlg, IDC_PREVIEW);
dragging = dragItem = 0;
ListView_SetImageList(hPreview, ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32|ILC_MASK, 0, 100), LVSIL_NORMAL);
ListView_SetIconSpacing(hPreview, 56, 67);
{
RECT rcThis, rcParent;
int cxScreen = GetSystemMetrics(SM_CXSCREEN);
GetWindowRect(hwndDlg, &rcThis);
GetWindowRect(hwndParent, &rcParent);
OffsetRect(&rcThis, rcParent.right-rcThis.left, 0);
OffsetRect(&rcThis, 0, rcParent.top-rcThis.top);
GetWindowRect(GetParent(hwndParent), &rcParent);
if (rcThis.right > cxScreen) {
OffsetRect(&rcParent, cxScreen-rcThis.right, 0);
OffsetRect(&rcThis, cxScreen-rcThis.right, 0);
MoveWindow(GetParent(hwndParent), rcParent.left, rcParent.top, rcParent.right-rcParent.left, rcParent.bottom-rcParent.top, TRUE);
}
MoveWindow(hwndDlg, rcThis.left, rcThis.top, rcThis.right-rcThis.left, rcThis.bottom-rcThis.top, FALSE);
GetClientRect(hwndDlg, &rcThis);
SendMessage(hwndDlg, WM_SIZE, 0, MAKELPARAM(rcThis.right-rcThis.left, rcThis.bottom-rcThis.top));
}
SHAutoComplete( GetDlgItem(hwndDlg, IDC_ICONSET), 1);
SetDlgItemText(hwndDlg, IDC_ICONSET, _T("icons.dll"));
return TRUE;
case DM_REBUILDICONSPREVIEW:
{
MySetCursor(IDC_WAIT);
ListView_DeleteAllItems(hPreview);
HIMAGELIST hIml = ListView_GetImageList(hPreview, LVSIL_NORMAL);
ImageList_RemoveAll(hIml);
TCHAR filename[MAX_PATH], caption[64];
GetDlgItemText(hwndDlg, IDC_ICONSET, filename, SIZEOF(filename));
{
RECT rcPreview, rcGroup;
GetWindowRect(hPreview, &rcPreview);
GetWindowRect( GetDlgItem(hwndDlg, IDC_IMPORTMULTI), &rcGroup);
//SetWindowPos(hPreview, 0, 0, 0, rcPreview.right-rcPreview.left, rcGroup.bottom-rcPreview.top, SWP_NOZORDER|SWP_NOMOVE);
}
if ( _taccess(filename, 0) != 0) {
MySetCursor(IDC_ARROW);
break;
}
LVITEM lvi;
lvi.mask = LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;
lvi.iSubItem = 0;
lvi.iItem = 0;
int count = (int)_ExtractIconEx(filename, -1, 16, 16, NULL, LR_DEFAULTCOLOR);
for (int i=0; i < count; lvi.iItem++, i++) {
mir_sntprintf(caption, SIZEOF(caption), _T("%d"), i+1);
lvi.pszText = caption;
HICON hIcon;
_ExtractIconEx(filename, i, 16, 16, &hIcon, LR_DEFAULTCOLOR);
lvi.iImage = ImageList_AddIcon(hIml, hIcon);
DestroyIcon(hIcon);
lvi.lParam = i;
ListView_InsertItem(hPreview, &lvi);
}
MySetCursor(IDC_ARROW);
}
break;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDC_BROWSE:
{
TCHAR str[MAX_PATH], *file;
GetDlgItemText(hwndDlg, IDC_ICONSET, str, SIZEOF(str));
if (!(file = OpenFileDlg(GetParent(hwndDlg), str, TRUE)))
break;
SetDlgItemText(hwndDlg, IDC_ICONSET, file);
SAFE_FREE((void**)&file);
}
break;
case IDC_GETMORE:
OpenIconsPage();
break;
case IDC_ICONSET:
if (HIWORD(wParam) == EN_CHANGE)
//.........这里部分代码省略.........
示例3: refresh_connections
//.........这里部分代码省略.........
GtkTreeModel *model = GTK_TREE_MODEL (ls_conns);
void *list, *next, *listend;
char *desc; /* holds line from conntrack_print */
GtkTreeIter iter; /* points to a specific row */
char flags[2], status[8];
unsigned int xferred = 0;
struct row_pairs *row = NULL, *nextrow = NULL, top, bottom;
/* null terminate strings */
flags[1] = 0;
status[7] = 0;
/* make sure the list has been created and window is visible */
if(ls_conns) {
if (!GTK_WIDGET_VISIBLE(conns_window))
return(FALSE);
} else {
/* Columns: Flags, Host, Port, "-", Host, Port,
Proto, State, Bytes, (hidden) pointer */
ls_conns = gtk_list_store_new (10,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT,
G_TYPE_POINTER);
connections = NULL;
}
/* remove old connections */
for(row = connections; row; row = nextrow) {
nextrow = row->next;
if(conntrack_print(0, row->conn, NULL, 0) == NULL) {
/* remove row from the GTK list */
gtk_list_store_remove(GTK_LIST_STORE(ls_conns), &row->iter);
/* remove pointers from the linked-list and free */
if(row->next)
row->next->prev = row->prev;
if(row->prev)
row->prev->next = row->next;
else
connections = row->next;
free(row);
row = NULL;
}
if(row)
lastconn = row;
}
/* make sure we have a place to start searching for new rows */
if(!lastconn) {
listend = conntrack_print(0, NULL, NULL, 0);
if(listend == NULL)
return(TRUE);
} else {
listend = lastconn->conn;
}
/* allocate space for conntrack_print to pass connection data */
SAFE_CALLOC(desc, 100, sizeof(char));
/* add new connections */
for(list = conntrack_print(+1, listend, NULL, 0); list; list = next) {
next = conntrack_print(+1, list, &desc, 99);
cache = gtkui_connections_add(desc, list, &connections);
if(cache)
lastconn = cache;
}
/* find the first and last visible rows */
gtkui_connection_list_row(1, &top);
gtkui_connection_list_row(0, &bottom);
if(top.conn == NULL)
return(TRUE);
iter = top.iter; /* copy iter by value */
/* update visible part of list */
do {
/* get the conntrack pointer for this row */
gtk_tree_model_get (model, &iter, 9, &list, -1);
conntrack_print(0, list, &desc, 99);
/* extract changing values from conntrack_print string */
flags[0] = desc[0];
strncpy(status, desc+50, 7);
int i =sscanf(desc+62, "%u", &xferred);
BUG_IF(i!=1);
gtk_list_store_set (ls_conns, &iter, 0, flags, 7, status, 8, xferred, -1);
/* when we reach the bottom of the visible part, stop updating */
if(bottom.conn == list)
break;
} while(gtk_tree_model_iter_next(model, &iter));
SAFE_FREE(desc);
return(TRUE);
}
示例4: _csync_remove_dir
static int _csync_remove_dir(CSYNC *ctx, csync_file_stat_t *st) {
c_list_t *list = NULL;
char errbuf[256] = {0};
char *uri = NULL;
int rc = -1;
switch (ctx->current) {
case LOCAL_REPLICA:
if (asprintf(&uri, "%s/%s", ctx->local.uri, st->path) < 0) {
ctx->status_code = CSYNC_STATUS_MEMORY_ERROR;
return -1;
}
break;
case REMOTE_REPLICA:
if (asprintf(&uri, "%s/%s", ctx->remote.uri, st->path) < 0) {
ctx->status_code = CSYNC_STATUS_MEMORY_ERROR;
return -1;
}
break;
default:
break;
}
if (csync_vio_rmdir(ctx, uri) < 0) {
ctx->status_code = csync_errno_to_status(errno,
CSYNC_STATUS_PROPAGATE_ERROR);
switch (errno) {
case ENOMEM:
strerror_r(errno, errbuf, sizeof(errbuf));
CSYNC_LOG(CSYNC_LOG_PRIORITY_FATAL,
"dir: %s, command: rmdir, error: %s",
uri,
errbuf);
rc = -1;
break;
case ENOTEMPTY:
switch (ctx->current) {
case LOCAL_REPLICA:
list = c_list_prepend(ctx->local.list, (void *) st);
if (list == NULL) {
ctx->status_code = CSYNC_STATUS_MEMORY_ERROR;
return -1;
}
ctx->local.list = list;
break;
case REMOTE_REPLICA:
list = c_list_prepend(ctx->remote.list, (void *) st);
if (list == NULL) {
ctx->status_code = CSYNC_STATUS_MEMORY_ERROR;
return -1;
}
ctx->remote.list = list;
break;
default:
break;
}
rc = 0;
break;
default:
strerror_r(errno, errbuf, sizeof(errbuf));
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR,
"dir: %s, command: rmdir, error: %s",
uri,
errbuf);
rc = 1;
break;
}
goto out;
}
/* set instruction for the statedb merger */
st->instruction = CSYNC_INSTRUCTION_DELETED;
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "REMOVED dir: %s", uri);
rc = 0;
out:
SAFE_FREE(uri);
/* set instruction for the statedb merger */
if (rc != 0) {
st->instruction = CSYNC_INSTRUCTION_NONE;
}
return rc;
}
示例5: smb_acl_to_posix
static acl_t smb_acl_to_posix(const struct smb_acl_t *acl)
{
acl_t result;
int i;
result = acl_init(acl->count);
if (result == NULL) {
DEBUG(10, ("acl_init failed\n"));
return NULL;
}
for (i=0; i<acl->count; i++) {
const struct smb_acl_entry *entry = &acl->acl[i];
acl_entry_t e;
acl_tag_t tag;
if (acl_create_entry(&result, &e) != 0) {
DEBUG(1, ("acl_create_entry failed: %s\n",
strerror(errno)));
goto fail;
}
switch (entry->a_type) {
case SMB_ACL_USER:
tag = ACL_USER;
break;
case SMB_ACL_USER_OBJ:
tag = ACL_USER_OBJ;
break;
case SMB_ACL_GROUP:
tag = ACL_GROUP;
break;
case SMB_ACL_GROUP_OBJ:
tag = ACL_GROUP_OBJ;
break;
case SMB_ACL_OTHER:
tag = ACL_OTHER;
break;
case SMB_ACL_MASK:
tag = ACL_MASK;
break;
default:
DEBUG(1, ("Unknown tag value %d\n", entry->a_type));
goto fail;
}
if (acl_set_tag_type(e, tag) != 0) {
DEBUG(10, ("acl_set_tag_type(%d) failed: %s\n",
tag, strerror(errno)));
goto fail;
}
switch (entry->a_type) {
case SMB_ACL_USER:
if (acl_set_qualifier(e, &entry->info.user.uid) != 0) {
DEBUG(1, ("acl_set_qualifiier failed: %s\n",
strerror(errno)));
goto fail;
}
break;
case SMB_ACL_GROUP:
if (acl_set_qualifier(e, &entry->info.group.gid) != 0) {
DEBUG(1, ("acl_set_qualifiier failed: %s\n",
strerror(errno)));
goto fail;
}
break;
default: /* Shut up, compiler! :-) */
break;
}
if (smb_acl_set_mode(e, entry->a_perm) != 0) {
goto fail;
}
}
if (acl_valid(result) != 0) {
char *acl_string = sys_acl_to_text(acl, NULL);
DEBUG(0, ("smb_acl_to_posix: ACL %s is invalid for set (%s)\n",
acl_string, strerror(errno)));
SAFE_FREE(acl_string);
goto fail;
}
return result;
fail:
if (result != NULL) {
acl_free(result);
}
return NULL;
}
示例6: server_init_wininet
/*!
* @brief Initialise the HTTP(S) connection.
* @param remote Pointer to the remote instance with the HTTP(S) transport details wired in.
* @param sock Reference to the original socket FD passed to metsrv (ignored);
* @return Indication of success or failure.
*/
static BOOL server_init_wininet(Transport* transport)
{
URL_COMPONENTS bits;
wchar_t tmpHostName[URL_SIZE];
wchar_t tmpUrlPath[URL_SIZE];
HttpTransportContext* ctx = (HttpTransportContext*)transport->ctx;
dprintf("[WININET] Initialising ...");
// configure proxy
if (ctx->proxy)
{
dprintf("[DISPATCH] Configuring with proxy: %S", ctx->proxy);
ctx->internet = InternetOpenW(ctx->ua, INTERNET_OPEN_TYPE_PROXY, ctx->proxy, NULL, 0);
}
else
{
ctx->internet = InternetOpenW(ctx->ua, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
}
if (!ctx->internet)
{
dprintf("[DISPATCH] Failed InternetOpenW: %d", GetLastError());
return FALSE;
}
dprintf("[DISPATCH] Configured hInternet: 0x%.8x", ctx->internet);
// The InternetCrackUrl method was poorly designed...
ZeroMemory(tmpHostName, sizeof(tmpHostName));
ZeroMemory(tmpUrlPath, sizeof(tmpUrlPath));
ZeroMemory(&bits, sizeof(bits));
bits.dwStructSize = sizeof(bits);
bits.dwHostNameLength = URL_SIZE - 1;
bits.lpszHostName = tmpHostName;
bits.dwUrlPathLength = URL_SIZE - 1;
bits.lpszUrlPath = tmpUrlPath;
dprintf("[DISPATCH] About to crack URL: %S", transport->url);
InternetCrackUrlW(transport->url, 0, 0, &bits);
SAFE_FREE(ctx->uri);
ctx->uri = _wcsdup(tmpUrlPath);
transport->comms_last_packet = current_unix_timestamp();
dprintf("[DISPATCH] Configured URI: %S", ctx->uri);
dprintf("[DISPATCH] Host: %S Port: %u", tmpHostName, bits.nPort);
// Allocate the connection handle
ctx->connection = InternetConnectW(ctx->internet, tmpHostName, bits.nPort, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
if (!ctx->connection)
{
dprintf("[DISPATCH] Failed InternetConnect: %d", GetLastError());
return FALSE;
}
if (ctx->proxy)
{
if (ctx->proxy_user)
{
InternetSetOptionW(ctx->connection, INTERNET_OPTION_PROXY_USERNAME, ctx->proxy_user, (DWORD)wcslen(ctx->proxy_user));
}
if (ctx->proxy_pass)
{
InternetSetOptionW(ctx->connection, INTERNET_OPTION_PROXY_PASSWORD, ctx->proxy_pass, (DWORD)wcslen(ctx->proxy_pass));
}
}
dprintf("[DISPATCH] Configured hConnection: 0x%.8x", ctx->connection);
return TRUE;
}
示例7: _csync_push_file
//.........这里部分代码省略.........
if (st->size != tstat->size) {
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR,
"file: %s, error: incorrect filesize (size: %jd should be %jd)",
turi, tstat->size, st->size);
ctx->status_code = CSYNC_STATUS_FILE_SIZE_ERROR;
rc = 1;
goto out;
}
if (_push_to_tmp_first(ctx)) {
/* override original file */
ctx->replica = drep;
if (csync_vio_rename(ctx, turi, duri) < 0) {
ctx->status_code = csync_errno_to_status(errno,
CSYNC_STATUS_PROPAGATE_ERROR);
switch (errno) {
case ENOMEM:
rc = -1;
break;
default:
rc = 1;
break;
}
strerror_r(errno, errbuf, sizeof(errbuf));
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR,
"file: %s, command: rename, error: %s",
duri,
errbuf);
goto out;
}
}
/* set mode only if it is not the default mode */
if ((st->mode & 07777) != C_FILE_MODE) {
if (csync_vio_chmod(ctx, duri, st->mode) < 0) {
ctx->status_code = csync_errno_to_status(errno,
CSYNC_STATUS_PROPAGATE_ERROR);
switch (errno) {
case ENOMEM:
rc = -1;
break;
default:
rc = 1;
break;
}
strerror_r(errno, errbuf, sizeof(errbuf));
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR,
"file: %s, command: chmod, error: %s",
duri,
errbuf);
goto out;
}
}
/* set owner and group if possible */
if (ctx->pwd.euid == 0) {
csync_vio_chown(ctx, duri, st->uid, st->gid);
}
/* sync time */
times[0].tv_sec = times[1].tv_sec = st->modtime;
times[0].tv_usec = times[1].tv_usec = 0;
ctx->replica = drep;
csync_vio_utimes(ctx, duri, times);
/* set instruction for the statedb merger */
st->instruction = CSYNC_INSTRUCTION_UPDATED;
CSYNC_LOG(CSYNC_LOG_PRIORITY_DEBUG, "PUSHED file: %s", duri);
rc = 0;
out:
ctx->replica = srep;
csync_vio_close(ctx, sfp);
ctx->replica = drep;
csync_vio_close(ctx, dfp);
csync_vio_file_stat_destroy(tstat);
/* set instruction for the statedb merger */
if (rc != 0) {
st->instruction = CSYNC_INSTRUCTION_ERROR;
if (turi != NULL) {
csync_vio_unlink(ctx, turi);
}
}
SAFE_FREE(suri);
SAFE_FREE(duri);
SAFE_FREE(turi);
SAFE_FREE(tdir);
ctx->replica = rep_bak;
return rc;
}
示例8: _reg_perfcount_get_instance_info
static bool _reg_perfcount_get_instance_info(struct PERF_INSTANCE_DEFINITION *inst,
TALLOC_CTX *mem_ctx,
int instId,
struct PERF_OBJECT_TYPE *obj,
TDB_CONTEXT *names)
{
TDB_DATA key, data;
char buf[PERFCOUNT_MAX_LEN], temp[PERFCOUNT_MAX_LEN];
smb_ucs2_t *name = NULL;
int pad;
/* First grab the instance data from the data file */
memset(temp, 0, PERFCOUNT_MAX_LEN);
snprintf(temp, PERFCOUNT_MAX_LEN, "i%d", instId);
_reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, obj->ObjectNameTitleIndex, temp);
if (!_reg_perfcount_get_counter_data(key, &data)) {
DEBUG(3, ("_reg_perfcount_get_counter_data failed\n"));
return false;
}
if(data.dptr == NULL)
{
DEBUG(3, ("_reg_perfcount_get_instance_info: No instance data for instance [%s].\n",
buf));
return False;
}
inst->counter_data.ByteLength = data.dsize + sizeof(inst->counter_data.ByteLength);
inst->counter_data.data = TALLOC_REALLOC_ARRAY(mem_ctx,
inst->counter_data.data,
uint8,
data.dsize);
if(inst->counter_data.data == NULL)
return False;
memset(inst->counter_data.data, 0, data.dsize);
memcpy(inst->counter_data.data, data.dptr, data.dsize);
SAFE_FREE(data.dptr);
/* Fetch instance name */
memset(temp, 0, PERFCOUNT_MAX_LEN);
snprintf(temp, PERFCOUNT_MAX_LEN, "i%dname", instId);
_reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, obj->ObjectNameTitleIndex, temp);
data = tdb_fetch(names, key);
if(data.dptr == NULL)
{
/* Not actually an error, but possibly unintended? -- just logging FYI */
DEBUG(3, ("_reg_perfcount_get_instance_info: No instance name for instance [%s].\n",
buf));
inst->NameLength = 0;
}
else
{
memset(buf, 0, PERFCOUNT_MAX_LEN);
memcpy(buf, data.dptr, MIN(PERFCOUNT_MAX_LEN-1,data.dsize));
buf[PERFCOUNT_MAX_LEN-1] = '\0';
inst->NameLength = rpcstr_push_talloc(mem_ctx, &name, buf);
if (inst->NameLength == (uint32_t)-1 || !name) {
SAFE_FREE(data.dptr);
return False;
}
inst->data = TALLOC_REALLOC_ARRAY(mem_ctx,
inst->data,
uint8,
inst->NameLength);
if (inst->data == NULL) {
SAFE_FREE(data.dptr);
return False;
}
memcpy(inst->data, name, inst->NameLength);
SAFE_FREE(data.dptr);
}
inst->ParentObjectTitleIndex = 0;
inst->ParentObjectTitlePointer = 0;
inst->UniqueID = PERF_NO_UNIQUE_ID;
inst->NameOffset = 6 * sizeof(uint32);
inst->ByteLength = inst->NameOffset + inst->NameLength;
/* Need to be aligned on a 64-bit boundary here for counter_data */
if((pad = (inst->ByteLength % 8)))
{
pad = 8 - pad;
inst->data = TALLOC_REALLOC_ARRAY(mem_ctx,
inst->data,
uint8,
inst->NameLength + pad);
memset(inst->data + inst->NameLength, 0, pad);
inst->ByteLength += pad;
}
return True;
}
示例9: c_rmdirs
int c_rmdirs(const char *path) {
_TDIR *d;
struct _tdirent *dp;
csync_stat_t sb;
char *fname = NULL;
const _TCHAR *wfname = NULL;
const _TCHAR *wpath = c_multibyte(path);
if ((d = _topendir(wpath)) != NULL) {
while( _tstat(wpath, &sb) == 0) {
/* if we can remove the directory we're done */
if (_trmdir(path) == 0) {
break;
}
switch (errno) {
case ENOTEMPTY:
case EEXIST:
case EBADF:
break; /* continue */
default:
_tclosedir(d);
return 0;
}
while ((dp = _treaddir(d)) != NULL) {
size_t len;
/* skip '.' and '..' */
if (dp->d_name[0] == '.' &&
(dp->d_name[1] == '\0' ||
(dp->d_name[1] == '.' && dp->d_name[2] == '\0'))) {
continue;
}
len = strlen(path) + _tcslen(dp->d_name) + 2;
fname = c_malloc(len);
if (fname == NULL) {
return -1;
}
snprintf(fname, len, "%s/%s", path, dp->d_name);
wfname = c_multibyte(fname);
/* stat the file */
if (_tstat(wfname, &sb) != -1) {
#ifdef __unix__
if (S_ISDIR(sb.st_mode) && !S_ISLNK(sb.st_mode)) {
#else
if (S_ISDIR(sb.st_mode)) {
#endif
if (_trmdir(wfname) < 0) { /* can't be deleted */
if (errno == EACCES) {
_tclosedir(d);
SAFE_FREE(fname);
c_free_multibyte(wfname);
return -1;
}
c_rmdirs(fname);
}
} else {
_tunlink(wfname);
}
} /* lstat */
SAFE_FREE(fname);
c_free_multibyte(wfname);
} /* readdir */
_trewinddir(d);
}
} else {
return -1;
}
_tclosedir(d);
return 0;
}
示例10: get_doc_string
Lisp_Object
get_doc_string (Lisp_Object filepos, bool unibyte, bool definition)
{
char *from, *to, *name, *p, *p1;
int fd;
int offset;
EMACS_INT position;
Lisp_Object file, tem, pos;
ptrdiff_t count;
USE_SAFE_ALLOCA;
if (INTEGERP (filepos))
{
file = Vdoc_file_name;
pos = filepos;
}
else if (CONSP (filepos))
{
file = XCAR (filepos);
pos = XCDR (filepos);
}
else
return Qnil;
position = eabs (XINT (pos));
if (!STRINGP (Vdoc_directory))
return Qnil;
if (!STRINGP (file))
return Qnil;
/* Put the file name in NAME as a C string.
If it is relative, combine it with Vdoc_directory. */
tem = Ffile_name_absolute_p (file);
file = ENCODE_FILE (file);
Lisp_Object docdir
= NILP (tem) ? ENCODE_FILE (Vdoc_directory) : empty_unibyte_string;
ptrdiff_t docdir_sizemax = SBYTES (docdir) + 1;
#ifndef CANNOT_DUMP
docdir_sizemax = max (docdir_sizemax, sizeof sibling_etc);
#endif
name = SAFE_ALLOCA (docdir_sizemax + SBYTES (file));
lispstpcpy (lispstpcpy (name, docdir), file);
fd = emacs_open (name, O_RDONLY, 0);
if (fd < 0)
{
#ifndef CANNOT_DUMP
if (!NILP (Vpurify_flag))
{
/* Preparing to dump; DOC file is probably not installed.
So check in ../etc. */
lispstpcpy (stpcpy (name, sibling_etc), file);
fd = emacs_open (name, O_RDONLY, 0);
}
#endif
if (fd < 0)
{
SAFE_FREE ();
AUTO_STRING (cannot_open, "Cannot open doc string file \"");
AUTO_STRING (quote_nl, "\"\n");
return concat3 (cannot_open, file, quote_nl);
}
}
count = SPECPDL_INDEX ();
record_unwind_protect_int (close_file_unwind, fd);
/* Seek only to beginning of disk block. */
/* Make sure we read at least 1024 bytes before `position'
so we can check the leading text for consistency. */
offset = min (position, max (1024, position % (8 * 1024)));
if (TYPE_MAXIMUM (off_t) < position
|| lseek (fd, position - offset, 0) < 0)
error ("Position %"pI"d out of range in doc string file \"%s\"",
position, name);
/* Read the doc string into get_doc_string_buffer.
P points beyond the data just read. */
p = get_doc_string_buffer;
while (1)
{
ptrdiff_t space_left = (get_doc_string_buffer_size - 1
- (p - get_doc_string_buffer));
int nread;
/* Allocate or grow the buffer if we need to. */
if (space_left <= 0)
{
ptrdiff_t in_buffer = p - get_doc_string_buffer;
get_doc_string_buffer
= xpalloc (get_doc_string_buffer, &get_doc_string_buffer_size,
16 * 1024, -1, 1);
p = get_doc_string_buffer + in_buffer;
space_left = (get_doc_string_buffer_size - 1
- (p - get_doc_string_buffer));
}
//.........这里部分代码省略.........
示例11: _reg_perfcount_get_counter_info
static bool _reg_perfcount_get_counter_info(struct PERF_DATA_BLOCK *block,
TALLOC_CTX *mem_ctx,
int CounterIndex,
struct PERF_OBJECT_TYPE *obj,
TDB_CONTEXT *names)
{
TDB_DATA key, data;
char buf[PERFCOUNT_MAX_LEN];
size_t dsize, padding;
long int data32, dbuf[2];
int64_t data64;
uint32 counter_size;
obj->counters[obj->NumCounters].DefaultScale = 0;
dbuf[0] = dbuf[1] = 0;
padding = 0;
_reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, CounterIndex, "type");
data = tdb_fetch(names, key);
if(data.dptr == NULL)
{
DEBUG(3, ("_reg_perfcount_get_counter_info: No type data for counter [%d].\n", CounterIndex));
return False;
}
memset(buf, 0, PERFCOUNT_MAX_LEN);
memcpy(buf, data.dptr, data.dsize);
obj->counters[obj->NumCounters].CounterType = atoi(buf);
DEBUG(10, ("_reg_perfcount_get_counter_info: Got type [%d] for counter [%d].\n",
obj->counters[obj->NumCounters].CounterType, CounterIndex));
SAFE_FREE(data.dptr);
/* Fetch the actual data */
_reg_perfcount_make_key(&key, buf, PERFCOUNT_MAX_LEN, CounterIndex, "");
_reg_perfcount_get_counter_data(key, &data);
if(data.dptr == NULL)
{
DEBUG(3, ("_reg_perfcount_get_counter_info: No counter data for counter [%d].\n", CounterIndex));
return False;
}
counter_size = _reg_perfcount_get_size_field(obj->counters[obj->NumCounters].CounterType);
if(counter_size == PERF_SIZE_DWORD)
{
dsize = sizeof(data32);
memset(buf, 0, PERFCOUNT_MAX_LEN);
memcpy(buf, data.dptr, data.dsize);
data32 = strtol(buf, NULL, 0);
if((obj->counters[obj->NumCounters].CounterType & 0x00000F00) == PERF_TYPE_NUMBER)
obj->counters[obj->NumCounters].DefaultScale = _reg_perfcount_compute_scale((int64_t)data32);
else
obj->counters[obj->NumCounters].DefaultScale = 0;
dbuf[0] = data32;
padding = (dsize - (obj->counter_data.ByteLength%dsize)) % dsize;
}
else if(counter_size == PERF_SIZE_LARGE)
{
dsize = sizeof(data64);
memset(buf, 0, PERFCOUNT_MAX_LEN);
memcpy(buf, data.dptr, data.dsize);
data64 = atof(buf);
if((obj->counters[obj->NumCounters].CounterType & 0x00000F00) == PERF_TYPE_NUMBER)
obj->counters[obj->NumCounters].DefaultScale = _reg_perfcount_compute_scale(data64);
else
obj->counters[obj->NumCounters].DefaultScale = 0;
memcpy((void *)dbuf, (const void *)&data64, dsize);
padding = (dsize - (obj->counter_data.ByteLength%dsize)) % dsize;
}
else /* PERF_SIZE_VARIABLE_LEN */
{
dsize = data.dsize;
memset(buf, 0, PERFCOUNT_MAX_LEN);
memcpy(buf, data.dptr, data.dsize);
}
SAFE_FREE(data.dptr);
obj->counter_data.ByteLength += dsize + padding;
obj->counter_data.data = TALLOC_REALLOC_ARRAY(mem_ctx,
obj->counter_data.data,
uint8,
obj->counter_data.ByteLength - sizeof(uint32));
if(obj->counter_data.data == NULL)
return False;
if(dbuf[0] != 0 || dbuf[1] != 0)
{
memcpy((void *)(obj->counter_data.data +
(obj->counter_data.ByteLength - (sizeof(uint32) + dsize))),
(const void *)dbuf, dsize);
}
else
{
/* Handling PERF_SIZE_VARIABLE_LEN */
memcpy((void *)(obj->counter_data.data +
(obj->counter_data.ByteLength - (sizeof(uint32) + dsize))),
(const void *)buf, dsize);
}
obj->counters[obj->NumCounters].CounterOffset = obj->counter_data.ByteLength - dsize;
if(obj->counters[obj->NumCounters].CounterOffset % dsize != 0)
{
DEBUG(3,("Improperly aligned counter [%d]\n", obj->NumCounters));
//.........这里部分代码省略.........
示例12: cli_resolve_path
BOOL cli_resolve_path( const char *mountpt, struct cli_state *rootcli, const char *path,
struct cli_state **targetcli, pstring targetpath )
{
CLIENT_DFS_REFERRAL *refs = NULL;
size_t num_refs;
uint16 consumed;
struct cli_state *cli_ipc;
pstring fullpath, cleanpath;
int pathlen;
fstring server, share;
struct cli_state *newcli;
pstring newpath;
pstring newmount;
char *ppath;
SMB_STRUCT_STAT sbuf;
uint32 attributes;
if ( !rootcli || !path || !targetcli )
return False;
*targetcli = NULL;
/* send a trans2_query_path_info to check for a referral */
clean_path( cleanpath, path );
cli_dfs_make_full_path( fullpath, rootcli->desthost, rootcli->share, cleanpath );
/* don't bother continuing if this is not a dfs root */
if ( !rootcli->dfsroot || cli_qpathinfo_basic( rootcli, cleanpath, &sbuf, &attributes ) ) {
*targetcli = rootcli;
pstrcpy( targetpath, path );
return True;
}
/* special case where client asked for a path that does not exist */
if ( cli_dfs_check_error(rootcli, NT_STATUS_OBJECT_NAME_NOT_FOUND) ) {
*targetcli = rootcli;
pstrcpy( targetpath, path );
return True;
}
/* we got an error, check for DFS referral */
if ( !cli_dfs_check_error(rootcli, NT_STATUS_PATH_NOT_COVERED) )
return False;
/* check for the referral */
if ( !(cli_ipc = cli_cm_open( rootcli->desthost, "IPC$", False )) )
return False;
if ( !cli_dfs_get_referral(cli_ipc, fullpath, &refs, &num_refs, &consumed)
|| !num_refs )
{
return False;
}
/* just store the first referral for now
Make sure to recreate the original string including any wildcards */
cli_dfs_make_full_path( fullpath, rootcli->desthost, rootcli->share, path );
pathlen = strlen( fullpath )*2;
consumed = MIN(pathlen, consumed );
pstrcpy( targetpath, &fullpath[consumed/2] );
split_dfs_path( refs[0].dfspath, server, share );
SAFE_FREE( refs );
/* open the connection to the target path */
if ( (*targetcli = cli_cm_open(server, share, False)) == NULL ) {
d_printf("Unable to follow dfs referral [//%s/%s]\n",
server, share );
return False;
}
/* parse out the consumed mount path */
/* trim off the \server\share\ */
fullpath[consumed/2] = '\0';
dos_clean_name( fullpath );
if ((ppath = strchr_m( fullpath, '\\' )) == NULL)
return False;
if ((ppath = strchr_m( ppath+1, '\\' )) == NULL)
return False;
if ((ppath = strchr_m( ppath+1, '\\' )) == NULL)
return False;
ppath++;
pstr_sprintf( newmount, "%s\\%s", mountpt, ppath );
cli_cm_set_mntpoint( *targetcli, newmount );
/* check for another dfs referral, note that we are not
checking for loops here */
if ( !strequal( targetpath, "\\" ) ) {
//.........这里部分代码省略.........
示例13: cli_dfs_get_referral
BOOL cli_dfs_get_referral( struct cli_state *cli, const char *path,
CLIENT_DFS_REFERRAL**refs, size_t *num_refs,
uint16 *consumed)
{
unsigned int data_len = 0;
unsigned int param_len = 0;
uint16 setup = TRANSACT2_GET_DFS_REFERRAL;
char param[sizeof(pstring)+2];
pstring data;
char *rparam=NULL, *rdata=NULL;
char *p;
size_t pathlen = 2*(strlen(path)+1);
uint16 num_referrals;
CLIENT_DFS_REFERRAL *referrals = NULL;
memset(param, 0, sizeof(param));
SSVAL(param, 0, 0x03); /* max referral level */
p = ¶m[2];
p += clistr_push(cli, p, path, MIN(pathlen, sizeof(param)-2), STR_TERMINATE);
param_len = PTR_DIFF(p, param);
if (!cli_send_trans(cli, SMBtrans2,
NULL, /* name */
-1, 0, /* fid, flags */
&setup, 1, 0, /* setup, length, max */
param, param_len, 2, /* param, length, max */
(char *)&data, data_len, cli->max_xmit /* data, length, max */
)) {
return False;
}
if (!cli_receive_trans(cli, SMBtrans2,
&rparam, ¶m_len,
&rdata, &data_len)) {
return False;
}
*consumed = SVAL( rdata, 0 );
num_referrals = SVAL( rdata, 2 );
if ( num_referrals != 0 ) {
uint16 ref_version;
uint16 ref_size;
int i;
uint16 node_offset;
referrals = SMB_XMALLOC_ARRAY( CLIENT_DFS_REFERRAL, num_referrals );
/* start at the referrals array */
p = rdata+8;
for ( i=0; i<num_referrals; i++ ) {
ref_version = SVAL( p, 0 );
ref_size = SVAL( p, 2 );
node_offset = SVAL( p, 16 );
if ( ref_version != 3 ) {
p += ref_size;
continue;
}
referrals[i].proximity = SVAL( p, 8 );
referrals[i].ttl = SVAL( p, 10 );
clistr_pull( cli, referrals[i].dfspath, p+node_offset,
sizeof(referrals[i].dfspath), -1, STR_TERMINATE|STR_UNICODE );
p += ref_size;
}
}
*num_refs = num_referrals;
*refs = referrals;
SAFE_FREE(rdata);
SAFE_FREE(rparam);
return True;
}
示例14: assert
unsigned char *packet_encrypt(ssh_session session, void *data, uint32_t len) {
struct ssh_cipher_struct *crypto = NULL;
HMACCTX ctx = NULL;
char *out = NULL;
unsigned int finallen;
uint32_t seq;
enum ssh_hmac_e type;
assert(len);
assert(len);
if (!session->current_crypto) {
return NULL; /* nothing to do here */
}
if(len % session->current_crypto->in_cipher->blocksize != 0){
ssh_set_error(session, SSH_FATAL, "Cryptographic functions must be set on at least one blocksize (received %d)",len);
return NULL;
}
out = malloc(len);
if (out == NULL) {
return NULL;
}
type = session->current_crypto->out_hmac;
seq = ntohl(session->send_seq);
crypto = session->current_crypto->out_cipher;
if (crypto->set_encrypt_key(crypto, session->current_crypto->encryptkey,
session->current_crypto->encryptIV) < 0) {
SAFE_FREE(out);
return NULL;
}
if (session->version == 2) {
ctx = hmac_init(session->current_crypto->encryptMAC, hmac_digest_len(type), type);
if (ctx == NULL) {
SAFE_FREE(out);
return NULL;
}
hmac_update(ctx,(unsigned char *)&seq,sizeof(uint32_t));
hmac_update(ctx,data,len);
hmac_final(ctx,session->current_crypto->hmacbuf,&finallen);
#ifdef DEBUG_CRYPTO
ssh_print_hexa("mac: ",data,hmac_digest_len(type));
if (finallen != hmac_digest_len(type)) {
printf("Final len is %d\n",finallen);
}
ssh_print_hexa("Packet hmac", session->current_crypto->hmacbuf, hmac_digest_len(type));
#endif
}
crypto->encrypt(crypto, data, out, len);
memcpy(data, out, len);
BURN_BUFFER(out, len);
SAFE_FREE(out);
if (session->version == 2) {
return session->current_crypto->hmacbuf;
}
return NULL;
}
示例15: ssh_message_free
/**
* @brief Free a SSH message.
*
* @param[in] msg The message to release the memory.
*/
void ssh_message_free(ssh_message msg){
if (msg == NULL) {
return;
}
switch(msg->type) {
case SSH_REQUEST_AUTH:
SAFE_FREE(msg->auth_request.username);
if (msg->auth_request.password) {
memset(msg->auth_request.password, 0,
strlen(msg->auth_request.password));
SAFE_FREE(msg->auth_request.password);
}
ssh_key_free(msg->auth_request.pubkey);
break;
case SSH_REQUEST_CHANNEL_OPEN:
SAFE_FREE(msg->channel_request_open.originator);
SAFE_FREE(msg->channel_request_open.destination);
break;
case SSH_REQUEST_CHANNEL:
SAFE_FREE(msg->channel_request.TERM);
SAFE_FREE(msg->channel_request.modes);
SAFE_FREE(msg->channel_request.var_name);
SAFE_FREE(msg->channel_request.var_value);
SAFE_FREE(msg->channel_request.command);
SAFE_FREE(msg->channel_request.subsystem);
break;
case SSH_REQUEST_SERVICE:
SAFE_FREE(msg->service_request.service);
break;
case SSH_REQUEST_GLOBAL:
SAFE_FREE(msg->global_request.bind_address);
break;
}
ZERO_STRUCTP(msg);
SAFE_FREE(msg);
}