小编Dev*_*man的帖子

How can I use impersonation to manipulate files/directories on a remote machine with UNC?

I need to download files from a server to a shared drive directory, creating the directory if it doesn't exist. There are a few things making this more complicated:

  1. I do not have write access (nor does the account that will run the job in UAT/Prod) to the shared drive directory.
  2. The Service account that does have write access does not have any privileges anywhere but the shared drive directory.

I attempt to impersonate, as so:

class Impersonation
{
    const …
Run Code Online (Sandbox Code Playgroud)

c# impersonation unc remote-access file-manipulation

7
推荐指数
1
解决办法
167
查看次数

记录判别式可以间接确定Ada中的数组长度吗?

我正在尝试说明一种特殊情况,其中几个数组的长度应该比正常的短,但是判别式和数组的长度之间没有直接关系。通常情况下,简化的记录如下所示:

type Int_Array is array(Integer range <>);

type My_Record is
record
    A : Integer;
    B : Integer;
    C : Int_Array(1..10);
    D : Int_Array(1..6);
end record;
Run Code Online (Sandbox Code Playgroud)

但是,如果某些判别式为320,则应如下所示:

type My_Record is
record
    A : Integer;
    B : Integer;
    C : Int_Array(1..4);
    D : Int_Array(1..2);
end record;
Run Code Online (Sandbox Code Playgroud)

我一直在玩它,但无法编译任何东西。这是我尝试过的一些方法:

type My_Record(Disc : Positive) is
record
    A : Integer;
    B : Integer;
    C : Int_Array(1..(if Disc = 320 then 4 else 10));
    D : Int_Array(1..(if Disc = 320 then 2 else 4));
end record;
Run Code Online (Sandbox Code Playgroud)

但这会导致错误“约束中的区别必须单独出现”。 …

types record ada

3
推荐指数
1
解决办法
136
查看次数

如何处理Ada中的int **?

我正在尝试使用对它来自的C库的预先绑定来调用SDL_LoadWAV。SDL_LoadWAV只是SDL_LoadWAV_RW的包装:

function SDL_LoadWAV
 (file      : C.char_array;
  spec      : access SDL_AudioSpec;
  audio_buf : System.Address;
  audio_len : access Uint32) return access SDL_AudioSpec
is
begin
  return SDL_LoadWAV_RW
      (SDL_RWFromFile (file, C.To_C ("rb")),
       1,
       spec,
       audio_buf,
       audio_len);
end SDL_LoadWAV;
Run Code Online (Sandbox Code Playgroud)

这是C函数的原型:

SDL_AudioSpec* SDL_LoadWAV_RW(SDL_RWops*     src,
                          int            freesrc,
                          SDL_AudioSpec* spec,
                          Uint8**        audio_buf,
                          Uint32*        audio_len)
Run Code Online (Sandbox Code Playgroud)

(浏览此处获取更多信息)

现在您可以看到,它以Uint8 **的形式通过引用传递了一个Uint8(无符号8位整数)数组。这使我非常烦恼。这是适当的绑定:

function SDL_LoadWAV_RW
 (src       : access SDL_RWops;
  freesrc   : C.int;
  spec      : access SDL_AudioSpec;
  audio_buf : System.Address;
  audio_len : access Uint32) return access SDL_AudioSpec;
pragma Import (C, SDL_LoadWAV_RW, "SDL_LoadWAV_RW");
Run Code Online (Sandbox Code Playgroud)

如您所见,绑定将Uint8 **映射到System.Address。我尝试了一些技巧来将数据获取到想要的位置,但是似乎没有任何效果。现在,我的代码看起来像这样(其中包含一些自定义类型和异常):

type …
Run Code Online (Sandbox Code Playgroud)

c ada ffi pass-by-reference memory-address

2
推荐指数
1
解决办法
107
查看次数

如何处理 Ada 动态谓词中未初始化的数据?

这是一些我尚未按原样测试的简化代码(因此可能包含错误),它演示了我遇到的问题:

type Space is private;

--Depending on members of Space, determines whether Outer fully contains Inner
function Contains(Outer : Space; Inner : Space);

--Outer should fully contain Inner
type Nested_Space is
record
    Inner : Space;
    Outer : Space;
end record
with Dynamic_Predicate => Contains(Outer, Inner);
Run Code Online (Sandbox Code Playgroud)

我无法找到一种方便的方法来初始化 Nested_Space 而不会使谓词定义的断言失败。如果我尝试先设置 Inner 的成员,Outer 的成员仍然位于默认的位置。但是,如果我尝试先将成员设置为 Outer,则 Inner 成员仍然位于默认的位置。即使我尝试在任一类型上强制使用默认值,仍然无法选择肯定在任何任意 Nested_Space 范围内的默认值。

甚至尝试用类似的东西初始化

declare
    My_Inner : Space := (...);
    My_Outer : Space := (...);
    My_NS : Nested_Space := (Inner => My_Inner, Outer => My_Outer);
begin
    .... …
Run Code Online (Sandbox Code Playgroud)

predicate ada gnat

2
推荐指数
1
解决办法
179
查看次数

阿达 - 阅读大文件

我正在构建一个HTTP服务器,主要是出于学习/好奇的目的,我遇到了一个我从未在Ada中遇到过的问题.如果我尝试使用Direct_IO读取太大的文件,我会收到存储错误:堆栈溢出异常.这几乎从未发生,但是当我请求视频文件时,将抛出异常.

所以我有了一次读取和发送1M个字符块的文件的想法,但是这给我留下了End Errors,因为大多数文件的长度都不是1M字符.我也不完全确定我是否正确,因为阅读整个文件之前一直都足够了.这是我写的程序:

procedure Send_File(Channel : GNAT.Sockets.Stream_Access; Filepath : String) is
    File_Size : Natural := Natural(Ada.Directories.Size (Filepath));
    subtype Meg_String is String(1 .. 1048576);
    package Meg_String_IO is new Ada.Direct_IO(Meg_String);
    Meg : Meg_String;
    File : Meg_String_IO.File_Type;
    Count : Natural := 0;
begin
    loop
        Meg_String_IO.Open(File, Mode => Meg_String_IO.In_File, Name => Filepath);
        Meg_String_IO.Read(File, Item => Meg);
        Meg_String_IO.Close(File);
        String'Write(Channel, Meg);
        exit when Count >= File_Size;
        Count := Count + 1048576;
    end loop;
end Send_File;
Run Code Online (Sandbox Code Playgroud)

我曾想过要声明两个单独的Direct_IO包/字符串大小,其中一个长度为1048576,而另一个长度为mod 1048576,但我不确定如何依次使用这两个读取器.

感谢任何能提供帮助的人.

file ada

1
推荐指数
1
解决办法
465
查看次数

Ada/Gnat - 包级动态泛型实例化

我有一个通用包:

generic
    Size : Positive;
package Foo is

