Using "runas" command for a program that writes a file (Windows Server 2008) - windows-server-2008

I wrote this simple console program (writeTxt.exe):
#include "stdafx.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char *fileName = "test.txt";
ofstream outStream(fileName, ios::out);
outStream << "This is a very simple test." << endl;
return 0;
}
Then I run it on the console of Windows Server 2008 using runas command (I logged-in as a different user from User1):
runas /user:User1 writeTxt.exe
But the program doesn't produce the file test.txt. If I log-in to the server as User1 and run the program, it works correctly. Do I have to set something for this to run correctly?

I believe that runas always launches programs with their working directory set to C:\Windows\System32 (or moral equivalent) rather than whatever your current working directory is when you invoke runas.
If User1 has permissions to write to that directory, that's where the file will be. If they don't have such a permission, then the program will fail.

Related

Objective C - NSTask support

I am programming an advanced Executable (binary) Analyser Application that can do many operations on Mach-O binaries. One of these functions is a simple launch operation with can simply execute the executable and log its output.
I recently found out the when terminal launches executable files, it detects when the executable runs its own NSTask inside its code.
eg.
Terminal is executing my application and is also showing (in the red circle) that my application is currently running an NSTask of the "file" command:
What I want to figure out is how I can make my app do this to other executable files. I want my app to launch an Executable and when the executable runs a shell script (NSTask), My app will detect it and log it.
eg.
An Executable has the following code:
int main(int argc, const char * argv[]) {
NSTask *task = [NSTask new];
task.launchPath = #"/usr/bin/file";
task.arguments = #[#"--mime", #"--brief", #"/path/to/file"];
task.standardOutput = [NSPipe new];
[task launch];
return 0;
}
When I execute this in Terminal, once the line
[task launch];
is executed, Terminal will display the sub process name in the titlebar:
I Want my app to execute an Executable just like terminal and when an executable runs its own NSTask, I want my app to detect that and log it.
So when my app runs this executable. I want my app to detect when the "file" task is executed in the executable.
I Hope this isn't to difficult to Understand. I also have a feeling I will have to dig deeper than NSTask to include this process.
Thanks.

'netcfg.exe' is not recognized as an internal or external command, operable program or batch file." when call through vbscript

i am trying to execute netcfg.exe /U ms_pacer etc to uninstall some bindings to the network adapter. now everytime i pass the command through vbscript the command prompt throws an error saying 'netcfg.exe' is not recognized as an internal or external command, operable program or batch file.
if i put it in a batch file and double click on it it runs fine. but again if i execute that batchfile through a .run in vbscript it gives the same error. i read somewhere that it could be environment variable issue, but tried setting environment, looks good but the command keeps throwing the error again and again. tried it in powershell but no go, please someone guide.
Ok found the answer, when running a 32 bit compiled application which needs to access another native windows application there is a catch. though windows has provided a set of 32-bit set of native applications in a 64 Bit OS, but has not changed names of files, and have been relocated in another folder i.e. %windir%\SysWoW64\ , now everytime a 32 bit application tries to access c:\windows\system32 on a 64 bit, it gets redirected to %windir%\SysWoW64\, now if one wants to refer to 64 bit native application then do %windir%\Sysnative

QSQLITE : not authorized unable to fetch row

