Does anyone know how to list NTFS permissions on all shares in a NETAPP vfiler using C#?
I tried to use NETAPP API but only get the share permissions, can't find a way to get the NTFS ones.
EDIT
Thanks Sobrique, here's the C# syntax:
var api = new NaElement("system-cli");
var args = new NaElement("args");
args.AddNewChild("arg", "fsecurity");
args.AddNewChild("arg", "show");
args.AddNewChild("arg", path);
api.AddChildElement(args);
s.InvokeElem(api)
For doing this though, I tend to use:
vfiler run vfilername fsecurity show /path/to/file/here
This will print the various ACL attributes (NTFS and Unix) for the file in question. You'll need to first enumerate your share paths to do this. (cifs shares is a start point).
There is a way to do it via the API - you need to use the undocumented 'system-cli' function that lets you remote execute commands and capture output.
Unfortunately doing this the output is ... about on a par with just running an ssh command.
However - craft your XML:
<!DOCTYPE netapp SYSTEM "/na_admin/netapp_filer.dtd">
<netapp version="1.7" xmlns="http://www.netapp.com/filer/admin">
<system-cli>
<args>
<arg>fsecurity</arg>
<arg>show</arg>
<arg>/vol/volname/qtreename/sharename/filename</arg>
</args>
</system-cli>
</netapp>
This will do the trick, although it will return you plain text cli-output element.
use strict;
use warnings;
use XML::Twig;
use LWP;
my $twig = XML::Twig->new( 'pretty_print' => 'indented' );
$twig->set_root(
XML::Twig::Elt->new(
'netapp',
{ version => 1.7,
vfiler => "somevfiler",
xmlns => "http://www.netapp.com/filer/admin",
},
)
);
my $api_req = $twig->root->insert_new_elt('system-cli');
my $args = $api_req->insert_new_elt('args');
$args->insert_new_elt( 'last_child', 'arg', 'fsecurity' );
$args->insert_new_elt( 'last_child', 'arg', 'show' );
$args->insert_new_elt( 'last_child', 'arg', '/vol/volname/qtree/filename' );
$twig->set_doctype('netapp SYSTEM "file:/etc/netapp_filer.dtd"');
$twig->set_xml_version("1.0");
$twig->set_encoding('utf-8');
$twig->print;
exit;
my $user_agent = LWP::UserAgent->new(
'ssl_opts' => {
'verify_hostname' => 0,
'SSL_version' => 'SSLv3',
}
);
my $request =
HTTP::Request->new( 'POST' =>
'https://myfilername/servlets/netapp.servlets.admin.XMLrequest_filer'
);
$request->authorization_basic( 'username_here', 'password_here' );
$request->content( $twig->sprint );
my $results = $user_agent->request($request);
if ( not $results->is_success ) {
print "Error: ", $results->status_line;
exit;
}
my $results_xml = XML::Twig->new( 'pretty_print' => 'indented_a' );
$results_xml->parse( $results->content );
$results_xml->print;
Related
I need an application which is use for advertise some services.
I installed some BLE plugin from NUGet and ı readed their documentation on github. Generally they explain scanner mode, except this plugin of BluetoothLE ( https://github.com/aritchie/bluetoothle) .
I tried that advertiser code :
protected override void OnStart()
{
var server = CrossBleAdapter.Current.CreateGattServer();
var service = server.AddService(Guid.NewGuid(), true); //ı got error on this line
var characteristic = service.AddCharacteristic(
Guid.NewGuid(),
CharacteristicProperties.Read | CharacteristicProperties.Write ,
GattPermissions.Read | GattPermissions.Write
);
var notifyCharacteristic = service.AddCharacteristic
(
Guid.NewGuid(),
CharacteristicProperties.Indicate | CharacteristicProperties.Notify,
GattPermissions.Read | GattPermissions.Write
);
IDisposable notifyBroadcast = null;
notifyCharacteristic.WhenDeviceSubscriptionChanged().Subscribe(e =>
{
var #event = e.IsSubscribed ? "Subscribed" : "Unsubcribed";
if (notifyBroadcast == null)
{
this.notifyBroadcast = Observable
.Interval(TimeSpan.FromSeconds(1))
.Where(x => notifyCharacteristic.SubscribedDevices.Count > 0)
.Subscribe(_ =>
{
Debug.WriteLine("Sending Broadcast");
var dt = DateTime.Now.ToString("g");
var bytes = Encoding.UTF8.GetBytes(dt);
notifyCharacteristic.Broadcast(bytes);
});
}
});
characteristic.WhenReadReceived().Subscribe(x =>
{
var write = "HELLO";
// you must set a reply value
x.Value = Encoding.UTF8.GetBytes(write);
x.Status = GattStatus.Success; // you can optionally set a status, but it defaults to Success
});
characteristic.WhenWriteReceived().Subscribe(x =>
{
var write = Encoding.UTF8.GetString(x.Value, 0, x.Value.Length);
// do something value
});
}
Error is that;
CS1061 'IObservable' does not contain a definition of 'AddService' and no accessible extension methods 'AddService' were found that accept a first argument of type 'IObservable' (could you be missing a using directive or assembly reference?)
What can ı do about that? Do you know another plugin can do advertiser ?
That plugin you are using is now out of service from reading the notice on the link you included. They have now shifted the functionality over to Shiny
I would strongly recommend looking at Shiny as it has some nice documentation on how to get setup with BLE Hosting here:
https://shinylib.net/blehosting/
Given that Shiny is written by the same person that wrote the plugin you were initially trying and looking over the documentation it shouldn't be too difficult to shift to this approach as large amounts of the code looks similar if not the same.
I have problems with Nusoap and Windows Phone and I hope that perhaps you could help me.
But first let me explain what I did:
First I created a webservice
<?php
require_once('./lib_095/nusoap.php');
$server = new soap_server();
$server->configureWSDL('test_wsdl', 'urn:test_wsdl');
$server->wsdl->schemaTargetNamespace = 'urn:test_wsdl';
$server->register('test', // method name
array('var' => 'xsd:string'), // input parameters
array('return' => 'xsd:string'), // output parameters
'urn:test_wsdl', // namespace
'urn:test_wsdl#test', // soapaction
'rpc', // style
'literal', // use
'Test-Methode des Webservices' // documentation
);
function test($var)
{
return "test fine: $var";
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
For my first test I wrote a console application in visual studio 2013:
ServiceReference1.test_servicePortTypeClient c = new ServiceReference1.test_servicePortTypeClient();
string check = "Milburn";
var result = c.test("Hallo");
Console.WriteLine(result);
This little programm works fine.
So I thought I could transfer the experience to Windows Phone - take the same code for that. But this didn't work. I even tried this code:
ServiceReference1.test_servicePortTypeClient c = new ServiceReference1.test_servicePortTypeClient();
string check = "Milburn";
var result = c.testAsync(check);
System.Diagnostics.Debug.WriteLine("Hallo"+result);
And as a result the program returned a task. So what can I do to get a string as a result ?
Thx for your help
The generated service uses async methods on Windows Phone (your test changed to testAsync) so you need to await them
var result = await c.testAsync(check);
Is it possible using the .Net driver to:
Check whether a certain Mongo instance is already a part of a replica
Create a replica if not
Add \ Remove a node from an existing replica
Thanks!
Yes. But it's much easier to do these things in the mongo shell because it has helper functions defined already. Check out the replica set tutorials. For each step using some function in the mongo shell, for example rs.initiate() or rs.add(), you can see the code for the function by entering the function name with parentheses at the shell prompt:
> rs.initiate
function (c) { return db._adminCommand({ replSetInitiate: c }); }
> rs.add
function (hostport, arb) {
var cfg = hostport;
var local = db.getSisterDB("local");
assert(local.system.replset.count() <= 1, "error: local.system.replset has unexpected contents");
var c = local.system.replset.findOne();
assert(c, "no config object retrievable from local.system.replset");
c.version++;
var max = 0;
for (var i in c.members)
if (c.members[i]._id > max) max = c.members[i]._id;
if (isString(hostport)) {
cfg = { _id: max + 1, host: hostport };
if (arb)
cfg.arbiterOnly = true;
}
if (cfg._id == null){
cfg._id = max+1;
}
c.members.push(cfg);
return this._runCmd({ replSetReconfig: c });
}
The code may be slightly different in your shell because of shell version; my shell is 3.0.1. You can use this code as a guide for writing your own versions of these functions in C#. You will use the RunCommand method to run the commands like replSetReconfig and replSetInitiate on the server(s).
I am trying to get the preview URL for various items in SharePoint. When viewing an image, something like this will work:
var sharePointServerUri = new Uri( item.Context.Url );
var sharePointFileUrl =
HttpUtility.UrlEncode( string.Format( "{0}://{1}{2}", sharePointServerUri.Scheme, sharePointServerUri.Host, item.File.ServerRelativeUrl ) );
var lightBoxShareUrl = string.Format( "{0}_layouts/15/Lightbox.aspx?url={1}", sharePointServerUri.AbsoluteUri, sharePointFileUrl );
However, this doesn't work for something like a Word document, only images/videos.
Is there a better way to do this which will handle all file types using the SharePoint API?
I was able to get a preview link by doing something like this:
Microsoft.SharePoint.Client.ClientContext clientContext;
Microsoft.SharePoint.Client.ListItem item;
var wopiFrameUrl = item.GetWOPIFrameUrl( Microsoft.SharePoint.Client.SPWOPIFrameAction.InteractivePreview );
clientContext.ExecuteQuery();
And the wopiFrameUrl.Value is the preview URL. It seems that it would come back null if the item is an image, in which case I used the code from the question to construct a LightBox URL.
I'd like to create a small application that can collect system information (Win32_blablabla) using WinRM as opposed to WMI. How can i do that from C#?
The main goal is to use WS-Man (WinRm) as opposed to DCOM (WMI).
I guess the easiest way would be to use WSMAN automation. Reference wsmauto.dll from windwos\system32 in your project:
then, code below should work for you. API description is here: msdn: WinRM C++ API
IWSMan wsman = new WSManClass();
IWSManConnectionOptions options = (IWSManConnectionOptions)wsman.CreateConnectionOptions();
if (options != null)
{
try
{
// options.UserName = ???;
// options.Password = ???;
IWSManSession session = (IWSManSession)wsman.CreateSession("http://<your_server_name>/wsman", 0, options);
if (session != null)
{
try
{
// retrieve the Win32_Service xml representation
var reply = session.Get("http://schemas.microsoft.com/wbem/wsman/1/wmi/root/cimv2/Win32_Service?Name=winmgmt", 0);
// parse xml and dump service name and description
var doc = new XmlDocument();
doc.LoadXml(reply);
foreach (var elementName in new string[] { "p:Caption", "p:Description" })
{
var node = doc.GetElementsByTagName(elementName)[0];
if (node != null) Console.WriteLine(node.InnerText);
}
}
finally
{
Marshal.ReleaseComObject(session);
}
}
}
finally
{
Marshal.ReleaseComObject(options);
}
}
hope this helps, regards
I've got an article that describes an easy way to run Powershell through WinRM from .NET at http://getthinktank.com/2015/06/22/naos-winrm-windows-remote-management-through-net/.
The code is in a single file if you want to just copy it and it's also a NuGet package that includes the reference to System.Management.Automation.
It auto manages trusted hosts, can run script blocks, and also send files (which isn't really supported but I created a work around). The returns are always the raw objects from Powershell.
// this is the entrypoint to interact with the system (interfaced for testing).
var machineManager = new MachineManager(
"10.0.0.1",
"Administrator",
MachineManager.ConvertStringToSecureString("xxx"),
true);
// will perform a user initiated reboot.
machineManager.Reboot();
// can run random script blocks WITH parameters.
var fileObjects = machineManager.RunScript(
"{ param($path) ls $path }",
new[] { #"C:\PathToList" });
// can transfer files to the remote server (over WinRM's protocol!).
var localFilePath = #"D:\Temp\BigFileLocal.nupkg";
var fileBytes = File.ReadAllBytes(localFilePath);
var remoteFilePath = #"D:\Temp\BigFileRemote.nupkg";
machineManager.SendFile(remoteFilePath, fileBytes);
Hope this helps, I've been using this for a while with my automated deployments. Please leave comments if you find issues.
I would like to note that this shows an interop error by default in Visual Studio 2010.
c.f. http://blogs.msdn.com/b/mshneer/archive/2009/12/07/interop-type-xxx-cannot-be-embedded-use-the-applicable-interface-instead.aspx
There appear to be two ways to solve this. This first is documented in the article listed above and appears to be the correct way to handle the problem. The pertinent changes for this example is:
WSMan wsManObject = new WSMan();
This is in lieu of IWSMan wsman = new WSManClass(); which will throw the error.
The second resolution is to go to the VS2010—>Solution Explorer—>Solution—>Project—>References and select WSManAutomation. Right click or hit Alt-Enter to access the properties. Change the value of the "Embed Interop Types" property of the wsmauto reference.