jcifs fails to resolve a DFS url - samba

When trying to access an SmbFile with a DFS URL, the jcifs library fails. But when I use the UNC returned by dfsutil it works.
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication( domain, user, pass );
SmbFile folder = new SmbFile(path,auth);
If path is set to
smb://mydomain.example.com/ourdfs/go/to/my/folder
the call fails with
Exception in thread "main" jcifs.smb.SmbException: The network name cannot be found.
But it is successful when invoked with the resolved name
dfsutil diag viewdfspath \\mydomain.example.com\ourdfs\go\to\my\folder
The DFS Path <\\mydomain.example.com\ourdfs\go\to\my\folder>
resolves to -> <\\someserver.example.com\sharename$\my\folder>
Then the following url works for path
smb://someserver.example.com/sharename$/my/folder
How do I set up jcifs to handle DFS properly i.e. not having to translate urls thru dfsutil?

The solution is to set the WINS configuration. IPCONFIG /ALL will show the information:
Connection-specific DNS Suffix . : MYDOMAIN.EXAMPLE.COM
Description . . . . . . . . . . . : Ethernet Connection
Physical Address. . . . . . . . . : DE-AD-BE-EF-F0-0D
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IPv4 Address. . . . . . . . . . . : 10.10.1.42(Preferred)
Subnet Mask . . . . . . . . . . . : 255.0.0.0
Lease Obtained. . . . . . . . . . : December 3, 2018 09:03:04 AM
Lease Expires . . . . . . . . . . : December 9, 2018 09:03:04 AM
Default Gateway . . . . . . . . . : 10.10.1.1
DHCPv4 Class ID . . . . . . . . . : O-mobile
DHCP Server . . . . . . . . . . . : 10.10.11.13
DNS Servers . . . . . . . . . . . : 10.10.4.48
10.10.4.56
Primary WINS Server . . . . . . . : 10.10.1.59
Secondary WINS Server . . . . . . : 10.10.2.58
NetBIOS over Tcpip. . . . . . . . : Enabled
The then configuration item has to be set as follows:
jcifs.netbios.wins=10.10.1.59
or by setting it with jcifs.Config.setProperty()

Related

Regular Expression in Tcl to parse a line

i need a regular expression to separate left and right part of this pattern . . . . . :
for e.g.
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . : alumnus.co.in
Description . . . . . . . . . . . : Microsoft ISATAP Adapter
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
and store them into two variable.
i have written this regular expression
regexp {([[a-z]*[0-9]*.*[0-9]*[a-z]*]*" "):([[a-z]*[0-9]*.*[0-9]*[a-z]*]*)} 6*rag5hu. . :4ku5-1a543m match a b
but it is not working.
Any help will be appreciated.
I would do this:
set text {Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . : alumnus.co.in
Description . . . . . . . . . . . : Microsoft ISATAP Adapter
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes}
foreach line [split $text \n] {
if {[regexp {^(.+?)(?: \.)+ : (.+)$} $line -> name value]} {
puts "$name => $value"
}
}
outputs
Media State => Media disconnected
Connection-specific DNS Suffix => alumnus.co.in
Description => Microsoft ISATAP Adapter
Physical Address. => 00-00-00-00-00-00-00-E0
DHCP Enabled. => No
Autoconfiguration Enabled => Yes
This uses a non-greedy quantifier (+?), and that make every quantifier in the regex non-greedy. You then require the anchors so that the bits you want to capture contain all the text you need.
Borrowing the definition of text:
package require textutil
foreach line [split $text \n] {
lassign [::textutil::splitx [string trim $line] {\s*(?:\. )+:\s*}] a b
puts "a: $a\nb: $b"
}
Giving the output
a: Media State
b: Media disconnected
a: Connection-specific DNS Suffix
b: alumnus.co.in
a: Description
b: Microsoft ISATAP Adapter
a: Physical Address
b: 00-00-00-00-00-00-00-E0
a: DHCP Enabled
b: No
a: Autoconfiguration Enabled
b: Yes
Documentation:
foreach,
lassign,
package,
puts,
split,
string,
textutil (package)

YII2 how to get each record after joinwith