I'm completely stuck with loading extensions in Qt's SQLite driver. I've done all steps from this 'how to'. Just changed SQLITE_ENABLE_LOAD_EXTENSION to DSQLITE_ENABLE_LOAD_EXTENSION. After that I'm trying to run following code in my app:
QSqlQuery tSqlQuery;
QString sql_command_text;
sql_command_text = QString("SELECT load_extension(\"libspatialite-4.dll\")");
if(!tSqlQuery.exec(sql_command_text))
qDebug() << tSqlQuery.lastError().text();
And qDebug gives me this: "not authorized Unable to fetch row".
I'm using Qt 4.6.3
What am I doing wrong? I've read tons of articles but couldn't find any solution.
You can be sure in following things:
I've done all steps from how-to
I've rebuild DLLs and replaced them
When I face this problem I've solved it this way:
Add in Src\qtbase\src\3rdparty\sqlite\sqlite3.c next lines:
#ifndef SQLITE_ENABLE_LOAD_EXTENSION
# define SQLITE_ENABLE_LOAD_EXTENSION 1
#endif
Added it somewhere near 150 line.
Removed from file Src\qtbase\src\3rdparty\sqlite.pri from DEFINES:
SQLITE_OMIT_EXTENSION
Leave it like this:
DEFINES += SQLITE_OMIT_COMPLETE SQLITE_ENABLE_FTS3 SQLITE_ENABLE_FTS3_PARENTHESIS SQLITE_ENABLE_RTREE
then cd command line (yeah, I'm at Win) to Src\qtbase\src\plugins\sqldrivers\sqlite
and execute next commands:
mingw32-make -j
mingw32-make install
flag -j makes make use all available cores for compiling, and install copy resulted dll to plugins\sqldrivers\sqlite dir (the place where all others dll's keep) of qt installation.
On linux (Ubuntu 14.10) I had to add this line in sqlite.pro before compiling:
LIBS=-ldl

Block remote CVS users from physically logging in to repo server

Our users are using ssh shell to run all CVS actitivies. Is it possible to block them from physically logging to the CVS server? For example, they use the following command to checkout files:
cvs -z3 -d:ext:username#cvsserver:/cvsroot/projects checkout -d project1 .
Since they are part of the group having the permissions to read/write CVS repository file system on the server, they could SSH login to the repo server and delete physical files. Can I block them? I have tried to sshd_config with DeneyUsers, or set /etc/passwd with NOLOGON shell, but they all block CVS commands too.
Thanks
Yes, it is possible. I'm using a custom shell that executes cvs only.
Here's the code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char** argv)
{
if (getenv("CVSROOT") == NULL)
setenv("CVSROOT", "/home/cvs", 0);
execl("/usr/bin/cvs", "cvs", "server", NULL);
printf("No Permission.\n");
}
You could install rssh and set this as the user's login shell.
http://www.pizzashack.org/rssh/
rssh has a list of commands (including cvs) that you can restrict users to. If they try and ssh directly into the machine they will be denied and receive a message like this:
This account is restricted by rssh.
Allowed commands: cvs
If you believe this is in error, please contact your system administrator.

script in mac app temporary location

I am a bit new to Mac OS X app development and I got stuck with Mac OS moving some Resources to a temp location wereas the her ones remain in the Resources folder. I have searched through google for a few hours and that did not help.
Here is my situation in a little more detail:
I have an application build in Xcode. It consist of an ObjC TaskWrapper and a perl script (main.pl) that is being called after the app is run. There is also an external file(say the name is extrafunctions (no extension)), that I need to load from the perl script in the runtime of application. Both the perl script and the external file are in the Resources folder inside the .app directory after building it from xcode.
After execution the main.pl file is moved to a temp location. The extrafunctions file remains in Resources inside the myMacApp.app folder. Then, when main.pl tries to load extrafunctions (used to be in the same directory) and fails, as extrafunctions has not been copied to the temp folder along.
I would need to access this extrafunctions file from the perl script, but cannot come across neither a way to get the msipp location, nor a way to let it be copied to the temp location as well.
Overview:
- main.pl = script in Resources inside myMacApp.app
- extrafunctions = external script to be loaded by main.pl in Resources
- main.pl tries to load extrafunctions: does not work
some code:
install.pl
...
if(-f "extrafunctions") {
open my $fh, "<", "extrafunctions" or die "Could not open extrafunctions : $!";
$content = do { local $/; <$fh> };
close $fh;
} else {
...
}
Any help highly appreciated!