// // Get the physical size of the file. Returns smaller // size for compressed or sparse files. // static uintmax_t _get_phys_size(char *szPath, uintmax_t ui64DefaultSize) { DWORD dwLow, dwHigh=0; typedef DWORD (WINAPI *PFNGETCOMPRESSEDFILESIZE)( LPCTSTR lpFileName, LPDWORD lpFileSizeHigh ); static PFNGETCOMPRESSEDFILESIZE pfnGetCompressedFileSize; if (gbReg) { return ui64DefaultSize; } if (!DynaLoad("KERNEL32.DLL", "GetCompressedFileSizeA", &pfnGetCompressedFileSize)) { return ui64DefaultSize; // Win9x } // // Is this a stream name? // if (szPath[0] != '\0' && szPath[1] != '\0' && _mbschr(szPath+2,':') != NULL) { return ui64DefaultSize; // already computed at lower level (streams.c) } dwLow = (*pfnGetCompressedFileSize)(szPath, &dwHigh); if (dwLow == INVALID_FILE_SIZE && GetLastError() != NO_ERROR) { return ui64DefaultSize; // failed } return _to_unsigned_int64(dwLow, dwHigh); }
// Same with strchr char *FindCharInString( const char *string, int c ) { // This *should* work OK even with UTF-8, since we're only searching for // '\n' in practice. Careful if you try to use this for anything other // than ASCII characters. return (char*)_mbschr( (const unsigned char *)string, c ); }
static unsigned short at2mode( int attr, char *fname ) /****************************************************/ { unsigned short mode; char *ext; if( attr & _A_SUBDIR ) { mode = S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; } else if( attr & AT_ISCHR ) { mode = S_IFCHR; } else { mode = S_IFREG; /* determine if file is executable, very PC specific */ if( (ext = _mbschr( fname, '.' )) != NULL ) { ++ext; if( _mbscmp( ext, "EXE" ) == 0 || _mbscmp( ext, "COM" ) == 0 ) { mode |= S_IXUSR | S_IXGRP | S_IXOTH; } } } mode |= S_IRUSR | S_IRGRP | S_IROTH; if( !(attr & _A_RDONLY) ) /* if file is not read-only */ mode |= S_IWUSR | S_IWGRP | S_IWOTH; /* - indicate writeable */ return( mode ); }
_WCRTLINK unsigned char _FFAR *_NEARFAR(_mbstok_r,_fmbstok_r)( unsigned char _FFAR *str, const unsigned char _FFAR *delim, unsigned char _FFAR **ptr ) { unsigned char _FFAR * string_start; int count; int char_len; // if( !__IsDBCS ) return( strtok( str, delim ) ); if( str == NULL ) { str = *ptr; if( str == NULL ) return( NULL ); } /*** Skip characters until we reach one not in 'delim' ***/ #ifdef __FARFUNC__ while( !_fmbterm(str) && _fmbschr(delim,_fmbsnextc(str))!=NULL ) str = _fmbsinc( str ); #else while( !_mbterm(str) && _mbschr(delim,_mbsnextc(str))!=NULL ) str = _mbsinc( str ); #endif if( _NEARFAR(_mbterm,_fmbterm)(str) ) return( NULL ); string_start = str; /*** Skip characters until we reach one in 'delim' ***/ #ifdef __FARFUNC__ while( !_fmbterm(str) && _fmbschr(delim,_fmbsnextc(str))==NULL ) str = _fmbsinc( str ); #else while( !_mbterm(str) && _mbschr(delim,_mbsnextc(str))==NULL ) str = _mbsinc( str ); #endif /*** Handle the next token ***/ if( !_NEARFAR(_mbterm,_fmbterm)(str) ) { char_len = _NEARFAR(_mbclen,_fmbclen)( str ); /* get char length */ for( count=0; count<char_len; count++ ) str[count] = '\0'; /* replace delim with NULL */ str += char_len; /* start of next token */ *ptr = str; /* save next start */ return( string_start ); /* return next token start */ } else { *ptr = NULL;/* no more tokens */ return( string_start ); /* return same token */ } }
// --------------------------------------------------------------------- SInt32 WinMBCString::Find(AChar character, SInt32 startIndex /* = 0 */) const { const unsigned char* target = reinterpret_cast<const unsigned char*>(innerString.c_str() + startIndex); const unsigned char* found = _mbschr(target, static_cast<unsigned char>(character)); if (NULL == found) { return -1; } else { return found - target + startIndex; } }
/* * @implemented */ unsigned char *_mbsspnp (const unsigned char *str1, const unsigned char *str2) { int c; while ((c = _mbsnextc (str1))) { if (_mbschr (str2, c) == 0) return (unsigned char *) str1; str1 = _mbsinc ((unsigned char *) str1); } return 0; }
// // Return 1 if the path is to a server root, eg "\\server\share" // // Note: Assumes the path is already clean // (no embedded double-slashes, dots, or dot-dots) // static int _IsServerRootPath(char *szPath) { char *sz; if (gbReg) { return 0; } if (szPath[0] != '\\' || szPath[1] != '\\') { // <\\>server... return 0; } sz = &szPath[2]; if ((sz = _mbschr(sz, '\\')) == NULL) { // \\server<\>... return 1; // \\server pseudo-path (from glob) } if ((sz = _mbschr(++sz, '\\')) == NULL) { return 1; // found \\server\share or \\server\ pseudo-path } return (*(sz+1) == '\0'); // found \\server\share\ }
/* * @implemented */ size_t _mbsspn (const unsigned char *str1, const unsigned char *str2) { int c; const unsigned char *save = str1; while ((c = _mbsnextc (str1))) { if (_mbschr (str2, c) == 0) break; str1 = _mbsinc ((unsigned char *) str1); } return str1 - save; }
Bool WInitStatusLines( HINSTANCE inst ) { LOGFONT lf; TEXTMETRIC tm; HFONT old_font; HDC dc; char *status_font; char *cp; int point_size; Bool use_default; memset( &lf, 0, sizeof( LOGFONT ) ); dc = GetDC( (HWND)NULL ); lf.lfWeight = FW_BOLD; use_default = TRUE; status_font = WAllocRCString( W_STATUSFONT ); if( status_font != NULL ) { cp = (char *)_mbschr( (unsigned char const *)status_font, '.' ); if( cp != NULL ) { *cp = '\0'; strcpy( lf.lfFaceName, status_font ); cp++; point_size = atoi( cp ); use_default = FALSE; } WFreeRCString( status_font ); } if( use_default ) { strcpy( lf.lfFaceName, STATUS_FONTNAME ); point_size = STATUS_POINTSIZE; } lf.lfHeight = -MulDiv( point_size, GetDeviceCaps( dc, LOGPIXELSY ), 72 ); WStatusFont = CreateFontIndirect( &lf ); old_font = SelectObject( dc, WStatusFont ); GetTextMetrics( dc, &tm ); SelectObject( dc, old_font ); ReleaseDC( (HWND)NULL, dc ); WStatusDepth = tm.tmHeight + STATUS_LINE_PAD + VERT_BORDER * 2; StatusWndInit( inst, WStatusWndProc, 0, NULL ); return( TRUE ); }
void WdeInitEditClass( void ) { LOGBRUSH lbrush; char *text; char *cp; int point_size; Bool use_default; WdeEditBrush = GetStockObject( WHITE_BRUSH ); /* create a transparent brush */ memset( &lbrush, 0, sizeof( LOGBRUSH ) ); lbrush.lbStyle = BS_HOLLOW; WdeFormsBrush = CreateBrushIndirect( &lbrush ); if( WdeEditFont == NULL ) { use_default = TRUE; text = WdeAllocRCString( WDE_EDITWINDOWFONT ); if( text != NULL ) { cp = (char *)_mbschr( (unsigned char const *)text, '.' ); if( cp != NULL ) { *cp = '\0'; cp++; point_size = atoi( cp ); use_default = FALSE; } } if( use_default ) { WdeEditFont = WdeGetFont( "Helv", 8, FW_BOLD ); } else { WdeEditFont = WdeGetFont( text, point_size, FW_BOLD ); } if( text != NULL ) { WdeFreeRCString( text ); } } }
static BOOL _PrepReg(const char *szPath, struct find_reg *fr, DWORD dwType) { char szBuf[FILENAME_MAX]; LPSTR sz, szRoot, szKey=NULL; DWORD dwLen; if (szPath == NULL || szPath[0] != '\\') { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } // // "\*" // "\hklm\foo\*" // "\hklm\foo\baz", Use dwType to determine // if (_mbsicmp((PCUSTR)szPath, (PCUSTR)"\\*") == 0) { // "\*" fr->fr_bRootKeys = TRUE; return TRUE; } if (szPath[1] == '\0') { // "\" fr->fr_bRootKeys = TRUE; fr->fr_bEof = TRUE; // singleton return TRUE; } dwLen = strlen(szPath); if (dwLen >= FILENAME_MAX) { SetLastError(ERROR_BUFFER_OVERFLOW); return FALSE; } lstrcpyn(szBuf, szPath, FILENAME_MAX); if (szPath[dwLen-2] == '\\' && szPath[dwLen-1] == '*') { // "\foo\*" // // Truncate to "\foo" // szBuf[dwLen-2] = '\0'; dwLen -= 2; } else if (szPath[dwLen-2] == '\\' && szPath[dwLen-1] == '.') { // "\foo\." // // Truncate to "\foo", singleton // szBuf[dwLen-2] = '\0'; dwLen -= 2; fr->fr_bEof = TRUE; // singleton } else { fr->fr_bEof = TRUE; // singleton } szRoot = szBuf+1; if ((sz = (char*)_mbschr((PCUSTR)szRoot, '\\')) != NULL) { *sz = '\0'; szKey = sz+1; } if (_mbsicmp((PCUSTR)szRoot, (PCUSTR)"HKLM") == 0) { fr->fr_hRoot = HKEY_LOCAL_MACHINE; } else if (_mbsicmp((PCUSTR)szRoot, (PCUSTR)"HKEY_LOCAL_MACHINE") == 0) { fr->fr_hRoot = HKEY_LOCAL_MACHINE; } else if (_mbsicmp((PCUSTR)szRoot, (PCUSTR)"HKCU") == 0) { fr->fr_hRoot = HKEY_CURRENT_USER; } else if (_mbsicmp((PCUSTR)szRoot, (PCUSTR)"HKEY_CURRENT_USER") == 0) { fr->fr_hRoot = HKEY_CURRENT_USER; } else if (_mbsicmp((PCUSTR)szRoot, (PCUSTR)"HKU") == 0) { fr->fr_hRoot = HKEY_USERS; } else if (_mbsicmp((PCUSTR)szRoot, (PCUSTR)"HKEY_USERS") == 0) { fr->fr_hRoot = HKEY_USERS; } else if (_mbsicmp((PCUSTR)szRoot, (PCUSTR)"HKCR") == 0) { fr->fr_hRoot = HKEY_CLASSES_ROOT; } else if (_mbsicmp((PCUSTR)szRoot, (PCUSTR)"HKEY_CLASSES_ROOT") == 0) { fr->fr_hRoot = HKEY_CLASSES_ROOT; } else { SetLastError(ERROR_PATH_NOT_FOUND); return FALSE; } strcpy(fr->fr_fd.name, szRoot); if (dwType == DT_REG) { // path is to a value, not a key fr->fr_bEof = TRUE; // singleton if ((sz = (LPSTR)strrchr((PCUSTR)szKey, '\\')) == NULL) { // Single value, no key fr->fr_szValue = xstrdup(szKey); } else { *sz = '\0'; fr->fr_szKey = xstrdup(szKey); fr->fr_szValue = xstrdup(sz+1); } return TRUE; } if (szKey) { fr->fr_szKey = xstrdup(szKey); } return TRUE; }
/* * Translate foo/dir1\\dir2" \\"bar"grok --> "foo\\dir1\\dir2 \\"bargrok". */ char *PathConvert( const char *pathname, char quote ) /***************************************************/ { const unsigned char *path = (const unsigned char *)pathname; char *out; unsigned char *p; bool quoteends = FALSE; /* quote the whole filename */ bool backslash = FALSE; /* true if last char was a '\\' */ bool inquote = FALSE; /* true if inside a quoted string */ /*** Allocate a buffer for the new string (should be big enough) ***/ out = AllocMem( 2 * ( strlen( (char *)path ) + 1 + 2 ) ); p = (unsigned char *)out; /*** Determine if path contains any bizarre characters ***/ if( _mbschr( path, ' ' ) != NULL || _mbschr( path, '\t' ) != NULL || _mbschr( path, '"' ) != NULL || _mbschr( path, '\'' ) != NULL || _mbschr( path, '`' ) != NULL || _mbschr( path, quote ) != NULL ) { quoteends = TRUE; *p++ = quote; } /*** Convert the path one character at a time ***/ while( *path != '\0' ) { if( *path == '"' ) { if( inquote ) { if( backslash ) { *p++ = '"'; /* handle \" within a string */ backslash = FALSE; } else { inquote = FALSE; } } else { inquote = TRUE; } } else if( *path == '\\' ) { *p++ = '\\'; if( backslash ) { backslash = FALSE; } else { backslash = TRUE; } } else if( *path == '/' ) { if( inquote ) { *p++ = '/'; } else { *p++ = '\\'; } backslash = FALSE; } else { _mbccpy( p, path ); /* copy an ordinary character */ p = _mbsinc( p ); backslash = FALSE; } path = _mbsinc( path ); } if( quoteends ) *p++ = quote; *p++ = '\0'; return( out ); }
/*---------------------------------------------------------------------------- lstrchr() マルチバイトstrchr ----------------------------------------------------------------------------*/ LPSTR lstrchr(LPCSTR sz, CHAR ch) { return (LPSTR)_mbschr((LPBYTE)sz, (UINT)ch); }
static void output_skeleton (void) { FILE *m4_in = NULL; FILE *m4_out = NULL; char m4_in_file_name[] = "~m4_in_temp_file_XXXXXX"; char m4_out_file_name[] = "~m4_out_temp_file_XXXXXX"; // FILE *in; // int filter_fd[2]; char const *argv[10]; // pid_t pid; /* Compute the names of the package data dir and skeleton files. */ char const m4sugar[] = "m4sugar/m4sugar.m4"; char const m4bison[] = "bison.m4"; char *full_m4sugar; char *full_m4bison; char *full_skeleton; char const *p; char const *m4 = (p = getenv ("M4")) ? p : "M4"; int i = 0; char const *pkgdatadir = compute_pkgdatadir (); size_t skeleton_size = strlen (skeleton) + 1; size_t pkgdatadirlen = strlen (pkgdatadir); while (pkgdatadirlen && pkgdatadir[pkgdatadirlen - 1] == '/') pkgdatadirlen--; full_skeleton = xmalloc (pkgdatadirlen + 1 + (skeleton_size < sizeof m4sugar ? sizeof m4sugar : skeleton_size)); strncpy (full_skeleton, pkgdatadir, pkgdatadirlen); full_skeleton[pkgdatadirlen] = '/'; strcpy (full_skeleton + pkgdatadirlen + 1, m4sugar); full_m4sugar = xstrdup (full_skeleton); strcpy (full_skeleton + pkgdatadirlen + 1, m4bison); full_m4bison = xstrdup (full_skeleton); if (_mbschr (skeleton, '/')) strcpy (full_skeleton, skeleton); else strcpy (full_skeleton + pkgdatadirlen + 1, skeleton); /* Test whether m4sugar.m4 is readable, to check for proper installation. A faulty installation can cause deadlock, so a cheap sanity check is worthwhile. */ xfclose (xfopen (full_m4sugar, "r")); /* Create an m4 subprocess connected to us via two pipes. */ if (trace_flag & trace_tools) fprintf (stderr, "running: %s %s - %s %s\n", m4, full_m4sugar, full_m4bison, full_skeleton); /* Some future version of GNU M4 (most likely 1.6) may treat the -dV in a position-dependent manner. Keep it as the first argument so that all files are traced. See the thread starting at <http://lists.gnu.org/archive/html/bug-bison/2008-07/msg00000.html> for details. */ { argv[i++] = m4; /* When POSIXLY_CORRECT is set, GNU M4 1.6 and later disable GNU extensions, which Bison's skeletons depend on. With older M4, it has no effect. M4 1.4.12 added a -g/--gnu command-line option to make it explicit that a program wants GNU M4 extensions even when POSIXLY_CORRECT is set. See the thread starting at <http://lists.gnu.org/archive/html/bug-bison/2008-07/msg00000.html> for details. */ // if (*M4_GNU_OPTION) // argv[i++] = M4_GNU_OPTION; argv[i++] = "-I"; argv[i++] = pkgdatadir; if (trace_flag & trace_m4) argv[i++] = "-dV"; argv[i++] = full_m4sugar; argv[i++] = "-"; argv[i++] = full_m4bison; argv[i++] = full_skeleton; argv[i++] = NULL; aver (i <= ARRAY_CARDINALITY (argv)); /* The ugly cast is because gnulib gets the const-ness wrong. */ // pid = create_pipe_bidi ("m4", m4, (char **)(void*)argv, false, true, // true, filter_fd); } if (trace_flag & trace_muscles) muscles_output (stderr); { m4_in = mkstempFILE(m4_in_file_name, "w+"); if (!m4_in) error (EXIT_FAILURE, get_errno (), "fopen"); muscles_output (m4_in); fflush(m4_in); if (fseek(m4_in, 0, SEEK_SET)) error (EXIT_FAILURE, get_errno (), "fseek"); } /* Read and process m4's output. */ { m4_out = mkstempFILE(m4_out_file_name, "w+"); if (!m4_out) error (EXIT_FAILURE, get_errno (), "fopen"); } if (main_m4(i-1, argv, m4_in, m4_out)) error (EXIT_FAILURE, get_errno (), "m4 failed"); free (full_m4sugar); free (full_m4bison); free (full_skeleton); fflush(m4_out); if (fseek(m4_out, 0, SEEK_SET)) error (EXIT_FAILURE, get_errno (), "fseek"); timevar_push (TV_M4); // in = fdopen (filter_fd[0], "r"); // if (! in) // error (EXIT_FAILURE, get_errno (), // "fdopen"); scan_skel (m4_out); /* scan_skel should have read all of M4's output. Otherwise, when we close the pipe, we risk letting M4 report a broken-pipe to the Bison user. */ aver (feof (m4_out)); xfclose (m4_in); xfclose (m4_out); _unlink (m4_in_file_name); _unlink (m4_out_file_name); // wait_subprocess (pid, "m4", false, false, true, true, NULL); timevar_pop (TV_M4); }
int passwd (int argc, char **argv) { int c; int err = 0; char *typed_password = NULL, *typed_password2 = NULL; const char *username, *user; passwd_entry *passnode; char *linebuf = NULL; char *real_user = NULL; char *password_domain = NULL; int adduser=0,deluser=0,disableuser=0,realuser=0,remove_realuser=0,use_domain=0; int arg_specified = 0; if (argc == -1) usage (passwd_usage); optind = 0; while ((c = getopt (argc, argv, "axXr:RD:")) != -1) { switch (c) { case 'a': if(arg_specified) usage (passwd_usage); arg_specified = 1; adduser = 1; break; case 'x': if(arg_specified) usage (passwd_usage); arg_specified = 1; disableuser = 1; break; case 'X': if(arg_specified) usage (passwd_usage); arg_specified = 1; deluser = 1; break; case 'r': realuser = 1; real_user = xstrdup(optarg); break; case 'R': remove_realuser = 1; break; case 'D': use_domain = 1; password_domain = xstrdup(optarg); break; case '?': default: usage (passwd_usage); break; } } argc -= optind; argv += optind; if(!argc) user = NULL; else user=argv[0]; #ifdef CLIENT_SUPPORT if (current_parsed_root->isremote) { if (argc > 1) usage (passwd_usage); if (!supported_request ("passwd")) error (1, 0, "server does not support passwd"); if(!user && adduser) { error(1,0,"You cannot add yourself"); } if(!user && deluser) { error(1,0,"You cannot delete yourself"); } if(user || current_parsed_root->username || current_parsed_root->hostname) { printf ("%s %s@%s\n", (adduser) ? "Adding user" : (deluser) ? "Deleting user" : "Changing repository password for", user?user:current_parsed_root->username?current_parsed_root->username:getcaller(),current_parsed_root->hostname); } else { printf ("Changing repository password for %s\n",getcaller()); } fflush (stdout); if(!use_domain && !deluser && !disableuser) { typed_password = getpass ("New password: "******"Verify password: "******"Passwords do not match, try again"); } memset (typed_password2, 0, strlen (typed_password2)); typed_password = xrealloc(typed_password, strlen(typed_password) +32); if(strlen(typed_password)) crypt_password(typed_password); } if (adduser) send_arg ("-a"); if (disableuser) send_arg ("-x"); if (deluser) send_arg ("-X"); if (realuser) { send_arg ("-r"); send_arg (real_user); } if (remove_realuser) send_arg ("-R"); if(use_domain) { send_arg ("-D"); send_arg (password_domain); } if (argc == 1) send_arg(user); else send_arg("*"); if(typed_password) { send_arg (typed_password); /* Send the new password */ memset (typed_password, 0, strlen (typed_password)); xfree (typed_password); } send_to_server ("passwd\012", 0); return get_responses_and_close (); } if(!server_active) #endif { if(argc!=0 && argc!=1) usage (passwd_usage); if(!user && adduser) { error(1,0,"You cannot add yourself"); } if(!user && deluser) { error(1,0,"You cannot delete yourself"); } if(user || current_parsed_root->username) { printf ("%s %s\n", (adduser) ? "Adding user" : (deluser) ? "Deleting user" : "Changing password for", user?user:current_parsed_root->username); } else { printf ("Changing repository password for %s\n",getcaller()); } fflush (stdout); if (argc == 0) username = CVS_Username; else { username = user; } if(!use_domain && !deluser && !disableuser) { typed_password = getpass ("New password: "******"Verify password: "******"Passwords do not match, try again"); } memset (typed_password2, 0, strlen (typed_password2)); typed_password = xrealloc(typed_password, strlen(typed_password) +32); if(strlen(typed_password)) crypt_password(typed_password); } } #ifdef SERVER_SUPPORT if(server_active) { if ((argc != 1) && (argc != 2)) usage (passwd_usage); if(!strcmp(user,"*")) username = CVS_Username; else { username = user; #if defined(_WIN32) #ifdef SJIS if(_mbschr(username,'\\') && !isDomainMember()) #else if(strchr(username,'\\') && !isDomainMember()) #endif { error(1,0,"CVS server is not acting as a domain member - cannot specify domains"); } #endif } if(argc==2) typed_password = argv[1]; } #endif if (typed_password && (strcmp(username, CVS_Username) != 0) && (! verify_admin ())) error (1, 0, "Only administrators can add or change another's password"); read_passwd_list(); passnode = find_passwd_entry(username); if (passnode == NULL) { if (!adduser) error (1, 0, "Could not find %s in password file", username); if (! verify_admin()) { error (1, 0, "Only administrators can add users" ); } passnode = new_passwd_entry(); passnode->username=xstrdup(username); passnode->password=xstrdup(typed_password); passnode->real_username=NULL; } if(deluser) { if (! verify_admin()) { error (1, 0, "Only administrators can delete users" ); } xfree(passnode->username); passnode->username = NULL; } else if(disableuser) { if (! verify_admin()) { error (1, 0, "Only administrators can disable users" ); } xfree(passnode->password); passnode->password=xstrdup("#DISABLED#"); } else { xfree(passnode->password); #ifdef _WIN32 /* Unix servers can't make any sense of this */ if(use_domain) { passnode->password = xmalloc(strlen(password_domain)+2); strcpy(passnode->password,"!"); strcat(passnode->password,password_domain); } else #endif passnode->password = xstrdup(typed_password); if(realuser) { if(!getpwnam(real_user)) error(1, 0, "User '%s' is not a real user on the system.",real_user); xfree(passnode->real_username); passnode->real_username = xstrdup(real_user); } else if (remove_realuser) { xfree(passnode->real_username); passnode->real_username=NULL; } if((passnode->real_username && !getpwnam(passnode->real_username)) || (!passnode->real_username && passnode->username && !getpwnam(passnode->username))) { error(0,0,"*WARNING* CVS user '%s' will not be able to log in until they are aliased to a valid system user.",username); } } write_passwd_list(); free_passwd_list(); xfree(real_user); xfree(password_domain); return (err); }
Bool WdeCreateStatusLine( HWND main, HINSTANCE inst ) { RECT rect; LOGFONT lf; TEXTMETRIC tm; HFONT old_font; HDC dc; status_block_desc sbd; char *status_font; char *cp; int point_size; Bool use_default; memset( &lf, 0, sizeof( LOGFONT ) ); dc = GetDC( main ); lf.lfWeight = FW_BOLD; use_default = TRUE; status_font = WdeAllocRCString( WDE_STATUSFONT ); if( status_font != NULL ) { cp = (char *)_mbschr( (unsigned char *)status_font, '.' ); if( cp != NULL ) { *cp = '\0'; strcpy( lf.lfFaceName, status_font ); cp++; point_size = atoi( cp ); use_default = FALSE; } WdeFreeRCString( status_font ); } if( use_default ) { strcpy( lf.lfFaceName, STATUS_FONTNAME ); point_size = STATUS_POINTSIZE; } lf.lfHeight = -MulDiv( point_size, GetDeviceCaps( dc, LOGPIXELSY ), 72 ); WdeStatusFont = CreateFontIndirect( &lf ); old_font = SelectObject( dc, WdeStatusFont ); GetTextMetrics( dc, &tm ); SelectObject( dc, old_font ); ReleaseDC( main, dc ); GetClientRect( main, &rect ); WdeStatusDepth = tm.tmHeight + STATUS_LINE_PAD + VERT_BORDER * 2; rect.top = rect.bottom - WdeStatusDepth; if( !StatusWndInit( inst, WdeStatusHookProc, 0, (HCURSOR)NULL ) ) { return( FALSE ); } WdeStatusBar = StatusWndStart(); sbd.separator_width = STATUS_LINE_PAD; sbd.width = STATUS1_WIDTH; sbd.width_is_percent = FALSE; sbd.width_is_pixels = TRUE; StatusWndSetSeparators( WdeStatusBar, 1, &sbd ); WdeStatusWindow = StatusWndCreate( WdeStatusBar, main, &rect, inst, NULL ); if( WdeStatusWindow == NULL ) { WdeDisplayErrorMsg( WDE_NOCREATESTATUS ); return( FALSE ); } /* set the text in the status window */ WdeSetStatusReadyText(); GetWindowRect( WdeStatusWindow, &rect ); WdeStatusDepth = rect.bottom - rect.top; return( TRUE ); }
int if_up(char *devname) { /* Get network adapter status from WMI using COM */ DWORD ifStatus = 0; HRESULT hres; IWbemLocator *locator=NULL; IWbemServices *services=NULL; IEnumWbemClassObject *results=NULL; BSTR resource=SysAllocString(L"ROOT\\CIMV2"); BSTR language=SysAllocString(L"WQL"); LPWSTR query_h=L"SELECT NetConnectionStatus FROM Win32_NetworkAdapter " L"WHERE NetConnectionID = "; size_t len=_mbslen(devname); size_t cont=0; /* Count how many single single quotes(') in devname for escap */ /* single quotes(') in WQL query string */ char *pc=devname; for(; pc=(char *)_mbschr(pc,'\''); pc++) { cont++; } /* Need to add two single quotes(') at begin and after devname */ WCHAR query_str[len+cont+wcslen(query_h)+3]; wcscpy(query_str,query_h); /* Add start single quote(') to query string before append devname */ wcscat(query_str,L"'"); WCHAR connid[len+1]; mbstowcs(connid,devname,len+1); WCHAR *pw, *qw=connid; for(pw=connid; pw=wcschr(pw, L'\''); pw++) { /* Escape single quotes(') in devname */ wcsncat(query_str,qw,pw-qw); wcscat(query_str,L"\\"); qw=pw; } wcscat(query_str,qw); /* Append terminal single quote(') to query string */ wcscat(query_str,L"'"); BSTR query=SysAllocString(query_str); // initialize COM hres=CoInitializeEx(0, COINIT_MULTITHREADED); if (FAILED(hres)) { log_warn("Failed to initialize COM library:0x%x\n", hres); goto cleanup; } hres=CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); if (FAILED(hres)) { log_warn("Failed to initialize security:0x%x\n",hres); CoUninitialize(); goto cleanup; } // connect to WMI hres=CoCreateInstance(&CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, &IID_IWbemLocator, (LPVOID *) &locator); if (FAILED(hres)) { log_warn("Failed to create IWbemLocator object:0x%x\n",hres); CoUninitialize(); goto cleanup; } hres=locator->lpVtbl->ConnectServer(locator, resource, NULL, NULL, NULL, 0, NULL, NULL, &services); if (FAILED(hres)) { log_warn("Could not connect:0x%x\n",hres); locator->lpVtbl->Release(locator); CoUninitialize(); goto cleanup; } // issue a WMI query hres=services->lpVtbl->ExecQuery(services, language, query, WBEM_FLAG_BIDIRECTIONAL, NULL, &results); if (FAILED(hres)) { log_warn("Query for processes failed:0x%x\n",hres); services->lpVtbl->Release(services); locator->lpVtbl->Release(locator); CoUninitialize(); goto cleanup; } // list the query results else { IWbemClassObject *result = NULL; ULONG returnedCount = 0; // enumerate the retrieved objects while((results->lpVtbl->Next(results, WBEM_INFINITE, 1, &result, &returnedCount)) == S_OK) { VARIANT status; // obtain the desired properties of the next result result->lpVtbl->Get(result, L"NetConnectionStatus", 0, &status, 0, 0); // release the current result object result->lpVtbl->Release(result); if(status.intVal==2) { ifStatus=-1; break; } } } // release WMI COM interfaces results->lpVtbl->Release(results); services->lpVtbl->Release(services); locator->lpVtbl->Release(locator); // unwind everything else we've allocated CoUninitialize(); cleanup: SysFreeString(query); SysFreeString(language); SysFreeString(resource); return ifStatus; }
_WCRTLINK void __F_NAME(_splitpath,_wsplitpath)( const CHAR_TYPE *path, CHAR_TYPE *drive, CHAR_TYPE *dir, CHAR_TYPE *fname, CHAR_TYPE *ext ) { const CHAR_TYPE *dotp; const CHAR_TYPE *fnamep; const CHAR_TYPE *startp; UINT_WC_TYPE ch; #ifdef __NETWARE__ const CHAR_TYPE *ptr; #endif /* take apart specification like -> //0/hd/user/fred/filename.ext for QNX */ /* take apart specification like -> c:\fred\filename.ext for DOS, OS/2 */ #if defined(__UNIX__) /* process node/drive specification */ startp = path; if( path[0] == DIR_SEP && path[1] == DIR_SEP ) { path += 2; for( ;; ) { if( *path == NULLCHAR ) break; if( *path == DIR_SEP ) break; if( *path == STRING( '.' ) ) break; ++path; } } copypart( drive, startp, path - startp, _MAX_NODE ); #elif defined(__NETWARE__) #ifdef __WIDECHAR__ ptr = wcschr( path, DRV_SEP ); #else ptr = _mbschr( (unsigned char *)path, DRV_SEP ); #endif if( ptr != NULL ) { if( drive != NULL ) { copypart( drive, path, ptr - path + 1, _MAX_SERVER + _MAX_VOLUME + 1 ); } #if defined( __WIDECHAR__ ) path = ptr + 1; #else path = _mbsinc( ptr ); #endif } else if( drive != NULL ) { *drive = NULLCHAR; } #else /* processs drive specification */ if( path[0] != NULLCHAR && path[1] == DRV_SEP ) { if( drive != NULL ) { drive[0] = path[0]; drive[1] = DRV_SEP; drive[2] = NULLCHAR; } path += 2; } else if( drive != NULL ) { drive[0] = NULLCHAR; } #endif /* process /user/fred/filename.ext for QNX */ /* process /fred/filename.ext for DOS, OS/2 */ dotp = NULL; fnamep = path; startp = path; for( ;; ) { /* 07-jul-91 DJG -- save *path in ch for speed */ if( *path == NULLCHAR ) break; #if defined( __WIDECHAR__ ) || defined( __UNIX__ ) || defined( __RDOS__ ) || defined( __RDOSDEV__ ) ch = *path; #else ch = _mbsnextc( (unsigned char *)path ); #endif if( ch == EXT_SEP ) { dotp = path; ++path; continue; } #if defined( __WIDECHAR__ ) || defined( __UNIX__ ) || defined( __RDOS__ ) || defined( __RDOSDEV__ ) ++path; #else path = (char *)_mbsinc( (unsigned char *)path ); #endif if( IS_DIR_SEP( ch ) ) { fnamep = path; dotp = NULL; } } copypart( dir, startp, fnamep - startp, _MAX_DIR - 1 ); if( dotp == NULL ) dotp = path; copypart( fname, fnamep, dotp - fnamep, _MAX_FNAME - 1 ); copypart( ext, dotp, path - dotp, _MAX_EXT - 1); }
// // // Wrapper around _aefindfirsti64() to report streams // // Note: This implementation requires abs paths (always do _ExpandPath first) // long _xfindfirsti64(const char *szPath, struct _finddatai64_t *pfd, BOOL bShowStreams, DWORD dwType) { char szStrippedPathBuf[FILENAME_MAX]; const char *szStrippedPath; char *szStreamPat; char *sz; long handle; struct find_stream *fs; static BOOL bSetPriv; if (gbReg) { return _RegFindFirst(szPath, pfd, dwType); } if (!bShowStreams) { return _aefindfirsti64(szPath, pfd); } // // Split into szStrippedPath, szStreamPat // if (szPath[0] == '\0' || szPath[1] == '\0' || (sz = _mbschr(szPath+2, ':')) == NULL) { szStrippedPath = szPath; szStreamPat = NULL; } else { szStreamPat = sz; // ":mystream" lstrcpyn(szStrippedPathBuf, szPath, FILENAME_MAX); szStrippedPathBuf[szStreamPat-szPath] = '\0'; // chop stream szStrippedPath = szStrippedPathBuf; } // // Query the file propper via the stripped path // if ((handle = _aefindfirsti64(szStrippedPath, pfd)) == FAIL) { return FAIL; } fs = (struct find_stream*)xmalloc(sizeof(*fs)); memset(fs, 0, sizeof(*fs)); fs->fs_handle = handle; fs->fs_szStrippedPath = xstrdup(szStrippedPath); fs->fs_szStreamPat = szStreamPat ? xstrdup(szStreamPat) : NULL; if (!bSetPriv) { bSetPriv = TRUE; #ifdef UNDEFINED // not needed // // Enable SeBackupPrivilege // _SetPrivileges(1, aszPrivs, TRUE); // ignore errors #endif } if (!_LookupStream(TRUE/*bFirst*/, fs, szStreamPat/*to match*/, pfd)) { _xfindclose((long)fs, bShowStreams); // free and close return FAIL; // bail } return (long)fs; }
void GetNameAndAddr(LPSTR lpszName, int nLenName, LPSTR lpszEMail, int nLenEMail, LPCTSTR lpszSrc) { *lpszName = '\0'; *lpszEMail = '\0'; LPSTR lpsz = strdup(lpszSrc); LPSTR lpBuf = lpsz; while (*lpsz == '\x20' || *lpsz == '\t') lpsz++; BOOL bQ = FALSE; LPSTR lpszAddr = lpsz; while (TRUE) { BYTE ch = *lpszAddr; if (_ismbblead(ch)) { lpszAddr++; } else if (ch == '\"') { bQ ^= TRUE; } else if (ch == '<' && !bQ) { break; } lpszAddr++; if (!*lpszAddr) { lpszAddr = NULL; break; } } LPSTR lpszTmp; if (lpszAddr) { lpszAddr++; lpszTmp = (LPSTR)_mbstok((LPBYTE)lpszAddr, (LPBYTE)">"); if (lpszTmp) { while (*lpszTmp == ' ' || *lpszTmp == '\t') lpszTmp++; strncpy(lpszEMail, lpszTmp, nLenEMail-1); lpszEMail[nLenEMail-1] = '\0'; } else { strcpy(lpszEMail, ""); } if (*lpsz != '<') { if (*lpsz == '\"') { lpszTmp = (LPSTR)_mbstok((LPBYTE)lpsz, (LPBYTE)"\""); } else { lpszTmp = (LPSTR)_mbstok((LPBYTE)lpsz, (LPBYTE)"<"); } if (lpszTmp) { while (*lpszTmp == ' ' || *lpszTmp == '\t') lpszTmp++; strncpy(lpszName, lpszTmp, nLenName-1); lpszName[nLenName-1] = '\0'; } else { strcpy(lpszName, ""); } } } else { lpszAddr = (LPSTR)_mbschr((LPBYTE)lpsz, (BYTE)'('); if (lpszAddr) { lpszAddr++; lpszTmp = (LPSTR)_mbstok((LPBYTE)lpszAddr, (LPBYTE)")"); if (lpszTmp) { while (*lpszTmp == ' ' || *lpszTmp == '\t') lpszTmp++; strncpy(lpszName, lpszTmp, nLenName-1); } else { strcpy(lpszName, ""); } lpszName[nLenName-1] = '\0'; lpszTmp = (LPSTR)_mbstok((LPBYTE)lpsz, (LPBYTE)"("); if (lpszTmp) { while (*lpszTmp == ' ' || *lpszTmp == '\t') lpszTmp++; strncpy(lpszEMail, lpszTmp, nLenEMail-1); lpszEMail[nLenEMail-1] = '\0'; } else { strcpy(lpszEMail, ""); } } else { strcpy(lpszName, ""); strncpy(lpszEMail, lpsz, nLenEMail-1); lpszEMail[nLenEMail-1] = '\0'; } } int nLen; nLen = strlen(lpszName); if (nLen) { nLen--; while (nLen && (lpszName[nLen] == ' ' || lpszName[nLen] == '\t')) { lpszName[nLen] = '\0'; nLen--; } } nLen = strlen(lpszEMail); if (nLen) { nLen--; while (nLen && (lpszEMail[nLen] == ' ' || lpszEMail[nLen] == '\t')) { lpszEMail[nLen] = '\0'; nLen--; } } free (lpBuf); }
_WCRTLINK void __F_NAME(_splitpath,_wsplitpath)( const CHAR_TYPE *path, CHAR_TYPE *drive, CHAR_TYPE *dir, CHAR_TYPE *fname, CHAR_TYPE *ext ) { const CHAR_TYPE *dotp; const CHAR_TYPE *fnamep; const CHAR_TYPE *startp; #ifndef __WIDECHAR__ unsigned ch; #else CHAR_TYPE ch; #endif #ifdef __NETWARE__ const CHAR_TYPE *ptr; #endif /* take apart specification like -> //0/hd/user/fred/filename.ext for QNX */ /* take apart specification like -> c:\fred\filename.ext for DOS, OS/2 */ #if defined(__UNIX__) /* process node/drive specification */ startp = path; if( path[ 0 ] == PC && path[ 1 ] == PC ) { path += 2; for( ;; ) { if( *path == NULLCHAR ) break; if( *path == PC ) break; if( *path == '.' ) break; #ifdef __WIDECHAR__ ++path; #else #ifdef __UNIX__ path++; #else path = _mbsinc( path ); #endif #endif } } copypart( drive, startp, path - startp, _MAX_NODE ); #elif defined(__NETWARE__) #ifdef __WIDECHAR__ ptr = wcschr( path, ':' ); #else #ifdef __UNIX__ ptr = strchr( path, ':' ); #else ptr = _mbschr( path, ':' ); #endif #endif if( ptr != NULL ) { if( drive != NULL ) { copypart( drive, path, ptr - path + 1, _MAX_SERVER + _MAX_VOLUME + 1 ); } #ifdef __WIDECHAR__ path = ptr + 1; #else #ifdef __UNIX__ path = ptr + 1; #else path = _mbsinc( ptr ); #endif #endif } else if( drive != NULL ) { *drive = '\0'; } #else /* processs drive specification */ if( path[ 0 ] != NULLCHAR && path[ 1 ] == ':' ) { if( drive != NULL ) { drive[ 0 ] = path[ 0 ]; drive[ 1 ] = ':'; drive[ 2 ] = NULLCHAR; } path += 2; } else if( drive != NULL ) { drive[ 0 ] = NULLCHAR; } #endif /* process /user/fred/filename.ext for QNX */ /* process /fred/filename.ext for DOS, OS/2 */ dotp = NULL; fnamep = path; startp = path; for( ;; ) { /* 07-jul-91 DJG -- save *path in ch for speed */ if( *path == NULLCHAR ) break; #ifdef __WIDECHAR__ ch = *path; #else #ifdef __UNIX__ ch = *path; #else ch = _mbsnextc( path ); #endif #endif if( ch == '.' ) { dotp = path; ++path; continue; } #ifdef __WIDECHAR__ ++path; #else #ifdef __UNIX__ path++; #else path = _mbsinc( path ); #endif #endif #if defined(__UNIX__) if( ch == PC ) { #else /* DOS, OS/2, Windows, Netware */ if( ch == PC || ch == ALT_PC ) { #endif fnamep = path; dotp = NULL; } } copypart( dir, startp, fnamep - startp, _MAX_DIR - 1 ); if( dotp == NULL ) dotp = path; copypart( fname, fnamep, dotp - fnamep, _MAX_FNAME - 1 ); copypart( ext, dotp, path - dotp, _MAX_EXT - 1); }