    type Unbounded_Sized_Array is Array(1..Size) of Unbounded_String;

    type My_Type is
    record
        My_Array : Unbounded_Sized_Array;
        --other stuff
    end record;

end Foo;
Run Code Online (Sandbox Code Playgroud)

我需要在另一个包中的包级别声明它:

package Bar is

    package Dynamic_Foo is new Foo(Count);

    --other stuff

end Bar;
Run Code Online (Sandbox Code Playgroud)

问题是我不知道Count是什么,直到我执行一些代码(它是给定目录中的文件数)并且我不确定如何推迟Dynamic_Foo的实例化直到完成之后.或者即使这是可以在Ada中完成的事情.我可以制作一个链表类型,但我真的不愿意,因为它的大小/长度应该在它启动后保持不变.

generics packages ada instantiation gnat

1
推荐指数
1
解决办法
144
查看次数

如何搜索每对符合标准的最大子集?

我希望这不是一个统计问题......

假设我有一个界面:

public interface PairValidatable<T>
{
    public boolean isValidWith(T);
}
Run Code Online (Sandbox Code Playgroud)

现在,如果我有一个大型的PairValidatables数组,如何找到每个对通过isValidWith测试的那个数组的最大子集?

为了澄清,如果子集中有三个条目,则元素0和1应传递isValidWith,元素1和2应传递isValidWith,元素0和2应传递isValidWith.

例,

public class Point implements PairValidatable<Point>
{
    int x;
    int y;

    public Point(int xIn, int yIn)
    {
        x = xIn;
        y = yIn;
    }

    public boolean isValidWith(Point other)
    {
        //whichever has the greater x must have the lesser (or equal) y
        return x > other.x != y > other.y;
    }
}
Run Code Online (Sandbox Code Playgroud)

直观的想法是保持一个点向量,添加数组元素0,并将每个剩余的数组元素与向量进行比较,如果它通过向量中的每个元素进行验证,如果是这样就将它添加到向量...但是问题元素0可能是非常严格的.例如,

Point[] arr = new Point[5];
arr[0] = new Point(1000, 1000);
arr[1] = new Point(10, 10); …
Run Code Online (Sandbox Code Playgroud)

algorithm search subset

0
推荐指数
1
解决办法
66
查看次数