How to get each record in an active record after multiple joinWiths?
$model = \common\models\opcr\OpcrKra::find()
->joinWith('opcrRoObjectives')
->joinWith('opcrRoObjectives.opcrFdObjectives')
->joinWith('opcrRoObjectives.opcrFdObjectives.opcrIndividuals');
I get a Trying to get property of non-object error.
foreach ($model->all() as $row) {
echo "<tr>"
. "<td></td>"
. "<td>" . $row->kra . "</td>"
. "<td>" . $row->opcrRoObjectives->id . "</td>" // error here
. "</tr>";
}
I tried to display the $row->count() and it gave me just the exact number of records I expected.
I solved this using the eager loading.
$authors = Author::find()->with('posts')->all(); // fetches the authors with their posts
foreach($authors as $author) {
echo "<h2>Author : " . $author->name . "</h2>";
echo "<ul>";
foreach($author->posts as $post) { // no query executed here
echo "<li>" . $post->title . "</li>";
}
echo "</ul>";
}
You just try this solution:
$model = \common\models\opcr\OpcrKra::find()
->joinWith('opcrRoObjectives')
->joinWith('opcrRoObjectives.opcrFdObjectives')
->joinWith('opcrRoObjectives.opcrFdObjectives.opcrIndividuals')
$result = $model->asArray()->all();
Then in your view:
foreach ($model as $row) {
echo "<tr>"
. "<td></td>"
. "<td>" . $row->kra . "</td>"
. "<td>" . $row['opcrRoObjectives']['id'] . "</td>"
. "</tr>";
}

Exim script before queue

I need to open exim relay to a list of ips in a mysql database.
I think if I can run a script before a email is queued, I can do that. Is there a way?
Mail Enable for windows has a similar solution called "SMTP Inbound Command Scripting".
# configure
. . . . .
hide mysql_servers = localhost/myoneandonlybase/login/pass
hostlist myfriends = ${lookup mysql{SELECT ipaddr FROM submitters}}
. . . . .
acl_smtp_connect = acl_conn
acl_smtp_rcpt = acl_rcpt
acl_smtp_data = acl_data
. . . . .
begin acl
acl_conn:
accept hosts = +myfriends
. . . . .
acl_rcpt:
accept hosts = +myfriends
. . . . .
acl_data:
accept hosts = +myfriends
. . . . .
The default exim configuration file already has a hostlist relay_from_hosts that you can easily populate with an SQL lookup and get the desired result:
hide mysql_servers = localhost/myoneandonlybase/login/pass
hostlist relay_to_domains = ${lookup mysql{SELECT ipaddr FROM submitters}}
Nothing more than that is needed.

echoing array results using 'While' does not show row 1

I am using a 'While' loop to run through an array of users' first names, last names, and emails. When my 'While' loop executes, and I echo the data, it successfully shows the row data from the database, but it does not show Row 1. It starts at row 2 and spits everything out properly, but why is it skipping row 1?
$query= "SELECT * FROM email_list";
$result=mysqli_query($dbc, $query);
$row=mysqli_fetch_array($result);
while ($row=mysqli_fetch_array($result)) {
echo $row['first_name'] . ' ' . $row['last_name'] . ' : '
. $row['email'] . '<br />';
}
mysqli_close($dbc);
One thing I have found, is if I put this section:
$row=mysqli_fetch_array($result);
echo $row['first_name'] . ' ' . $row['last_name'] . ' : '
. $row['email'] . '<br />';
above the 'While' loop, then it does successfully show the first row of data, and all the other rows too, so, if that's confusing, coding it like this (the long way - below) actually works, but it seems redundant and I want to use best DRY practices:
$query= "SELECT * FROM email_list";
$result=mysqli_query($dbc, $query);
$row=mysqli_fetch_array($result);
echo $row['first_name'] . ' ' . $row['last_name'] . ' : '
. $row['email'] . '<br />';
while ($row=mysqli_fetch_array($result)) {
echo $row['first_name'] . ' ' . $row['last_name'] . ' : '
. $row['email'] . '<br />';
}
mysqli_close($dbc);
You have 2 calls to $row=mysqli_fetch_array($result); before you print your result. One before the loop and the other as the expression in the while statement.
Try deleting the one before the while loop.
$result=mysqli_query($dbc, $query);
// kill this line $row=mysqli_fetch_array($result);
while ($row=mysqli_fetch_array($result)) {
echo $row['first_name'] . ' ' . $row['last_name'] . ' : '
. $row['email'] . '<br />';
}

Display arabic text correctly on chrome

(link for the picture http://d.pr/i/SCks just in case..)
On the three browsers above, the arabic text is well displayed.
On Chrome (V 15) bellow, it's a bit not well organized.
What seems to be the problem ?
PS: i'm using Fusioncharts
EDIT:
That's how I'm writing it:
echo '<set label="' . addslashes($label) . ' - \' + value_' . $i . ' + \'% (' . $label_value . ') " value="' . $data_pie['nb'] . '" />\';' . "\n";