|
No, the folders are copied out side of the program. The program should be able to identify the folders that are complete, as opposed to the ones that are still in progress. I tried traversing the directory with FindFirstFile and FindNextFile and tried opening the files inside, hoping that if it returns an invalid handle then the directory is still in progress. But this did not work.
Any helpful hints?
Thank you,
Indu
|
|
|
|
|
The only thing I can think of is to try and open the file(s) exclusively. Files that are being copied would not allow such access.
Are you using ReadDirectoryChangesW() for the monitoring?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I also looked at FindFirstChangeNotification, which will trigger an event when directory properties change. Has any body done anything similar, I am running out of options.
Thank you,
Indu
|
|
|
|
|
icsr wrote: I also looked at FindFirstChangeNotification...
This will tell you that some file has changed, but it won't tell you what that file is.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
HANDLE cnh = FindFirstChangeNotification(inDirName, TRUE, <br />
FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME|FILE_NOTIFY_CHANGE_SIZE|FILE_NOTIFY_CHANGE_LAST_WRITE);<br />
if(cnh!= INVALID_HANDLE_VALUE)<br />
{<br />
DWORD dwMilSecs = 500;
DWORD wr = WaitForSingleObject(cnh, dwMilSecs);
<br />
if(wr == WAIT_OBJECT_0)<br />
{<br />
<br />
do {<br />
FindNextChangeNotification(cnh);<br />
wr = WaitForSingleObject(cnh, dwMilSecs);<br />
} while(wr == WAIT_OBJECT_0);<br />
}<br />
FindCloseChangeNotification(cnh); <br />
}<br />
<br />
MoveFileEx (inDirName,outDirName, MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED); <br />
<br />
Thank you David for your reply. This is what I have done. Since I only care about whether the directory changed or not, I used WaitForSingleObject. I think my program is not waiting long enough. I am also trying to understand what you have done in FaxWatch. I want to move only the directories that are done copying.
Thank you,
Indu
|
|
|
|
|
icsr wrote: I am also trying to understand what you have done in FaxWatch.
Nothing that would help here. Knowing when an operation starts is easy, but knowing when an operation is done is not. I would hazard a guess that even the OS does not know such a thing. When an application starts a file/folder operation, only it knows when it will be done.
You could try something brute-force like taking a snapshot of the folder when you first detect a change, and then re-checking that folder every few seconds to see if anything differs (e.g., file sizes).
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Would I not get continuous notification if I am watching for FILE_NOTIFY_CHANGE_SIZE and the directory is in progress?
do {<br />
FindNextChangeNotification(cnh);<br />
wr = WaitForSingleObject(cnh, dwMilSecs);<br />
} while(wr == WAIT_OBJECT_0);
I think the OS caching is also making it difficult to monitor.
Thank you,
Indu
|
|
|
|
|
I have written a program which is meant to be run with Administrator privileges: it carries out tasks for the user as an administrator and there is nothing fancy going on here; simply a proof of concept. At some point, the program launches another program, but I would it to launch _without_ admin privileges. I would like it to inherit the user security descriptors but not the admin through the CreateProcess API. I have gone through the Securty/Authorization API and I am able to read and identify SIDs and Permissions LUIDs, etc., but I am at a dead end I would appreciate anyone pointing me in the right direction.
Thanks,
m.bergman
-- For Bruce Schneier, quanta only have one state : afraid.
|
|
|
|
|
Use CreateProcessAsUser() function please.
Hope you can take ideas From this [^] article.
|
|
|
|
|
I have the following (part of openssl source code)
struct EVP_MD
{
int type;
int pkey_type;
int md_size;
unsigned long flags;
int (*init)(EVP_MD_CTX *ctx);
int (*update)(EVP_MD_CTX *ctx,const void *data,size_t count);
int (*final)(EVP_MD_CTX *ctx,unsigned char *md);
int (*copy)(EVP_MD_CTX *to,const EVP_MD_CTX *from);
int (*cleanup)(EVP_MD_CTX *ctx);
int (*sign)(int type, const unsigned char *m, unsigned int m_length,
unsigned char *sigret, unsigned int *siglen, void *key);
int (*verify)(int type, const unsigned char *m, unsigned int m_length,
const unsigned char *sigbuf, unsigned int siglen, void *key);
int required_pkey_type[5];
int block_size;
int ctx_size;
};
My question is in regards to the lines that look like this:
int (*init)(EVP_MD_CTX *ctx);
What the hell is that? It looks like a function pointer.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: It looks like a function pointer
Mostly because it is. A pointer to something like.
<br />
int InitFunc(EVP_MD_CTX* ctx)<br />
{<br />
}<br />
the struct member is called init
It looks like an attempt to sort of create a class in 'C' by tying functions to a struct to make them 'member' functions.
Anyway I thought you'd entirely graduated to 'toy' languages like C# and left all this grungy stuff behind?
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I have had to do some pretty wide-ranging stuff. I've converted about 500 lines of PHP code down to 200 lines of C# code, and now my boss wants to see if we can convert part of the PHP source code that deals with openssl signature verification (written in C) to C# (the original message is part of that tasking). In order to convert it, I have to understand what it's doing in the original language. I've already suggested that we at least use C++/CLI, but he really wants it in C#.
I could have avoided this conversion if I could have found a way to verify the signature with the .net crypto stuff. I've never dealt with any kind of crypto stuff before, so I haven't got an earthly clue about where to start or what to look for in that regard (and nobody here or anywhere else seems to know where to point me). I am therefore doomed challenged to convert this code (if possible).
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
That explains it. I have full confidence that you'll be able to convert this. C is great for porting because it's simple enough most of the time to be really certain about what it means just from reading it. I've had some great fun porting C to C++ in the past. Even better from what you posted this C was written by a C++ programmer anyway so it's already closer to C# than it might be in really nasty K&R C. Good luck.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Matthew Faithfull wrote: I have full confidence that you'll be able to convert this.
The problem is that I don't have time to convert it. I'd rather do this with the built in .Net crypto stuff if possible (see my exchange with led_mike).
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I sympathise with the time pressure. I'm afarid the Crypto API in C# is about as much out of my league as it gets. I can only wish you luck.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
John Simmons / outlaw programmer wrote: and nobody here or anywhere else seems to know where to point me
PHP... does that mean a Web Application? So you are trying to convert to ASP.NET?
John Simmons / outlaw programmer wrote: openssl signature verification
Well I would start reading about security, certificates and signatures at a standards level. Once you have a grasp of that the Crypto API documentation will make a lot more sense and finally a .NET interface to it as well.
This[^] is old, but should prove useful. Also I have no current knowledge as to the levels of support in the Frameworks library versions. Also what .NET platform are you on, that likely makes a difference.
|
|
|
|
|
led mike wrote: PHP... does that mean a Web Application? So you are trying to convert to ASP.NET?
Actually, yes. I created a website project and converted all the php to C# (duplicating the PHP code's Hex2Bin() function was interesting to say the least). The signature verification part is the only thing I need to do, and it's proving to be a supreme bitch.
led mike wrote: Well I would start reading about security,
I just want a code snippet at this point. I'm bumping my head on time constraints (I've been at this for about two weeks now) and don't have the time or desire to ponder the subtle nuances that encompass the broader topic of "encryption".
I'm using .Net 2.0 (why anyone would start new .Net projects with anything older is beyond me).
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: I'm using .Net 2.0 (why anyone would start new .Net projects with anything older is beyond me).
Yeah, I was thinking newer because I have no idea what they added to 3.+
So if you are on ASP.NET running under IIS why are you messing with this? It sounds like you want SSL on your site and that is all just IIS configuration?
|
|
|
|
|
led mike wrote: So if you are on ASP.NET running under IIS why are you messing with this?
Because I don't know any better.
We don't need the sight to be a secure site. We just want to verify that the people trying to access it are coming from a another site through this crappy single sign-on code (I think they may have two or three users - counting our customer). Unfortunately, we're stuck with what the customer is using.
We get a query string that contains some data in the clear, some encrypted data, and a SSL signature. We already have the public key with which to verify the signature.
Everything is in place and ready to be "verified". That's all I need to do - *verify* the signature. This shouldn't require anything regarding SSL on the part of the server as far as I can tell (if it does, this just serves to illustrate my lack of knowledge in this area). Shouldn't I be able to simply verify the signature without having to make any changes on the IIS side? Shouldn't the crypto stuff in .Net let me do this?
The existing PHP code uses its internal openssl module and calls a single function with three parameters - the data, the public key, and the signature - and returns a 1 or a 0 to indicate success. I want to have a function that does exactly the same thing, but using the .Net crypto functionality, if possible. It appears as if it is possible, but I haven't been able to find anything that says how, and I can't find anyplace to ask other than here.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: We just want to verify that the people trying to access it are coming from a another site
??? I don't get that.
|
|
|
|
|
...coming from a specific site.
Like everything else web based, it's a clusterfuck of disparate technologies trying to rub each other the right way without puking all over each other's shoes.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
ROTFLMAO... and I couldn't agree more. I've been involved in web dev off and on since 1996 and have seen it go from something that was enormously beneficial to being abused beyond all imagination by all the wanna-be jerkoffs.
But I was asking a specific question to try and assist you. Perhaps my reply in the new thread will start a fruitful conversation.
|
|
|
|
|
I just found a site that looks like it has a five-part article about what I'm after.
http://www.dotnetbips.com/articles/c9e90522-df22-4a0b-937a-913d6b992ddd.aspx[^]
Unfortunately, the associated download is lost somewhere on the site.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I think you would need to create a System.Security.Cryptography.X509Certificates.X509Certificate2 to represent the certificate, then get the PublicKey property's Key property, which is an abstract type representing the encryption algorithm used by the certificate, appropriately initialised.
Then you'd have to cast that to an RSACryptoServiceProvider or DSACryptoServiceProvider as appropriate (you can simply use as for this, to check the type and cast in one operation, as per C++ dynamic_cast ) and call VerifyData . For the halg parameter I think you pass the certificate's SignatureAlgorithm property (this may need to be the FriendlyName or the Value property).
Yes, I can see why you were struggling!
DoEvents : Generating unexpected recursion since 1991
|
|
|
|
|
Oh you don't really want to rewrite the crypto code in C# for your project.
All Web security is based on standards, all the algorithms are built into .Net framework, and most importantly - the administration part of handling the certificates, public/private keys and such.
This means that you can port the C code, but the result will be unmanageable: the administrators who know how to work with .Net servers, have no idea how it is done for PHP; the administrators who run PHP servers, do not know how to deal with .Net security policies. And no one knows how your solution will work when Microsoft issues the next security update.
I strongly recommend to use .Net native cryptography, even if you need to learn it or use an external expert.
Cheers,
Alex
|
|
|
|